Class: ODDB::Model::Predicate

Inherits:
Object
  • Object
show all
Defined in:
lib/oddb/model.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(action, type, *delegators) ⇒ Predicate

Returns a new instance of Predicate.



14
15
16
17
# File 'lib/oddb/model.rb', line 14

def initialize(action, type, *delegators)
  raise "unknown predicate type: #{type}" unless respond_to?(type)
  @action, @type, @delegators = action, type, delegators
end

Instance Attribute Details

#actionObject (readonly)

Returns the value of attribute action.



13
14
15
# File 'lib/oddb/model.rb', line 13

def action
  @action
end

#delegatorsObject (readonly)

Returns the value of attribute delegators.



13
14
15
# File 'lib/oddb/model.rb', line 13

def delegators
  @delegators
end

#typeObject (readonly)

Returns the value of attribute type.



13
14
15
# File 'lib/oddb/model.rb', line 13

def type
  @type
end

Instance Method Details

#cascade(action, next_level) ⇒ Object



18
19
20
21
22
23
24
25
26
# File 'lib/oddb/model.rb', line 18

def cascade(action, next_level)
  if(next_level.is_a?(Array))
    next_level.each { |element| 
      cascade(action, element)
    }
  else
    next_level.send(action) if(next_level.respond_to?(action))
  end
end

#delegate(action, next_level) ⇒ Object



27
28
# File 'lib/oddb/model.rb', line 27

def delegate(action, next_level)
end

#execute(action, object) ⇒ Object



29
30
31
32
33
34
35
# File 'lib/oddb/model.rb', line 29

def execute(action, object)
  if(action == @action)
    @delegators.each { |delegator|
      self.send(@type, action, object.send(delegator))
    }
  end
end