Class: Rrant::Local
Overview
Public: Contains local storage handling methods, operates on top of store object.
Instance Method Summary collapse
-
#initialize(store) ⇒ Local
constructor
A new instance of Local.
-
#random ⇒ Object
Public: Returns random rant from the store.
-
#unseen(set) ⇒ Object
Public: Sets ‘unseen’ instance variable and returns self.
Methods included from Helper
#bill, #files_path, #image_blank?
Constructor Details
#initialize(store) ⇒ Local
Returns a new instance of Local.
10 11 12 13 14 15 |
# File 'lib/rrant/local.rb', line 10 def initialize(store) raise Error::InvalidStore unless store.is_a?(Store) @store = store @unseen = false end |
Instance Method Details
#random ⇒ Object
Public: Returns random rant from the store. Returns placeholder if there are no available rants. Updates rant’s ‘viewed_at’ parameter.
19 20 21 22 23 24 25 |
# File 'lib/rrant/local.rb', line 19 def random return placeholder if @store.empty? rant = pick_random return placeholder unless rant rant.tap { |r| @store.touch(r['id']) } end |
#unseen(set) ⇒ Object
Public: Sets ‘unseen’ instance variable and returns self. With ‘unseen’ set to true, we fetch only rants with ‘viewed_at’ set to nil.
29 30 31 32 |
# File 'lib/rrant/local.rb', line 29 def unseen(set) @unseen = set self end |