Class: Rulz::Attribute::Condition
- Inherits:
-
Object
- Object
- Rulz::Attribute::Condition
- Defined in:
- lib/rulz/attribute.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#proc ⇒ Object
readonly
Returns the value of attribute proc.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(klass, attr, name, proc) ⇒ Condition
constructor
A new instance of Condition.
Constructor Details
#initialize(klass, attr, name, proc) ⇒ Condition
Returns a new instance of Condition.
22 23 24 25 26 27 28 29 30 |
# File 'lib/rulz/attribute.rb', line 22 def initialize(klass, attr, name, proc) @name = name @proc = proc klass.instance_exec self do |condition| conditions = instance_variable_get("@rulz_#{attr}_conditions") || [] conditions << condition instance_variable_set("@rulz_#{attr}_conditions", conditions) end end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
21 22 23 |
# File 'lib/rulz/attribute.rb', line 21 def name @name end |
#proc ⇒ Object (readonly)
Returns the value of attribute proc.
21 22 23 |
# File 'lib/rulz/attribute.rb', line 21 def proc @proc end |
Class Method Details
.find(klass, attr, name) ⇒ Object
32 33 34 35 36 |
# File 'lib/rulz/attribute.rb', line 32 def self.find(klass, attr, name) result = klass.instance_variable_get("@rulz_#{attr}_conditions").find {|c| c.name == name } raise ArgumentError, "Condition '#{name}' for '#{attr}' does not exist" unless result result end |