Class: GridCLI::YMLHash

Inherits:
Hash
  • Object
show all
Defined in:
lib/gridcli/ymlhash.rb

Direct Known Subclasses

Config, Plugins, Stats, SubGrids

Instance Method Summary collapse

Constructor Details

#initialize(fname) ⇒ YMLHash

Returns a new instance of YMLHash.



5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/gridcli/ymlhash.rb', line 5

def initialize(fname)
  # Initialize the grid dir
  @griddir = File.expand_path(File.join("~", ".grid"))
  Dir.mkdir(@griddir) if not File.exists?(@griddir)

  # This is a hash, so initialize it, set w/ default config options, then set
  # with any config options in the ~/.grid/#{fname} file
  @conffile = File.join(@griddir, fname)
  super
  update default_config
  # if conf file exists, update this obj w/ it's values.  Otherwise, create file
  File.exists?(@conffile) ? update(YAML.load_file(@conffile)) : save
end

Instance Method Details

#default_configObject



19
20
21
# File 'lib/gridcli/ymlhash.rb', line 19

def default_config
  {}
end

#saveObject



23
24
25
# File 'lib/gridcli/ymlhash.rb', line 23

def save
  File.open(@conffile, 'w') { |f| YAML.dump(Hash.new.merge(self), f) }
end