Class: QiitaMail::Storage

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename = Storage.default_filename) ⇒ Storage

Returns a new instance of Storage.



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

def initialize(filename = Storage.default_filename)
  @filename = filename
  
  if File.exist?(@filename)
    @data = MarshalFile.load(@filename)
  else
    @data = {}
  end
end

Class Method Details

.default_filenameObject



12
13
14
# File 'lib/qiita_mail/storage.rb', line 12

def self.default_filename
  File.expand_path('~/.qiita_mail.marshal')
end

Instance Method Details

#add_reading(uuid) ⇒ Object



26
27
28
29
# File 'lib/qiita_mail/storage.rb', line 26

def add_reading(uuid)
  @data[:reading] ||= {}
  @data[:reading][uuid] = true
end

#reading?(uuid) ⇒ Boolean

Returns:

  • (Boolean)


31
32
33
34
35
36
37
# File 'lib/qiita_mail/storage.rb', line 31

def reading?(uuid)
  if @data.has_key? :reading
    @data[:reading].has_key? uuid
  else
    false
  end
end

#saveObject



39
40
41
# File 'lib/qiita_mail/storage.rb', line 39

def save
  MarshalFile.save(@filename, @data)
end