Sha256: ca6d2e32bef0678315c3aa756d6f009acb033c10aa51676b98cf3146ae072060

Contents?: true

Size: 1.02 KB

Versions: 1

Compression:

Stored size: 1.02 KB

Contents

module FeedCache
  DEFAULT_ENTRIES_LIMIT = 10
  DEFAULT_EXPIRES_IN = 900

  class MissingEntries < StandardError; end

  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
    begin
      feed = fetch(url, options)
      (feed ? feed.entries : []).take(limit)
    rescue TypeError
      raise FeedCache::MissingEntries
    end
  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.1.0 lib/feed_cache.rb