Class: Shipit::Cli::Configuration
- Inherits:
-
Object
- Object
- Shipit::Cli::Configuration
- Defined in:
- lib/shipit/cli/configuration.rb
Overview
This class maintains all system-wide configuration for shipit. It properly applies the correct source of configuration values based on the different contexts and also makes sure that compulsory data are not missing.
Constant Summary collapse
- ATTRIBUTES =
List of all the configuration attributes stored for use within the gem
[:endpoint, :private_token, :protected_branches]
Instance Attribute Summary collapse
-
#endpoint ⇒ Object
Returns the value of attribute endpoint.
-
#private_token ⇒ Object
Returns the value of attribute private_token.
-
#protected_branches ⇒ Object
Returns the value of attribute protected_branches.
Instance Method Summary collapse
-
#apply(attributes = {}) ⇒ Object
Apply a configuration hash to a configuration instance.
- #motd_list ⇒ Object
-
#to_hash ⇒ Hash
The configuration instance formatted as a stringified hash.
-
#to_stdout ⇒ Object
Write a configuration summary to STDOUT, useful for output in the CLI.
Instance Attribute Details
#endpoint ⇒ Object
Returns the value of attribute endpoint.
13 14 15 |
# File 'lib/shipit/cli/configuration.rb', line 13 def endpoint @endpoint end |
#private_token ⇒ Object
Returns the value of attribute private_token.
13 14 15 |
# File 'lib/shipit/cli/configuration.rb', line 13 def private_token @private_token end |
#protected_branches ⇒ Object
Returns the value of attribute protected_branches.
13 14 15 |
# File 'lib/shipit/cli/configuration.rb', line 13 def protected_branches @protected_branches end |
Instance Method Details
#apply(attributes = {}) ⇒ Object
Apply a configuration hash to a configuration instance
25 26 27 28 29 30 31 |
# File 'lib/shipit/cli/configuration.rb', line 25 def apply(attributes = {}) prepared_attributes = prepare_attributes attributes prepared_attributes.each_pair do |attribute, value| send("#{attribute}=", value) end self end |
#motd_list ⇒ Object
59 60 61 |
# File 'lib/shipit/cli/configuration.rb', line 59 def motd_list File.readlines(File.('../../motd', __FILE__)).map(&:chomp) end |
#to_hash ⇒ Hash
The configuration instance formatted as a stringified hash
42 43 44 45 46 47 48 |
# File 'lib/shipit/cli/configuration.rb', line 42 def to_hash config_hash = ATTRIBUTES.inject({}) do |hash, attr| hash["#{attr}"] = instance_variable_get("@#{attr}") hash end Shipit::Cli::Sanitizer.symbolize config_hash end |
#to_stdout ⇒ Object
Write a configuration summary to STDOUT, useful for output in the CLI
52 53 54 55 56 57 |
# File 'lib/shipit/cli/configuration.rb', line 52 def to_stdout to_hash.each_pair do |attribute, value| puts format("%-20s %-50s", "#{attribute}:", value) end nil end |