Class: PropertyBuilder::PropertyDefinition

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ PropertyDefinition

Returns a new instance of PropertyDefinition.



48
49
50
51
# File 'lib/property_builder.rb', line 48

def initialize(options)
  @chain = options.select{|a|!a.is_a?(Hash)}
  @options = options.last.is_a?(Hash) ? options.last : {}
end

Instance Attribute Details

#chainObject

Returns the value of attribute chain.



47
48
49
# File 'lib/property_builder.rb', line 47

def chain
  @chain
end

#optionsObject

Returns the value of attribute options.



47
48
49
# File 'lib/property_builder.rb', line 47

def options
  @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