Sha256: 3246b13db43f4658af88c608965dc3649ae913e440540c48f3c055ffffde3eb9

Contents?: true

Size: 917 Bytes

Versions: 1

Compression:

Stored size: 917 Bytes

Contents

module FeedCache
  DEFAULT_ENTRIES_LIMIT = 10
  DEFAULT_EXPIRES_IN = 900

  class << self
    attr_accessor :cache
    attr_writer :default_entries_limit, :default_expires_in

    def default_entries_limit
      @default_entries_limit || DEFAULT_ENTRIES_LIMIT
    end

    def default_expires_in
      @default_expires_in || DEFAULT_EXPIRES_IN
    end

    def configure(&block)
      yield self
    end
    alias_method :config, :configure
  end

  def self.fetch(url, options = {})
    feed = FeedCache::Fetcher.new(url, options)
    feed.fetch
    feed.valid_feed? ? feed : nil
  end

  def self.entries_for(url, options = {})
    limit = options.delete(:limit) || default_entries_limit
    feed = fetch(url, options)
    (feed ? feed.entries : []).take(limit)
  end
end

require File.expand_path("feed_cache/fetcher", File.dirname(__FILE__))
require File.expand_path("feed_cache/version", File.dirname(__FILE__))

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
feed_cache-0.0.1 lib/feed_cache.rb