Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

symbol_decoration

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

symbol_decoration

  • 1.1.0
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

Symbol Decoration

The Symbol Decoration gem provides symbol method extensions to implement DSL such as like where(:field.in => [1,2,3]).

The goal is to allow different ORMs such as Mongoid and NoBrainer to co-exist as both ORMs need such functionality.

Usage

In the following example: where(:field.in => [1,2,3]), the in keyword is a decorator, and decorates the :field symbol.

To register decorators, you may call Symbol::Decoration.register(decorator, ...). For example:

Symbol::Decoration.register(:in)
Symbol::Decoration.register(*%w(in nin eq ne not gt ge gte lt le lte))

Once registered, a decorator can be used with symbol.decorator, which returns a Symbol::Decoration instance.

To support the lowest common denominator, decorators may accept arguments and blocks. For example, :field.gt(5) is valid.

You may retrieve the decoration properties with:

  • decorated_symbol.symbol to get the symbol which is being decorated.
  • decorated_symbol.decorator to get the decoration (for example :gt).
  • decorated_symbol.args to get the decoration arguments.
  • decorated_symbol.blocks to get the decoration block.

Full example:

Symbol::Decoration.register(:gt)

:field.gt.is_a?(Symbol::Decoration) == true
:field.gt.symbol                    == :field
:field.gt.decorator                 == :gt
:field.gt(5).args                   == [5]
:field.gt { 5 }.block.call          == 5

To allow certain decorators to be chainable, you must use the :chainable => true option when registering the decorator. Example:

Symbol::Decoration.register(:any, chainable => true)
Symbol::Decoration.register(:in)

:field.any.in # valid
:field.in.any # invalid

License

Symbol Decoration is MIT Licensed.

FAQs

Package last updated on 17 Nov 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc