Class: Superhosting::ScriptExecutor::Container

Inherits:
Base
  • Object
show all
Defined in:
lib/superhosting/script_executor/container.rb

Direct Known Subclasses

Site

Instance Attribute Summary collapse

Attributes inherited from Base

#commands, #lib, #model

Instance Method Summary collapse

Methods inherited from Base

#execute

Methods included from Helpers

#create_conf, #erb, #instance_variables_to_hash, #remove_line_from_file, #write_if_not_exist

Constructor Details

#initialize(container:, container_name:, container_lib:, registry_path:, on_reconfig_only: false, **kwargs) ⇒ Container

Returns a new instance of Container.



6
7
8
9
10
11
12
13
# File 'lib/superhosting/script_executor/container.rb', line 6

def initialize(container:, container_name:, container_lib:, registry_path:, on_reconfig_only: false, **kwargs)
  self.container = container
  self.container_name = container_name
  self.container_lib = container_lib
  self.registry_path = registry_path
  self.on_reconfig_only = on_reconfig_only
  super(**kwargs)
end

Instance Attribute Details

#containerObject

Returns the value of attribute container.



4
5
6
# File 'lib/superhosting/script_executor/container.rb', line 4

def container
  @container
end

#container_libObject

Returns the value of attribute container_lib.



4
5
6
# File 'lib/superhosting/script_executor/container.rb', line 4

def container_lib
  @container_lib
end

#container_nameObject

Returns the value of attribute container_name.



4
5
6
# File 'lib/superhosting/script_executor/container.rb', line 4

def container_name
  @container_name
end

#on_reconfig_onlyObject

Returns the value of attribute on_reconfig_only.



4
5
6
# File 'lib/superhosting/script_executor/container.rb', line 4

def on_reconfig_only
  @on_reconfig_only
end

#registry_pathObject

Returns the value of attribute registry_path.



4
5
6
# File 'lib/superhosting/script_executor/container.rb', line 4

def registry_path
  @registry_path
end

Instance Method Details

#config(save_to, script, **options) ⇒ Object



15
16
17
18
19
20
21
22
23
24
# File 'lib/superhosting/script_executor/container.rb', line 15

def config(save_to, script, **options)
  unless self.on_reconfig_only
    script_mapper = self.container.f(script, default: self.model.f(script))
    raise NetStatus::Exception.new(error: :error, message: 'File does not exist') if script_mapper.nil?
    opts = instance_variables_to_hash(self).merge(options)
    FileUtils.mkdir_p File.dirname(save_to)
    File.open(save_to, 'w') {|f| f.write(erb(script_mapper, **opts)) }
    create_conf(self.registry_path, save_to)
  end
end

#on_reconfig(cmd) ⇒ Object

def container_config(save_to, script, **options)

raise NetStatus::Exception.new(error: :error, message: "File '#{save_to}' has incorrect name format") if save_to.include? File::SEPARATOR
config(File.join(self.lib_configs._path, save_to), script, options)

end



31
32
33
# File 'lib/superhosting/script_executor/container.rb', line 31

def on_reconfig(cmd)
  self.commands << cmd
end