class Superhosting::ConfigExecutor::Container

Attributes

container[RW]
mux[RW]
mux_name[RW]
registry_files[RW]

Public Class Methods

new(container:, on_reconfig:, on_config:, mux: nil, **kwargs) click to toggle source
Calls superclass method Superhosting::ConfigExecutor::Base::new
# 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

Public Instance Methods

config(save_to, script=nil, **options) click to toggle source
# File lib/superhosting/config_executor/container.rb, line 24
def config(save_to, script=nil, **options)
  if @on_config
    save_to_mapper = PathMapper.new(save_to)
    script = options.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(options).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, options)
    self.registry_files << save_to_mapper.path.to_s
  end
end
mkdir(path, **options) click to toggle source
# File lib/superhosting/config_executor/container.rb, line 16
def mkdir(path, **options)
  if @on_config
    PathMapper.new(path).create!
    self.set_file_attributes(path, options)
    self.registry_files << path.to_s
  end
end
on_reconfig(cmd) click to toggle source
# File lib/superhosting/config_executor/container.rb, line 38
def on_reconfig(cmd)
  self.commands << cmd if @on_reconfig
end
run_commands() click to toggle source
# 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

Protected Instance Methods

base_mapper() click to toggle source
# File lib/superhosting/config_executor/container.rb, line 59
def base_mapper
  self.container
end
config_mapper(options) click to toggle source
# File lib/superhosting/config_executor/container.rb, line 63
def config_mapper(options)
  self.base_mapper.erb_options = instance_variables_to_hash(self).merge(options)
  self.base_mapper
end
set_file_attributes(path, user: nil, group: nil, mode: nil, **kwargs) click to toggle source
# File lib/superhosting/config_executor/container.rb, line 54
def set_file_attributes(path, user: nil, group: nil, mode: nil, **kwargs)
  chown!(user, group, path) if user and group
  chmod!(mode, path) if user and mode
end