Module: Tyrion::Storage::ClassMethods

Defined in:
lib/tyrion/storage.rb

Instance Method Summary collapse

Instance Method Details

#reloadObject



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/tyrion/storage.rb', line 14

def reload
  klass_name = to_s.downcase
  path = klass_filepath klass_name

  if File.exists?(path)
    raw_file = File.read(path)
    storage[klass_name] = MultiJson.decode(raw_file).map{ |doc| new(doc) }
  else
    storage[klass_name] = []
  end
end

#save_storage(klass_name) ⇒ Object



26
27
28
29
30
31
32
# File 'lib/tyrion/storage.rb', line 26

def save_storage klass_name
  path = klass_filepath klass_name

  File.open(path, 'w') do |f|
    f.puts MultiJson.encode(storage[klass_name].map &:attributes)
  end
end

#storageObject



10
11
12
# File 'lib/tyrion/storage.rb', line 10

def storage
  @storage ||= {}
end