Class: Optix::Configurator

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

Instance Method Summary collapse

Constructor Details

#initialize(config, &b) ⇒ Configurator

Returns a new instance of Configurator.



172
173
174
175
# File 'lib/optix.rb', line 172

def initialize(config, &b)
  @config = config
  cloak(&b).bind(self).call
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



177
178
179
180
181
182
# File 'lib/optix.rb', line 177

def method_missing(meth, *args, &block)
  unless @config.include? meth
    raise ArgumentError, "Unknown configuration key '#{meth}'"
  end
  @config[meth] = args[0]
end

Instance Method Details

#cloak(&b) ⇒ Object



184
185
186
187
188
189
190
191
# File 'lib/optix.rb', line 184

def cloak &b
  (class << self; self; end).class_eval do
    define_method :cloaker_, &b
    meth = instance_method :cloaker_
    remove_method :cloaker_
    meth
  end
end