Class: BankExchangeApi::Config
- Inherits:
-
Object
- Object
- BankExchangeApi::Config
- Defined in:
- lib/bank_exchange_api/config.rb
Class Method Summary collapse
-
.conf_accessor(*names) ⇒ Object
Defines both class & instance methods Works the same as cattr_accessor from ActiveSupport on a class level (globally) and an instance level (locally).
Class Method Details
.conf_accessor(*names) ⇒ Object
Defines both class & instance methods Works the same as cattr_accessor from ActiveSupport on a class level (globally) and an instance level (locally)
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/bank_exchange_api/config.rb', line 6 def self.conf_accessor(*names) names.each do |name| class_eval <<-METHODS, __FILE__, __LINE__ + 1 def #{name} (defined?(@#{name}) && @#{name}) || self.class.#{name} end def #{name}! self.#{name} || self.class.#{name}! end def #{name}=(value) @#{name} = value end def self.#{name} @@#{name} if class_variable_defined?(:"@@#{name}") end def self.#{name}=(value) @@#{name} = value end def self.#{name}! self.#{name} || (raise ConfigurationError, "'#{name}' config param is required") end METHODS end end |