Class: ODDB::Model::Predicate
- Inherits:
-
Object
- Object
- ODDB::Model::Predicate
- Defined in:
- lib/oddb/model.rb
Instance Attribute Summary collapse
-
#action ⇒ Object
readonly
Returns the value of attribute action.
-
#delegators ⇒ Object
readonly
Returns the value of attribute delegators.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #cascade(action, next_level) ⇒ Object
- #delegate(action, next_level) ⇒ Object
- #execute(action, object) ⇒ Object
-
#initialize(action, type, *delegators) ⇒ Predicate
constructor
A new instance of Predicate.
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
#action ⇒ Object (readonly)
Returns the value of attribute action.
13 14 15 |
# File 'lib/oddb/model.rb', line 13 def action @action end |
#delegators ⇒ Object (readonly)
Returns the value of attribute delegators.
13 14 15 |
# File 'lib/oddb/model.rb', line 13 def delegators @delegators end |
#type ⇒ Object (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 |