class Speedflow::Plugin::Configuration
Plugin
configuration
Constants
- CONFIG_KEY
Public Class Methods
new(arguments, plugin_name)
click to toggle source
Initialize.
arguments - Hash
of arguments. plugin_name - Name of plugin.
Examples
Configuration.new({}, 'plugin') # => <Speedflow::Plugin::Configuration>
Returns nothing.
# File lib/speedflow/plugin/configuration.rb, line 18 def initialize(arguments, plugin_name) @arguments = arguments @plugin_name = plugin_name end
Public Instance Methods
all_config()
click to toggle source
Public: All config.
Returns Hash
of all config.
# File lib/speedflow/plugin/configuration.rb, line 26 def all_config @arguments.key?(CONFIG_KEY) ? @arguments[CONFIG_KEY] : {} end
all_input()
click to toggle source
Public: All input.
Returns Hash
of all input.
# File lib/speedflow/plugin/configuration.rb, line 33 def all_input @arguments.select { |k, _| k != CONFIG_KEY } end
by_config(key, default_value = '')
click to toggle source
Public: Get a specific config.
key - Key of config. default_value - Default value.
Returns value of config key.
# 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 = '')
click to toggle source
Public: Get an input config by key.
key - Key of config. default_value - Default value.
Returns value of input config key.
# 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)
click to toggle source
Public: Get multiple config.
keys_and_defaults - Hash
of keys and defaults. { 'key' => 'default' }
Returns Hash
with values or defaults.
# 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 = '')
click to toggle source
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.
# 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