Class: OsCtld::Container::RawConfigs

Inherits:
Object
  • Object
show all
Includes:
Lockable
Defined in:
lib/osctld/container/raw_configs.rb

Constant Summary collapse

KEYS =
%i(lxc)

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Lockable

#exclusively, included, #inclusively, #init_lock, #lock, #unlock

Constructor Details

#initialize(configs = {}) ⇒ RawConfigs

Returns a new instance of RawConfigs.

Parameters:

  • configs (Hash<Symbol, String>) (defaults to: {})


15
16
17
18
19
# File 'lib/osctld/container/raw_configs.rb', line 15

def initialize(configs = {})
  init_lock
  @data = {}
  KEYS.each { |k| @data[k] = configs[k] }
end

Class Method Details

.load(config) ⇒ Object

Parameters:

  • config (Hash<String, String>)


10
11
12
# File 'lib/osctld/container/raw_configs.rb', line 10

def self.load(config)
  new(Hash[config.map { |k, v| [k.to_sym, v] }])
end

Instance Method Details

#dumpObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/osctld/container/raw_configs.rb', line 31

def dump
  inclusively do
    if @data.empty?
      nil
    else
      ret = {}

      @data.each do |k, v|
        ret[k.to_s] = v if v
      end

      ret
    end
  end
end

#dupObject



47
48
49
50
51
52
# File 'lib/osctld/container/raw_configs.rb', line 47

def dup
  ret = super
  ret.init_lock
  ret.instance_variable_set('@data', @data.clone)
  ret
end