Class: Proc::Conditions

Inherits:
BlankSlate show all
Defined in:
lib/data_mapper/support/proc.rb

Defined Under Namespace

Classes: Attribute

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ Conditions

Returns a new instance of Conditions.



12
13
14
15
# File 'lib/data_mapper/support/proc.rb', line 12

def initialize(&block)
  @block = block
  @conditions = []
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(sym, *args) ⇒ Object



17
18
19
20
21
# File 'lib/data_mapper/support/proc.rb', line 17

def method_missing(sym, *args)
  attribute = Attribute.new(sym)
  @conditions << attribute
  attribute
end

Instance Method Details

#__to_hash__ ⇒ Object



23
24
25
26
27
28
# File 'lib/data_mapper/support/proc.rb', line 23

def __to_hash__
  instance_eval(&@block)      
  @conditions.inject({}) do |h,attribute|
    h[attribute.__operator__] = *attribute.__args__; h
  end
end