Sha256: 8e505c0bfbb9ece3ff0d5395d406e1807435526de5919f833d52b98ca9a8c319

Contents?: true

Size: 923 Bytes

Versions: 6

Compression:

Stored size: 923 Bytes

Contents

require 'pstore'

module FeedTorrents
  def self.store
    Store.instance
  end

  class Store
    include Singleton
    include LogFunctions

    def present?(item)
      pstore.transaction(true) { return !!pstore[item] }
    end

    def persist(item)
      pstore.transaction { pstore[item] = Time.now.to_i }
    end

    def prune
      prune_count = 0

      pstore.transaction do
        pstore.roots.each do |item|
          if outdated?(item)
            pstore.delete(item)
            prune_count += 1
          end
        end
      end

      if prune_count > 0
        info "Pruned #{prune_count} items"
      end
    end

    private

    def pstore
      @pstore ||= PStore.new(pstore_file)
    end

    def pstore_file
      File.expand_path(FeedTorrents.configuration.datastore)
    end

    def outdated?(time)
      (Time.now.to_i - time.to_i < 7776000) # older than 90 days is outdated
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
feed_torrents-0.2.2 lib/feed_torrents/store.rb
feed_torrents-0.2.1 lib/feed_torrents/store.rb
feed_torrents-0.2.0 lib/feed_torrents/store.rb
feed_torrents-0.1.5 lib/feed_torrents/store.rb
feed_torrents-0.1.4 lib/feed_torrents/store.rb
feed_torrents-0.1.3 lib/feed_torrents/store.rb