Class: NonConfig::ConfigFile
- Defined in:
- lib/non_config/config_file.rb
Overview
Hash with filepath and #save method
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
-
#initialize(path = nil) ⇒ ConfigFile
constructor
parses yaml from path.
-
#save ⇒ Object
rewrite file so you can save your changes.
Methods inherited from NonHash
#[]=, convert_array_subhashes, from_hash, #method_missing, #to_hash, #to_yaml
Constructor Details
#initialize(path = nil) ⇒ ConfigFile
parses yaml from path
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/non_config/config_file.rb', line 13 def initialize(path = nil) super() return unless path fail FileNotFound unless File.exist? path @path = path file_data = File.read @path records = YAML.load file_data merge! self.class.from_hash(records) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class NonConfig::NonHash
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
10 11 12 |
# File 'lib/non_config/config_file.rb', line 10 def path @path end |
Instance Method Details
#save ⇒ Object
rewrite file so you can save your changes
25 26 27 |
# File 'lib/non_config/config_file.rb', line 25 def save File.open(@path, 'w') { |f| f.write to_yaml } end |