Use ordered options instead of ever-growing kwarg list
This commit is contained in:
@@ -1,20 +1,22 @@
|
|||||||
|
require "active_support/ordered_options"
|
||||||
|
|
||||||
class Mrsk::Configuration
|
class Mrsk::Configuration
|
||||||
attr_accessor :service, :image, :servers, :env, :ssh_user
|
delegate :service, :image, :env, :registry, :ssh_user, to: :config, allow_nil: true
|
||||||
|
|
||||||
def self.load_file(file)
|
def self.load_file(file)
|
||||||
if file.exist?
|
if file.exist?
|
||||||
new **YAML.load_file(file).symbolize_keys!
|
new YAML.load_file(file).symbolize_keys
|
||||||
else
|
else
|
||||||
raise "Configuration file not found in #{file}"
|
raise "Configuration file not found in #{file}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def initialize(service:, image:, servers:, env: {}, ssh_user: "root")
|
def initialize(config)
|
||||||
@service, @image, @servers, @env, @ssh_user = service, image, servers, env, ssh_user
|
@config = ActiveSupport::InheritableOptions.new(config)
|
||||||
end
|
end
|
||||||
|
|
||||||
def servers
|
def servers
|
||||||
ENV["SERVERS"] || @servers
|
ENV["SERVERS"] || config.servers
|
||||||
end
|
end
|
||||||
|
|
||||||
def version
|
def version
|
||||||
@@ -45,6 +47,8 @@ class Mrsk::Configuration
|
|||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
attr_accessor :config
|
||||||
|
|
||||||
def parameterize(param, hash)
|
def parameterize(param, hash)
|
||||||
hash.collect { |k, v| "#{param} #{k}=#{v}" }.join(" ")
|
hash.collect { |k, v| "#{param} #{k}=#{v}" }.join(" ")
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user