class NexusCli::Configuration

Constants

DEFAULT_FILE

Public Class Methods

file_path() click to toggle source

The filepath to the nexus cli configuration file

@return [String]

# File lib/nexus_cli/configuration.rb, line 12
def file_path
  File.expand_path(ENV['NEXUS_CONFIG'] || File.expand_path(DEFAULT_FILE))
end
from_file() click to toggle source

Creates a new instance of the Configuration object from the config file

@return [NexusCli::Configuration]

# File lib/nexus_cli/configuration.rb, line 34
def from_file
  config = load_config
  raise MissingSettingsFileException unless config
  config = config.with_indifferent_access
  new(config)
end
from_overrides(overrides) click to toggle source

Creates a new instance of the Configuration object based on some overrides

@param [Hash] overrides

@return [NexusCli::Configuration]

# File lib/nexus_cli/configuration.rb, line 21
def from_overrides(overrides)
  raise MissingSettingsFileException unless overrides
  overrides = overrides.with_indifferent_access

  configuration = (load_config || Hash.new).with_indifferent_access
  configuration.merge!(overrides)
  new(configuration)
end
new(options) click to toggle source
# File lib/nexus_cli/configuration.rb, line 90
def initialize(options)
  mass_assign(options)
  self.repository = options[:repository]
end
validate!(config) click to toggle source

Validates an instance of the Configuration object and raises when there is an error with it

@param config [NexusCli::Configuration]

@raise [NexusCli::InvalidSettingsException]

# File lib/nexus_cli/configuration.rb, line 47
def validate!(config)
  unless config.valid?
    raise InvalidSettingsException.new(config.errors)
  end
end

Private Class Methods

load_config() click to toggle source

Loads the config file

@return [Hash]

# File lib/nexus_cli/configuration.rb, line 58
def load_config
  begin
    config = YAML.load_file(file_path)
  rescue Errno::ENOENT
    nil
  end
end

Public Instance Methods

validate!() click to toggle source
# File lib/nexus_cli/configuration.rb, line 67
def validate!
  self.class.validate!(self)
end