Class: FeedCache::Fetcher

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/feed_cache/fetcher.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url, options = {}) ⇒ Fetcher

Returns a new instance of Fetcher.



16
17
18
19
20
# File 'lib/feed_cache/fetcher.rb', line 16

def initialize(url, options = {})
  raise "cache must be set with FeedCache.cache=" unless cache
  @url = url
  @options = { :expires_in => FeedCache.default_expires_in }.merge options
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



8
9
10
# File 'lib/feed_cache/fetcher.rb', line 8

def options
  @options
end

#urlObject (readonly)

Returns the value of attribute url.



8
9
10
# File 'lib/feed_cache/fetcher.rb', line 8

def url
  @url
end

Instance Method Details

#cacheObject



12
13
14
# File 'lib/feed_cache/fetcher.rb', line 12

def cache
  FeedCache.cache
end

#fetchObject



22
23
24
25
26
# File 'lib/feed_cache/fetcher.rb', line 22

def fetch
  @fz_feed = cache.fetch(cache_key, options) do
    Feedzirra::Feed.fetch_and_parse(url)
  end
end

#valid_feed?Boolean

Returns:

  • (Boolean)


28
29
30
31
32
# File 'lib/feed_cache/fetcher.rb', line 28

def valid_feed?
  # Feedzirra returns fixnums in error conditions, so we
  # need to type check.
  @fz_feed && ! @fz_feed.is_a?(Fixnum)
end