Class: Speedflow::Plugin::Flowdock::Configuration
- Inherits:
-
Object
- Object
- Speedflow::Plugin::Flowdock::Configuration
- Defined in:
- lib/speedflow/plugin/flowdock/configuration.rb
Overview
Flowdock Configuration
Constant Summary collapse
- CONFIG_KEY =
'_config'.freeze
- PLUGIN_KEY =
'flowdock'.freeze
Instance Method Summary collapse
-
#auth ⇒ Object
Public: Auth configuration.
-
#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_required_input(key, default_value = '') ⇒ Object
Public: Get an input config by key but required.
-
#initialize(arguments) ⇒ Configuration
constructor
Initialize.
Constructor Details
#initialize(arguments) ⇒ Configuration
Initialize.
arguments - Hash of arguments.
Examples
Configuration.new({})
# => <Speedflow::Plugin::Flowdock::Configuration>
Returns nothing.
19 20 21 |
# File 'lib/speedflow/plugin/flowdock/configuration.rb', line 19 def initialize(arguments) @arguments = arguments end |
Instance Method Details
#auth ⇒ Object
Public: Auth configuration.
Returns Hash of auth configuration.
26 27 28 29 30 |
# File 'lib/speedflow/plugin/flowdock/configuration.rb', line 26 def auth { api_token: by_config('token') } 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.
38 39 40 41 42 43 44 |
# File 'lib/speedflow/plugin/flowdock/configuration.rb', line 38 def by_config(key, default_value = '') if @arguments.key?(CONFIG_KEY) && @arguments[CONFIG_KEY].key?(PLUGIN_KEY) config = @arguments[CONFIG_KEY][PLUGIN_KEY] end config.key?(key) ? config[key] : default_value 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.
52 53 54 55 56 57 58 |
# File 'lib/speedflow/plugin/flowdock/configuration.rb', line 52 def by_input(key, default_value = '') if @arguments.key?(key) @arguments[key]['value'] else default_value end 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.
66 67 68 69 70 71 72 73 74 75 |
# File 'lib/speedflow/plugin/flowdock/configuration.rb', line 66 def by_required_input(key, default_value = '') value = by_input(key, default_value) # TODO: Improve communication with core for errors if by_input(key).empty? raise Exception, "Required value for '#{key}'." end value end |