Class: Sticky::Store
- Inherits:
-
Object
- Object
- Sticky::Store
- Defined in:
- lib/sticky/store.rb
Instance Attribute Summary collapse
-
#store ⇒ Object
readonly
Returns the value of attribute store.
Instance Method Summary collapse
- #delete!(tag) ⇒ Object
- #fetch(tag = nil, date = nil) ⇒ Object
-
#initialize(config = Sticky::Config.new) ⇒ Store
constructor
A new instance of Store.
- #save!(sticky) ⇒ Object
Constructor Details
Instance Attribute Details
#store ⇒ Object (readonly)
Returns the value of attribute store.
6 7 8 |
# File 'lib/sticky/store.rb', line 6 def store @store end |
Instance Method Details
#delete!(tag) ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'lib/sticky/store.rb', line 27 def delete!(tag) if tag store.transaction do store[:sticky_notes] || [] store[:sticky_notes].reject! { |sticky| sticky.tag == tag } end end end |
#fetch(tag = nil, date = nil) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/sticky/store.rb', line 13 def fetch(tag = nil, date = nil) # FIXME: this is ugly, refactor this store.transaction do store[:sticky_notes] || [] store[:sticky_notes].each do |sticky| if block_given? && ((tag.nil? && date.nil?) \ || tag == sticky.tag \ || date&.to_date == sticky.&.to_date) yield sticky end end end end |
#save!(sticky) ⇒ Object
36 37 38 39 40 41 |
# File 'lib/sticky/store.rb', line 36 def save!(sticky) store.transaction do store[:sticky_notes] ||= [] store[:sticky_notes] << sticky end end |