Module: RPCMapper::ConfigOptions::ClassMethods

Defined in:
lib/rpc_mapper/config_options.rb

Instance Method Summary collapse

Instance Method Details

#config_options(options = {}) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/rpc_mapper/config_options.rb', line 6

def config_options(options={})
  options.each do |option, default_value|
    class_eval do
      self.configure_options << option
      class_inheritable_accessor option
      self.send "#{option}=", default_value
    end
    # TRP: We run a direct string eval on the class because we cannot get a closure on the class << self scope
    #      We need that in order to use our option variable to define a class method of the same name.
    self.class_eval <<-EOS
      def self.#{option}                                                              # def self.my_awesome_option
        val = read_inheritable_attribute(:#{option})                                  #   val = read_inheritable_attribute(:my_awesome_option)
        val.is_a?(Proc) ? write_inheritable_attribute(:#{option}, val.call) : val     #   val.is_a?(Proc) ? write_inheritable_attribute(:my_awesome_option, val.call) : val
      end                                                                             # end
    EOS
  end
end