Class: Nit::Config::File

Inherits:
Object
  • Object
show all
Defined in:
lib/nit/config.rb

Overview

Warning: this API will soon change.

Instance Method Summary collapse

Constructor Details

#initialize(name, app) ⇒ File

FIXME: i hate the app dependency for #create_file.



10
11
12
13
# File 'lib/nit/config.rb', line 10

def initialize(name, app) # FIXME: i hate the app dependency for #create_file.
  @name = name
  @app  = app
end

Instance Method Details

#read(key) ⇒ Object



15
16
17
18
# File 'lib/nit/config.rb', line 15

def read(key)
  return unless exist?
  yaml_hash[key]
end

#rm!Object



28
29
30
# File 'lib/nit/config.rb', line 28

def rm!
  @app.remove_file(@name)
end

#write(key, value) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/nit/config.rb', line 20

def write(key, value)
  @app.create_file(@name, Psych.dump({})) unless exist?

  hash = yaml_hash
  hash[key] = value
  ::File.open(@name, "w") { |f| f.write(Psych.dump(hash))  }
end