Support for Ruby symbol decorations such as where( => [1,2,3])
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.

Symbol Decoration

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

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


In the following example: where( => [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(*%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, 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) == true                    == :field                 == :gt                   == [5] { 5 }          == 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) # valid # invalid


Symbol Decoration is MIT Licensed.