Class: PropertyBuilder::PropertyDefinition
- Defined in:
- lib/property_builder.rb
Instance Attribute Summary collapse
-
#chain ⇒ Object
Returns the value of attribute chain.
-
#options ⇒ Object
Returns the value of attribute options.
Class Method Summary collapse
Instance Method Summary collapse
- #build(obj) ⇒ Object
-
#initialize(options) ⇒ PropertyDefinition
constructor
A new instance of PropertyDefinition.
Constructor Details
#initialize(options) ⇒ PropertyDefinition
Returns a new instance of PropertyDefinition.
48 49 50 51 |
# File 'lib/property_builder.rb', line 48 def initialize() @chain = .select{|a|!a.is_a?(Hash)} @options = .last.is_a?(Hash) ? .last : {} end |
Instance Attribute Details
#chain ⇒ Object
Returns the value of attribute chain.
47 48 49 |
# File 'lib/property_builder.rb', line 47 def chain @chain end |
#options ⇒ Object
Returns the value of attribute options.
47 48 49 |
# File 'lib/property_builder.rb', line 47 def @options end |
Class Method Details
.build(level, chain) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/property_builder.rb', line 57 def self.build(level, chain) if !chain.nil? && chain.is_a?(Array) && chain.size > 0 sender = chain.shift if sender.is_a?(Array) #Only supports one argument for now result = level.send(sender.first, sender.last) elsif sender.is_a?(String) result = level.instance_eval(sender) else result = level.send(sender) end chain.size == 0 ? result : (result.nil? ? result : build(result, chain)) elsif chain.is_a?(String) chain elsif chain.is_a?(Symbol) level.send(chain) end end |
Instance Method Details
#build(obj) ⇒ Object
53 54 55 |
# File 'lib/property_builder.rb', line 53 def build(obj) PropertyDefinition.build(obj, @chain.dup) end |