Class: Shipit::Cli::ConfigurationFile

Inherits:
Object
  • Object
show all
Defined in:
lib/shipit/cli/configuration_file.rb

Constant Summary collapse

ATTR_READER =
[:endpoint, :private_token, :protected_branches, :ship_skips_ci]

Instance Method Summary collapse

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

Returns:

  • (Boolean)


15
16
17
# File 'lib/shipit/cli/configuration_file.rb', line 15

def exist?
  File.exist?(@path)
end

#persistObject



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_hashObject



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