Class: Superhosting::ConfigExecutor::Container
- Defined in:
- lib/superhosting/config_executor/container.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#container ⇒ Object
Returns the value of attribute container.
-
#mux ⇒ Object
Returns the value of attribute mux.
-
#mux_name ⇒ Object
Returns the value of attribute mux_name.
-
#registry_files ⇒ Object
Returns the value of attribute registry_files.
Attributes inherited from Base
#commands, #docker_api, #etc, #lib, #model
Instance Method Summary collapse
- #config(save_to, script = nil, **options) ⇒ Object
-
#initialize(container:, on_reconfig:, on_config:, mux: nil, **kwargs) ⇒ Container
constructor
A new instance of Container.
- #mkdir(path, **options) ⇒ Object
- #on_reconfig(cmd) ⇒ Object
- #run_commands ⇒ Object
Methods inherited from Base
Methods included from Helpers
Methods included from Helper::Config
#_config, #_config_options, #_save_registry!, #apply, #configure, #configure_with_apply, #reconfig, #unapply, #unconfigure, #unconfigure_with_unapply
Methods included from Helper::Cmd
#_command, #_command_without_debug, #command, #command!
Methods included from Helper::File
#chmod!, #chown!, #chown_r!, #safe_link!, #safe_unlink!
Methods included from Helper::Logger
#__debug, #__dry_run, #__dry_run=, #__logger, #__logger=, #debug, #debug_block, #debug_operation, #indent, #indent=, #indent_reset, #indent_step, #indent_step_back, #info, #storage, #t, #with_dry_run, #with_indent, #with_logger
Constructor Details
#initialize(container:, on_reconfig:, on_config:, mux: nil, **kwargs) ⇒ Container
Returns a new instance of Container.
6 7 8 9 10 11 12 13 14 |
# File 'lib/superhosting/config_executor/container.rb', line 6 def initialize(container:, on_reconfig:, on_config:, mux: nil, **kwargs) self.container = container self.mux = mux self.mux_name = mux.nil? ? mux : "mux-#{mux.name}" self.registry_files = [] @on_config = on_config @on_reconfig = on_reconfig super(**kwargs) end |
Instance Attribute Details
#container ⇒ Object
Returns the value of attribute container.
4 5 6 |
# File 'lib/superhosting/config_executor/container.rb', line 4 def container @container end |
#mux ⇒ Object
Returns the value of attribute mux.
4 5 6 |
# File 'lib/superhosting/config_executor/container.rb', line 4 def mux @mux end |
#mux_name ⇒ Object
Returns the value of attribute mux_name.
4 5 6 |
# File 'lib/superhosting/config_executor/container.rb', line 4 def mux_name @mux_name end |
#registry_files ⇒ Object
Returns the value of attribute registry_files.
4 5 6 |
# File 'lib/superhosting/config_executor/container.rb', line 4 def registry_files @registry_files end |
Instance Method Details
#config(save_to, script = nil, **options) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/superhosting/config_executor/container.rb', line 24 def config(save_to, script=nil, **) if @on_config save_to_mapper = PathMapper.new(save_to) script = .delete(:source) || save_to_mapper.name if script.nil? script = script.to_s.end_with?('.erb') ? script : "#{script}.erb" raise NetStatus::Exception.new(error: :error, code: :can_not_pass_an_absolute_path, data: { path: script }) if Pathname.new(script).absolute? script_mapper = self.config_mapper().config_templates.f(script) raise NetStatus::Exception.new(error: :error, code: :file_does_not_exists, data: { path: script_mapper.path.to_s }) if script_mapper.nil? save_to_mapper.put!(script_mapper) self.set_file_attributes(save_to_mapper.path, ) self.registry_files << save_to_mapper.path.to_s end end |
#mkdir(path, **options) ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/superhosting/config_executor/container.rb', line 16 def mkdir(path, **) if @on_config PathMapper.new(path).create! self.set_file_attributes(path, ) self.registry_files << path.to_s end end |
#on_reconfig(cmd) ⇒ Object
38 39 40 |
# File 'lib/superhosting/config_executor/container.rb', line 38 def on_reconfig(cmd) self.commands << cmd if @on_reconfig end |
#run_commands ⇒ Object
42 43 44 45 46 47 48 49 50 |
# File 'lib/superhosting/config_executor/container.rb', line 42 def run_commands self.commands.each do |cmd| if cmd == :container_restart self.container.lib.signature.delete!(logger: false) else self.command! cmd end end end |