Module: UseConfig::ClassMethods
- Defined in:
- lib/use_config.rb
Instance Method Summary collapse
-
#drop_config(name, options = {}) ⇒ Object
Removes configuration access methods.
-
#use_config(name, options = {}, &block) ⇒ Object
Adds configuration hash readed from config/name.yaml file to configuration class, and generates configuration access methods.
Instance Method Details
#drop_config(name, options = {}) ⇒ Object
Removes configuration access methods
45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/use_config.rb', line 45 def drop_config(name, = {}) if respond_to? name conf = send(name) if conf.respond_to? :configuration? and conf.configuration? UseConfig::Configuration.drop_conf(self, name) = class << self; self; end .instance_eval do remove_method name.to_sym end remove_method name.to_sym end end end |
#use_config(name, options = {}, &block) ⇒ Object
Adds configuration hash readed from config/name.yaml file to configuration class, and generates configuration access methods.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/use_config.rb', line 22 def use_config(name, = {}, &block) = class << self; self; end if self.respond_to? name conf = self.send(name) unless conf.respond_to? :configuration? and conf.configuration? raise "Method '#{name}' already in use" end end .instance_eval do attr_accessor name end self.send "#{name}=".to_sym, UseConfig::Configuration.add_conf(self, name, , &block) class_eval <<-EVAL def #{name} self.class.#{name} end EVAL end |