Class: NexusCli::Configuration
- Inherits:
-
Object
- Object
- NexusCli::Configuration
- Defined in:
- lib/nexus_cli/configuration.rb
Constant Summary collapse
- DEFAULT_FILE =
(ENV['HOME'] ? "~/.nexus_cli" : "/root/.nexus_cli").freeze
Instance Attribute Summary collapse
-
#password ⇒ Object
Returns the value of attribute password.
-
#repository ⇒ Object
Returns the value of attribute repository.
-
#url ⇒ Object
Returns the value of attribute url.
-
#username ⇒ Object
Returns the value of attribute username.
Class Method Summary collapse
-
.file_path ⇒ String
The filepath to the nexus cli configuration file.
-
.from_file ⇒ NexusCli::Configuration
Creates a new instance of the Configuration object from the config file.
-
.from_overrides(overrides) ⇒ NexusCli::Configuration
Creates a new instance of the Configuration object based on some overrides.
-
.validate!(config) ⇒ Object
Validates an instance of the Configuration object and raises when there is an error with it.
Instance Method Summary collapse
- #[](attr) ⇒ Object
- #[]=(attr, value) ⇒ Object
- #errors ⇒ Object
-
#initialize(options) ⇒ Configuration
constructor
A new instance of Configuration.
- #valid? ⇒ Boolean
- #validate! ⇒ Object
Constructor Details
#initialize(options) ⇒ Configuration
Returns a new instance of Configuration.
84 85 86 87 88 89 90 91 92 93 |
# File 'lib/nexus_cli/configuration.rb', line 84 def initialize() @url = [:url] || ['url'] @repository = [:repository] || ['repository'] @username = [:username] || ['username'] @password = [:password] || ['password'] if @repository.is_a?(String) @repository = @repository.gsub(' ', '_') end end |
Instance Attribute Details
#password ⇒ Object
Returns the value of attribute password.
82 83 84 |
# File 'lib/nexus_cli/configuration.rb', line 82 def password @password end |
#repository ⇒ Object
Returns the value of attribute repository.
80 81 82 |
# File 'lib/nexus_cli/configuration.rb', line 80 def repository @repository end |
#url ⇒ Object
Returns the value of attribute url.
79 80 81 |
# File 'lib/nexus_cli/configuration.rb', line 79 def url @url end |
#username ⇒ Object
Returns the value of attribute username.
81 82 83 |
# File 'lib/nexus_cli/configuration.rb', line 81 def username @username end |
Class Method Details
.file_path ⇒ String
The filepath to the nexus cli configuration file
11 12 13 |
# File 'lib/nexus_cli/configuration.rb', line 11 def file_path File.(ENV['NEXUS_CONFIG'] || File.(DEFAULT_FILE)) end |
.from_file ⇒ NexusCli::Configuration
Creates a new instance of the Configuration object from the config file
32 33 34 35 36 |
# File 'lib/nexus_cli/configuration.rb', line 32 def from_file config = load_config raise MissingSettingsFileException unless config new(config) end |
.from_overrides(overrides) ⇒ NexusCli::Configuration
Creates a new instance of the Configuration object based on some overrides
20 21 22 23 24 25 26 |
# File 'lib/nexus_cli/configuration.rb', line 20 def from_overrides(overrides) raise MissingSettingsFileException unless overrides configuration = load_config || Hash.new configuration.merge!(overrides) new(configuration) end |
.validate!(config) ⇒ Object
Validates an instance of the Configuration object and raises when there is an error with it
44 45 46 47 48 |
# File 'lib/nexus_cli/configuration.rb', line 44 def validate!(config) unless config.valid? raise InvalidSettingsException.new(config.errors) end end |
Instance Method Details
#[](attr) ⇒ Object
95 96 97 |
# File 'lib/nexus_cli/configuration.rb', line 95 def [](attr) self.instance_variable_get('@' + attr.to_s) end |
#[]=(attr, value) ⇒ Object
99 100 101 102 103 104 |
# File 'lib/nexus_cli/configuration.rb', line 99 def []=(attr, value) self.instance_variable_set('@' + attr.to_s, value) if @repository.is_a?(String) @repository = @repository.gsub(' ', '_') end end |
#errors ⇒ Object
72 73 74 75 76 77 |
# File 'lib/nexus_cli/configuration.rb', line 72 def errors result = Hash.new result[:url] = ["url required"] unless url.is_a?(String) && url.size > 0 result[:repository] = ["repository required"] unless repository.is_a?(String) && repository.size > 0 result end |
#valid? ⇒ Boolean
68 69 70 |
# File 'lib/nexus_cli/configuration.rb', line 68 def valid? errors.empty? end |
#validate! ⇒ Object
64 65 66 |
# File 'lib/nexus_cli/configuration.rb', line 64 def validate! self.class.validate!(self) end |