Class: Lxc::FileConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/elecksee/lxc_file_config.rb

Overview

Configuration file interface

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ FileConfig

Create new instance

Parameters:

  • path (String)


37
38
39
40
41
42
43
44
# File 'lib/elecksee/lxc_file_config.rb', line 37

def initialize(path)
  @path = path
  if(File.exists?(path))
    parse!
  else
    @state = LxcStruct.new
  end
end

Instance Attribute Details

#pathString (readonly)

Returns path to config file.

Returns:

  • (String)

    path to config file



30
31
32
# File 'lib/elecksee/lxc_file_config.rb', line 30

def path
  @path
end

#stateAttrubuteStruct

Returns config file contents.

Returns:

  • (AttrubuteStruct)

    config file contents



32
33
34
# File 'lib/elecksee/lxc_file_config.rb', line 32

def state
  @state
end

Instance Method Details

#generate_contentString

Generate config file content from current value of state

Returns:

  • (String)


61
62
63
# File 'lib/elecksee/lxc_file_config.rb', line 61

def generate_content
  process_item(state_hash).flatten.join("\n")
end

#state_hashSmash

Returns hash like dump of state.

Returns:

  • (Smash)

    hash like dump of state



47
48
49
# File 'lib/elecksee/lxc_file_config.rb', line 47

def state_hash
  state._dump.to_smash
end

#write!Integer

Overwrite the config file

Returns:

  • (Integer)


54
55
56
# File 'lib/elecksee/lxc_file_config.rb', line 54

def write!
  File.write(path, generate_content)
end