Class: Canfig::EnvConfig
- Inherits:
-
OpenConfig
- Object
- Config
- OpenConfig
- Canfig::EnvConfig
- Defined in:
- lib/canfig/env_config.rb
Instance Attribute Summary collapse
-
#namespace ⇒ Object
readonly
Returns the value of attribute namespace.
Instance Method Summary collapse
- #env(key, default = nil, &block) ⇒ Object
- #get(key, default = nil, &block) ⇒ Object
-
#initialize(namespace = nil, **options, &block) ⇒ EnvConfig
constructor
A new instance of EnvConfig.
Methods inherited from OpenConfig
Methods inherited from Config
#[], #[]=, #allowed?, #changed, #changed?, #clear, #configure, #configure_with_args, #configure_with_block, #configure_with_file, #disable_state_saves!, #enable_state_saves!, #method_missing, #save_state!, #save_state?, #set, #to_h
Constructor Details
#initialize(namespace = nil, **options, &block) ⇒ EnvConfig
Returns a new instance of EnvConfig.
5 6 7 8 |
# File 'lib/canfig/env_config.rb', line 5 def initialize(namespace=nil, **, &block) @namespace = namespace ? "#{namespace.to_s.underscore.upcase.gsub(/_$/, '')}_" : namespace super(**, &block) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Canfig::Config
Instance Attribute Details
#namespace ⇒ Object (readonly)
Returns the value of attribute namespace.
3 4 5 |
# File 'lib/canfig/env_config.rb', line 3 def namespace @namespace end |
Instance Method Details
#env(key, default = nil, &block) ⇒ Object
14 15 16 17 18 |
# File 'lib/canfig/env_config.rb', line 14 def env(key, default=nil, &block) key = key.to_s.underscore.upcase key = key.gsub(/^#{namespace}/, '') if namespace super("#{namespace}#{key}", default, &block) end |
#get(key, default = nil, &block) ⇒ Object
10 11 12 |
# File 'lib/canfig/env_config.rb', line 10 def get(key, default=nil, &block) super || env(key, default, &block) end |