Class: Orchparty::HashBuilder

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

Direct Known Subclasses

VariableBuilder

Instance Method Summary collapse

Methods inherited from Builder

#assign_or_merge, build

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
# File 'lib/orchparty/dsl_parser.rb', line 139

def method_missing(_, *values, &block)
  if block_given?
    value = HashBuilder.build(block)
    if values.count == 1
      @hash ||= AST.hash
      @hash[values.first.to_sym] = value
    else
      @hash ||= AST.array
      @hash << value
    end
  else
    value = values.first
    if value.is_a? Hash
      @hash ||= AST.hash
      key, value = value.first
      @hash[key.to_sym] = value
    else
      @hash ||= AST.array
      @hash << value
    end
  end
  self
end

Instance Method Details

#_buildObject



163
164
165
# File 'lib/orchparty/dsl_parser.rb', line 163

def _build
  @hash
end