Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

drop chozo+extlib in configuration parsing (fixes #123) #1

Merged
merged 1 commit into from
Mar 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 25 additions & 19 deletions lib/nexus_cli/configuration.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
require 'extlib'
require 'chozo'
require 'yaml'

module NexusCli
class Configuration
Expand Down Expand Up @@ -68,28 +67,35 @@ def validate!
self.class.validate!(self)
end

include Chozo::VariaModel
def valid?
errors.empty?
end

attribute :url,
type: String,
required: true
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

attribute :repository,
type: String,
required: true,
coerce: lambda { |m|
m = m.is_a?(String) ? m.gsub(' ', '_') : m
}
attr_accessor :url
attr_accessor :repository
attr_accessor :username
attr_accessor :password

attribute :username,
type: String
def initialize(options)
@url = options[:url]
@repository = options[:repository]
@username = options[:username]
@password = options[:password]

attribute :password,
type: String
if @repository.is_a?(String)
@repository = @repository.gsub(' ', '_')
end
end

def initialize(options)
mass_assign(options)
self.repository = options[:repository]
def [](attr)
self.instance_variable_get('@' + attr.to_s)
end
end
end
2 changes: 0 additions & 2 deletions nexus_cli.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,9 @@ Gem::Specification.new do |s|

s.add_dependency 'thor'
s.add_dependency 'httpclient', '~> 2.8.0'
s.add_dependency 'extlib'
s.add_dependency 'json'
s.add_dependency 'highline'
s.add_dependency 'jsonpath'
s.add_runtime_dependency 'chozo', '>= 0.6.0'
s.add_runtime_dependency 'activesupport', '~> 3.2.0'

s.add_development_dependency 'rspec'
Expand Down