Class: Vagrant::Notify::Data

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant-notify/data.rb

Instance Method Summary collapse

Constructor Details

#initialize(data_dir) ⇒ Data

Returns a new instance of Data.



4
5
6
# File 'lib/vagrant-notify/data.rb', line 4

def initialize(data_dir)
  @data_dir = data_dir
end

Instance Method Details

#[](key) ⇒ Object



17
18
19
20
# File 'lib/vagrant-notify/data.rb', line 17

def [](key)
  file = @data_dir.join(key.to_s)
  file.read if file.file?
end

#[]=(key, value) ⇒ Object



8
9
10
11
12
13
14
15
# File 'lib/vagrant-notify/data.rb', line 8

def []=(key, value)
  file = @data_dir.join(key.to_s)
  if value.nil?
    file.delete
  else
    file.open("w+") { |f| f.write(value) }
  end
end