Module: Superhosting::Helper::Config

Included in:
Superhosting::Helpers
Defined in:
lib/superhosting/helper/config.rb

Instance Method Summary collapse

Instance Method Details

#_config(name:, on_reconfig:, on_config:) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/superhosting/helper/config.rb', line 49

def _config(name:, on_reconfig:, on_config:)
  mapper = self.index[name][:mapper]
  options = self._config_options(name: name, on_reconfig: on_reconfig, on_config: on_config)
  registry_mapper = options.delete(:registry_mapper)
  registry_files = []

  mapper.f('config.rb', overlay: false).reverse.each do |config|
    ex = ConfigExecutor.new(options)
    ex.execute(config)
    ex.run_commands
    registry_files += ex.registry_files
  end

  self._save_registry!(registry_mapper, registry_files) if on_config
end

#_config_options(name:, on_reconfig:, on_config:) ⇒ Object



65
66
67
# File 'lib/superhosting/helper/config.rb', line 65

def _config_options(name:, on_reconfig:, on_config:)
  {}
end

#_save_registry!(registry_mapper, registry_files) ⇒ Object



69
70
71
72
73
74
75
76
77
# File 'lib/superhosting/helper/config.rb', line 69

def _save_registry!(registry_mapper, registry_files)
  old_configs = registry_mapper.lines
  unless (old_configs = old_configs - registry_files).empty?
    self.debug_block(desc: { code: :deleting_old_configs }) do
      old_configs.each { |file| PathMapper.new(file).delete! }
    end
  end
  registry_mapper.override!(registry_files.join("\n"))
end

#apply(name:) ⇒ Object



25
26
27
28
# File 'lib/superhosting/helper/config.rb', line 25

def apply(name:)
  self._config(name: name, on_reconfig: true, on_config: false)
  {}
end

#configure(name:) ⇒ Object



4
5
6
7
# File 'lib/superhosting/helper/config.rb', line 4

def configure(name:)
  self._config(name: name, on_reconfig: false, on_config: true)
  {}
end

#configure_with_apply(name:) ⇒ Object



34
35
36
37
# File 'lib/superhosting/helper/config.rb', line 34

def configure_with_apply(name:)
  self._config(name: name, on_reconfig: true, on_config: true)
  {}
end

#reconfig(name:) ⇒ Object



44
45
46
47
# File 'lib/superhosting/helper/config.rb', line 44

def reconfig(name:)
  self.unconfigure(name: name)
  self.configure(name: name)
end

#unapply(name:) ⇒ Object



30
31
32
# File 'lib/superhosting/helper/config.rb', line 30

def unapply(name:)
  apply(name: name)
end

#unconfigure(name:) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/superhosting/helper/config.rb', line 9

def unconfigure(name:)
  case self.index[name][:mapper].parent.name
    when 'containers'
      registry_mapper = self.index[name][:mapper].lib.registry.container
    when 'sites'
      registry_mapper = self.index[name][:container_mapper].lib.registry.sites.f(name)
    else raise NetStatus::Exception, { error: :logical_error, code: :mapper_type_not_supported, data: { name: type } }
  end

  unless registry_mapper.nil?
    registry_mapper.lines.each {|path| PathMapper.new(path).delete! }
    registry_mapper.delete!
  end
  {}
end

#unconfigure_with_unapply(name:) ⇒ Object



39
40
41
42
# File 'lib/superhosting/helper/config.rb', line 39

def unconfigure_with_unapply(name:)
  self.unconfigure(name: name)
  self.unapply(name: name)
end