Class: Lxc::FileConfig
- Inherits:
-
Object
- Object
- Lxc::FileConfig
- Defined in:
- lib/elecksee/lxc_file_config.rb
Overview
Configuration file interface
Instance Attribute Summary collapse
-
#path ⇒ String
readonly
Path to config file.
-
#state ⇒ AttrubuteStruct
Config file contents.
Instance Method Summary collapse
-
#generate_content ⇒ String
Generate config file content from current value of state.
-
#initialize(path) ⇒ FileConfig
constructor
Create new instance.
-
#state_hash ⇒ Smash
Hash like dump of state.
-
#write! ⇒ Integer
Overwrite the config file.
Constructor Details
#initialize(path) ⇒ FileConfig
Create new instance
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
#path ⇒ String (readonly)
Returns path to config file.
30 31 32 |
# File 'lib/elecksee/lxc_file_config.rb', line 30 def path @path end |
#state ⇒ AttrubuteStruct
Returns config file contents.
32 33 34 |
# File 'lib/elecksee/lxc_file_config.rb', line 32 def state @state end |
Instance Method Details
#generate_content ⇒ String
Generate config file content from current value of state
61 62 63 |
# File 'lib/elecksee/lxc_file_config.rb', line 61 def generate_content process_item(state_hash).flatten.join("\n") end |
#state_hash ⇒ Smash
Returns 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
54 55 56 |
# File 'lib/elecksee/lxc_file_config.rb', line 54 def write! File.write(path, generate_content) end |