Class: Rrant::Store
Overview
Public: Handles local storage using PStore and directory structure initialization. Serializes given rants for proper storage.
Instance Attribute Summary collapse
-
#images ⇒ Object
readonly
Returns the value of attribute images.
-
#root ⇒ Object
readonly
Returns the value of attribute root.
-
#store ⇒ Object
readonly
Returns the value of attribute store.
Instance Method Summary collapse
-
#add(rants) ⇒ Object
Public: Adds serialized rants as ‘entities’ and ‘ids’ to the store.
- #empty? ⇒ Boolean
-
#initialize(path = nil) ⇒ Store
constructor
Constructor: Initializes directories and store.
-
#touch(rant_id) ⇒ Object
Public: Finds rant with given ID and updates its ‘viewed_at’ parameter.
Methods included from Helper
#bill, #files_path, #image_blank?
Constructor Details
#initialize(path = nil) ⇒ Store
Constructor: Initializes directories and store.
path - Integer, directory where we want to store our rants/images
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/rrant/store.rb', line 16 def initialize(path = nil) path = path || Dir.home raise Error::InvalidPath unless Dir.exist?(path) @root = "#{path}/.rrant" @images = "#{@root}/images/" initialize_directories initialize_store end |
Instance Attribute Details
#images ⇒ Object (readonly)
Returns the value of attribute images.
11 12 13 |
# File 'lib/rrant/store.rb', line 11 def images @images end |
#root ⇒ Object (readonly)
Returns the value of attribute root.
11 12 13 |
# File 'lib/rrant/store.rb', line 11 def root @root end |
#store ⇒ Object (readonly)
Returns the value of attribute store.
11 12 13 |
# File 'lib/rrant/store.rb', line 11 def store @store end |
Instance Method Details
#add(rants) ⇒ Object
Public: Adds serialized rants as ‘entities’ and ‘ids’ to the store.
28 29 30 31 32 33 |
# File 'lib/rrant/store.rb', line 28 def add(rants) @store.transaction do @store[:ids] += build_ids(rants) @store[:entities] += build_entities(rants) end end |
#empty? ⇒ Boolean
35 36 37 |
# File 'lib/rrant/store.rb', line 35 def empty? ids.empty? end |
#touch(rant_id) ⇒ Object
Public: Finds rant with given ID and updates its ‘viewed_at’ parameter.
47 48 49 50 51 52 53 54 |
# File 'lib/rrant/store.rb', line 47 def touch(rant_id) @store.transaction do @store[:entities] = @store[:entities].map do |rant| rant['viewed_at'] = DateTime.now if rant['id'] == rant_id rant end end end |