Class: NexusCli::Configuration

Inherits:
Object
  • Object
show all
Includes:
Chozo::VariaModel
Defined in:
lib/nexus_cli/configuration.rb

Constant Summary collapse

DEFAULT_FILE =
(ENV['HOME'] ? "~/.nexus_cli" : "/root/.nexus_cli").freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Configuration

Returns a new instance of Configuration.



75
76
77
78
# File 'lib/nexus_cli/configuration.rb', line 75

def initialize(options)
  mass_assign(options)
  self.repository = options[:repository]
end

Class Method Details

.file_pathString

The filepath to the nexus cli configuration file

Returns:

  • (String)


12
13
14
# File 'lib/nexus_cli/configuration.rb', line 12

def file_path
  File.expand_path(ENV['NEXUS_CONFIG'] || File.expand_path(DEFAULT_FILE))
end

.from_fileNexusCli::Configuration

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



31
32
33
34
35
36
37
# File 'lib/nexus_cli/configuration.rb', line 31

def from_file
  config = YAML.load_file(file_path)
  raise MissingSettingsFileException unless config

  config = config.with_indifferent_access
  new(config)
end

.from_overrides(overrides) ⇒ NexusCli::Configuration

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

Parameters:

  • overrides (Hash)

Returns:

Raises:



21
22
23
24
25
# File 'lib/nexus_cli/configuration.rb', line 21

def from_overrides(overrides)
  raise MissingSettingsFileException unless overrides
  overrides = overrides.with_indifferent_access
  new(overrides)
end

.validate!(config) ⇒ Object

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



45
46
47
48
49
# File 'lib/nexus_cli/configuration.rb', line 45

def validate!(config)
  unless config.valid?
    raise InvalidSettingsException.new(config.errors)
  end
end

Instance Method Details

#validate!Object



52
53
54
# File 'lib/nexus_cli/configuration.rb', line 52

def validate!
  self.class.validate!(self)
end