Class: AnyStyle::Dictionary::Marshal

Inherits:
AnyStyle::Dictionary show all
Defined in:
lib/anystyle/dictionary/marshal.rb

Instance Attribute Summary

Attributes inherited from AnyStyle::Dictionary

#db, #options

Instance Method Summary collapse

Methods inherited from AnyStyle::Dictionary

#close, create, #empty?, #get, instance, #open?, #populate!, #put, #tag_counts, #tags, #truncate

Constructor Details

#initialize(options = {}) ⇒ Marshal

Returns a new instance of Marshal.


8
9
10
# File 'lib/anystyle/dictionary/marshal.rb', line 8

def initialize(options = {})
  super(self.class.defaults.merge(options))
end

Instance Method Details

#openObject


12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/anystyle/dictionary/marshal.rb', line 12

def open
  if File.exists?(options[:path])
    @db = ::Marshal.load(File.open(options[:path]))
  else
    @db = {}
  end
  self
ensure
  if empty?
    populate!
    if File.writable?(options[:path])
      ::Marshal.dump(db, File.open(options[:path], 'wb'))
    end
  end
end