Class: Orchparty::HashBuilder

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

Instance Method Summary collapse

Constructor Details

#initializeHashBuilder

Returns a new instance of HashBuilder.



111
112
# File 'lib/orchparty/dsl_parser.rb', line 111

def initialize
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(_, *values, &block) ⇒ Object



114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# File 'lib/orchparty/dsl_parser.rb', line 114

def method_missing(_, *values, &block)
  if block_given?
    builder = HashBuilder.new
    builder.instance_eval(&block)
    value = builder._build
    if values.count == 1
      @hash ||= {}
      @hash[values.first.to_sym] = value
    else
      @hash ||= []
      @hash << value
    end
  else
    value = values.first
    if value.is_a? Hash
      @hash ||= {}
      key, value = value.first
      @hash[key.to_sym] = value
    else
      @hash ||= []
      @hash << value
    end
  end
  self
end

Instance Method Details

#_buildObject



140
141
142
# File 'lib/orchparty/dsl_parser.rb', line 140

def _build
  @hash || {}
end