lib/superhosting/base.rb in superhosting-0.0.1 vs lib/superhosting/base.rb in superhosting-0.0.2
- old
+ new
@@ -1,37 +1,31 @@
module Superhosting
class Base
include Helpers
- def initialize(config_path: '/etc/sx', lib_path: '/var/lib/sx', logger: nil, docker_socket: nil)
+ attr_reader :config, :lib
+
+ def initialize(config_path: '/etc/sx', lib_path: '/var/sx', logger: nil, docker_api: nil, dry_run: nil, debug: nil, **kwargs)
@config_path = Pathname.new(config_path)
@lib_path = Pathname.new(lib_path)
@config = PathMapper.new(config_path)
@lib = PathMapper.new(lib_path)
- @logger = logger
+ Thread.current[:logger] ||= logger
+ Thread.current[:debug] ||= debug
+ Thread.current[:dry_run] ||= dry_run
- @docker_api = DockerApi.new(socket: docker_socket)
+ @docker_api = docker_api || DockerApi.new(socket: @config.f('docker_socket', default: nil))
end
- def debug(*a, &b)
- @logger.debug(*a, &b) unless @logger.nil?
+ def get_base_controller_options
+ {
+ config_path: @config_path.to_s,
+ lib_path: @lib_path.to_s,
+ docker_api: @docker_api,
+ }
end
- def command!(*command_args)
- cmd = Mixlib::ShellOut.new(*command_args)
- cmd.run_command
- if cmd.status.success?
- debug([cmd.stdout, cmd.stderr].join("\n"))
- cmd
- else
- raise NetStatus::Exception.new(error: :error, message: [cmd.stdout, cmd.stderr].join("\n"))
- end
- end
-
- def command(*command_args)
- cmd = Mixlib::ShellOut.new(*command_args)
- cmd.run_command
- debug([cmd.stdout, cmd.stderr].join("\n"))
- cmd
+ def get_controller(controller, **kwargs)
+ controller.new(**self.get_base_controller_options.merge!(kwargs))
end
end
end