Class: Pik::ConfigFile

Inherits:
Hash show all
Defined in:
lib/pik/config_file.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Hash

#to_yaml

Constructor Details

#initializeConfigFile

Returns a new instance of ConfigFile.



9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/pik/config_file.rb', line 9

def initialize
  @file = File.join(PIK_HOME, 'config.yml')
  @global = {}
  super
  if File.exists? @file
    contents = File.read( @file )
    unless contents.empty?
      documents = YAML.load_stream( contents )  
      self.update( documents[0] )
      @global.update( documents[1] ) if documents[1]
    end
  end
end

Instance Attribute Details

#globalObject (readonly)

Returns the value of attribute global.



7
8
9
# File 'lib/pik/config_file.rb', line 7

def global
  @global
end

Instance Method Details

#writeObject



23
24
25
26
27
# File 'lib/pik/config_file.rb', line 23

def write
  File.open(@file, 'w')do |f| 
    f.puts YAML::dump_stream( Hash[self]), YAML.dump(global) 
  end
end