Class: Madhouse::DataFile

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

Constant Summary collapse

DEFAULT_FILENAME =
'data.pstore'
DATA_ROOT =
'root'

Instance Method Summary collapse

Constructor Details

#initialize(namespace) ⇒ DataFile

Returns a new instance of DataFile.



30
31
32
# File 'lib/madhouse.rb', line 30

def initialize(namespace)
  @namespace = namespace
end

Instance Method Details

#contentObject



38
39
40
41
42
43
# File 'lib/madhouse.rb', line 38

def content
  return unless exist?
  store.transaction(true) do
    store[DATA_ROOT]
  end
end

#exist?Boolean

Returns:

  • (Boolean)


51
52
53
# File 'lib/madhouse.rb', line 51

def exist?
  File.exist?(location)
end

#locationObject



34
35
36
# File 'lib/madhouse.rb', line 34

def location
  File.expand_path(File.join('~', ".#{@namespace}", DEFAULT_FILENAME))
end

#update(data) ⇒ Object



45
46
47
48
49
# File 'lib/madhouse.rb', line 45

def update(data)
  store.transaction do
    store[DATA_ROOT] = data
  end
end