Class: Arsenicum::Configuration::ConfigurationHash

Inherits:
Hash
  • Object
show all
Defined in:
lib/arsenicum/configuration.rb

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_id, *args, &block) ⇒ Object



180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
# File 'lib/arsenicum/configuration.rb', line 180

def method_missing(method_id, *args, &block)
  case args.length
    when 0
      return self[method_id] unless in_configuration?

      if block_given?
        new_value = ConfigurationHash.new
        new_value.under_configuration do
          new_value.instance_eval &block
        end
        self[method_id] = new_value
      else
        self[method_id] ||= ConfigurationHash.new
      end
    when 1
      if (method_name = method_id.to_s)[-1] == '='
        return self[method_name[0...-1].to_sym] = args.first
      end

      self[method_id] = args.first
    else
      super
  end
end

Instance Method Details

#in_configuration?Boolean

Returns:

  • (Boolean)


169
170
171
# File 'lib/arsenicum/configuration.rb', line 169

def in_configuration?
  @in_configuration
end

#under_configuration(&_) ⇒ Object



173
174
175
176
177
178
# File 'lib/arsenicum/configuration.rb', line 173

def under_configuration(&_)
  @in_configuration = true
  yield if block_given?
ensure
  @in_configuration = false
end