class Config
This class is used to set the options for a specific environment.
Signature
- public
Since
stable-v1
.
Definitions
attr_reader :options
Signature
-
returns
Hash
The options.
attr_reader :env
Signature
-
returns
Symbol
The environment.
def initialize
Initialize the configuration.
Implementation
def initialize
@options = {}
@env = nil
end
def on(env)
Set the options for a specific environment.
Signature
-
parameter
env
Symbol
The environment to set the options.
-
yields
{...}
When a block is given, the block is yielded with the option.
Implementation
def on(env)
raise ArgumentError, 'Block is required.' unless block_given?
@env = env
yield self
@env = nil
end
def environment(env_name)
Get the options for a specific environment.
Signature
-
parameter
env_name
Symbol
The environment to get the options.
-
yields
{...}
When a block is given, the block is yielded with the option.
-
returns
Hash
The options if a block is not given.
Implementation
def environment(env_name)
return {} unless @options.key?(env_name)
@env = env_name
if block_given?
yield @options[env_name].merge(environment: @env)
@env = nil
else
result = @options[env_name]
@env = nil
result
end
end
def []=(key, value)
Set the option for a specific environment.
Signature
-
parameter
key
Symbol
The option name.
-
parameter
value
String
The option value.
-
returns
Nil
The option value.
Implementation
def []=(key, value)
@options[@env] ||= {}
@options[@env][key] = value
end
def [](env, key)
Signature
-
parameter
env
Symbol
The environment to get the option.
-
parameter
key
Symbol
The option name.
-
returns
String
The option value.