Class: Myredditnews::History

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

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ History

Returns a new instance of History.



162
163
164
165
166
# File 'lib/myredditnews.rb', line 162

def initialize path
  @path         = path
  @posted_queue = []
  @db           = PStore.new(File.expand_path @path)
end

Instance Method Details

#append_entries!Object



183
184
185
186
187
188
189
190
# File 'lib/myredditnews.rb', line 183

def append_entries!
  return if Myredditnews.dry
  @db.transaction do
    @posted_queue.each do |e|
      @db[e] = 0
    end
  end
end

#delete_all!Object



191
192
193
194
# File 'lib/myredditnews.rb', line 191

def delete_all!
  @db = nil
  File.delete @path if File.exists? @path
end

#filter(entries) ⇒ Object



167
168
169
170
171
# File 'lib/myredditnews.rb', line 167

def filter entries
  @db.transaction do
    entries.reject { |e| @db.root? e }
  end
end

#posted!(entry) ⇒ Object



180
181
182
# File 'lib/myredditnews.rb', line 180

def posted! entry
  @posted_queue << entry
end

#posted?(entry) ⇒ Boolean

TODO : the only reason this method was not removed is because it’s used in some tests

Returns:

  • (Boolean)


174
175
176
177
178
179
# File 'lib/myredditnews.rb', line 174

def posted? entry
  return true if @posted_queue.include? entry
  @db.transaction do
    @db.root? entry
  end
end