Class: Hastie::ConfigFile
- Inherits:
-
Object
- Object
- Hastie::ConfigFile
- Defined in:
- lib/hastie/config_file.rb
Class Method Summary collapse
-
.append(filename, data) ⇒ Object
very lazy.
-
.load(filename, root = nil) ⇒ Object
takes yaml filename outputs thor’s hash with indifferent access of content if input file cannot be read, empty thor hash is returned.
- .write(filename, data) ⇒ Object
Class Method Details
.append(filename, data) ⇒ Object
very lazy. very limited only use for _reports.yml
32 33 34 35 36 37 38 39 40 |
# File 'lib/hastie/config_file.rb', line 32 def self.append filename, data if !File.exists? filename puts "ERROR: #{filename} not found" return end File.open(filename, 'a') do |file| file.puts "- #{data}" end end |
.load(filename, root = nil) ⇒ Object
takes yaml filename outputs thor’s hash with indifferent access of content if input file cannot be read, empty thor hash is returned
10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/hastie/config_file.rb', line 10 def self.load filename, root = nil if !File.exists? filename return end output = Thor::CoreExt::HashWithIndifferentAccess.new() config = YAML.load(File.read(filename)) if config if root config = {root => config} end output = Thor::CoreExt::HashWithIndifferentAccess.new(config) end output end |
.write(filename, data) ⇒ Object
25 26 27 28 |
# File 'lib/hastie/config_file.rb', line 25 def self.write filename, data output_data = data.to_hash.to_yaml File.open(filename, 'w') {|file| file.puts output_data} end |