class Sticky::Store

Attributes

store[R]

Public Class Methods

new(config = Sticky::Config.new) click to toggle source
# File lib/sticky/store.rb, line 8
def initialize(config = Sticky::Config.new)
  klass = Object.const_get(config.fetch(:store))
  @store = klass.new(config.fetch(:sticky_path))
end

Public Instance Methods

delete!(tag) click to toggle source
# 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) { |sticky| ... } click to toggle source
# 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.timestamp&.to_date)
        yield sticky
      end
    end
  end
end
save!(sticky) click to toggle source
# File lib/sticky/store.rb, line 36
def save!(sticky)
  store.transaction do
    store[:sticky_notes] ||= []
    store[:sticky_notes] << sticky
  end
end