Module: UseConfig::ClassMethods
- Defined in:
- lib/use_config.rb
Overview
This module contains class methods use_config and drop_config.
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
48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/use_config.rb', line 48 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.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/use_config.rb', line 23 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 # Generates class accessor. .instance_eval do attr_accessor name end self.send "#{name}=".to_sym, UseConfig::Configuration.add_conf(self, name, , &block) # Generates instance accessor. class_eval <<-EVAL def #{name} self.class.#{name} end EVAL end |