Class: Speedflow::Plugin::Configuration
- Inherits:
-
Object
- Object
- Speedflow::Plugin::Configuration
- Defined in:
- lib/speedflow/plugin/configuration.rb
Overview
Plugin configuration
Constant Summary collapse
- CONFIG_KEY =
'_config'.freeze
Instance Method Summary collapse
-
#all_config ⇒ Object
Public: All config.
-
#all_input ⇒ Object
Public: All input.
-
#by_config(key, default_value = '') ⇒ Object
Public: Get a specific config.
-
#by_input(key, default_value = '') ⇒ Object
Public: Get an input config by key.
-
#by_multiple_config(keys_and_defaults) ⇒ Object
Public: Get multiple config.
-
#by_required_input(key, default_value = '') ⇒ Object
Public: Get an input config by key but required.
-
#initialize(arguments, plugin_name) ⇒ Configuration
constructor
Initialize.
Constructor Details
#initialize(arguments, plugin_name) ⇒ Configuration
Initialize.
arguments - Hash of arguments. plugin_name - Name of plugin.
Examples
Configuration.new({}, 'plugin')
# => <Speedflow::Plugin::Configuration>
Returns nothing.
18 19 20 21 |
# File 'lib/speedflow/plugin/configuration.rb', line 18 def initialize(arguments, plugin_name) @arguments = arguments @plugin_name = plugin_name end |
Instance Method Details
#all_config ⇒ Object
Public: All config.
Returns Hash of all config.
26 27 28 |
# File 'lib/speedflow/plugin/configuration.rb', line 26 def all_config @arguments.key?(CONFIG_KEY) ? @arguments[CONFIG_KEY] : {} end |
#all_input ⇒ Object
Public: All input.
Returns Hash of all input.
33 34 35 |
# File 'lib/speedflow/plugin/configuration.rb', line 33 def all_input @arguments.select { |k, _| k != CONFIG_KEY } end |
#by_config(key, default_value = '') ⇒ Object
Public: Get a specific config.
key - Key of config. default_value - Default value.
Returns value of config key.
43 44 45 46 47 48 49 50 51 |
# File 'lib/speedflow/plugin/configuration.rb', line 43 def by_config(key, default_value = '') config = {} if @arguments.key?(CONFIG_KEY) if @arguments[CONFIG_KEY].key?(@plugin_name) config = @arguments[CONFIG_KEY][@plugin_name] end end config.key?(key) ? config[key].to_s : default_value.to_s end |
#by_input(key, default_value = '') ⇒ Object
Public: Get an input config by key.
key - Key of config. default_value - Default value.
Returns value of input config key.
68 69 70 71 72 73 74 |
# File 'lib/speedflow/plugin/configuration.rb', line 68 def by_input(key, default_value = '') if @arguments.key?(key) @arguments[key]['value'].to_s else default_value.to_s end end |
#by_multiple_config(keys_and_defaults) ⇒ Object
Public: Get multiple config.
keys_and_defaults - Hash of keys and defaults. { ‘key’ => ‘default’ }
Returns Hash with values or defaults.
58 59 60 |
# File 'lib/speedflow/plugin/configuration.rb', line 58 def by_multiple_config(keys_and_defaults) keys_and_defaults.each { |k, v| keys_and_defaults[k] = by_config(k, v) } end |
#by_required_input(key, default_value = '') ⇒ Object
Public: Get an input config by key but required.
key - Key of config. default_value - Default value.
Returns value of input config key or Exception.
82 83 84 85 86 87 88 89 90 |
# File 'lib/speedflow/plugin/configuration.rb', line 82 def by_required_input(key, default_value = '') value = by_input(key, default_value) if by_input(key).empty? raise ConfigurationInputRequire, "Required value for '#{key}'." end value end |