Class: Shipit::Cli::ConfigurationFile
- Inherits:
-
Object
- Object
- Shipit::Cli::ConfigurationFile
- Defined in:
- lib/shipit/cli/configuration_file.rb
Constant Summary collapse
- ATTR_READER =
[:endpoint, :private_token, :protected_branches]
Instance Method Summary collapse
- #exist? ⇒ Boolean
-
#initialize(path, configuration = nil) ⇒ ConfigurationFile
constructor
A new instance of ConfigurationFile.
- #persist ⇒ Object
- #reload! ⇒ Object
- #to_hash ⇒ Object
Constructor Details
#initialize(path, configuration = nil) ⇒ ConfigurationFile
Returns a new instance of ConfigurationFile.
9 10 11 12 13 |
# File 'lib/shipit/cli/configuration_file.rb', line 9 def initialize(path, configuration = nil) @path = path @file = load_file @configuration = configuration || load_configuration end |
Instance Method Details
#exist? ⇒ Boolean
15 16 17 |
# File 'lib/shipit/cli/configuration_file.rb', line 15 def exist? File.exist?(@path) end |
#persist ⇒ Object
27 28 29 30 31 32 |
# File 'lib/shipit/cli/configuration_file.rb', line 27 def persist File.open(@path, "w") do |f| f.write @configuration.to_yaml end reload! end |
#reload! ⇒ Object
34 35 36 37 |
# File 'lib/shipit/cli/configuration_file.rb', line 34 def reload! @file = load_file @configuration = load_configuration end |
#to_hash ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/shipit/cli/configuration_file.rb', line 19 def to_hash config_hash = ATTR_READER.inject({}) do |hash, attr| hash["#{attr}"] = instance_variable_get("@#{attr}") hash end Shipit::Cli::Sanitizer.symbolize config_hash end |