class Shipit::Cli::ConfigurationFile

Constants

ATTR_READER

Public Class Methods

new(path, configuration = nil) click to toggle source
# File lib/shipit/cli/configuration_file.rb, line 9
def initialize(path, configuration = nil)
  @path = path
  @file = load_file
  @configuration = configuration || load_configuration
end

Public Instance Methods

exist?() click to toggle source
# File lib/shipit/cli/configuration_file.rb, line 15
def exist?
  File.exist?(@path)
end
persist() click to toggle source
# 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!() click to toggle source
# File lib/shipit/cli/configuration_file.rb, line 34
def reload!
  @file = load_file
  @configuration = load_configuration
end
to_hash() click to toggle source
# 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

Private Instance Methods

load_configuration() click to toggle source
# File lib/shipit/cli/configuration_file.rb, line 49
def load_configuration
  if @file
    ATTR_READER.each do |attr|
      instance_variable_set "@#{attr}", @file[attr]
    end
  end
end
load_file() click to toggle source
# File lib/shipit/cli/configuration_file.rb, line 41
def load_file
  if exist?
    Shipit::Cli::Sanitizer.symbolize YAML.load_file(@path)
  else
    {}
  end
end