Module: FeedCache
- Defined in:
- lib/feed_cache.rb,
lib/feed_cache/fetcher.rb,
lib/feed_cache/version.rb
Defined Under Namespace
Classes: Fetcher, MissingEntries
Constant Summary
collapse
- DEFAULT_ENTRIES_LIMIT =
10
- DEFAULT_EXPIRES_IN =
900
- VERSION =
"0.1.0"
Class Attribute Summary collapse
Class Method Summary
collapse
Class Attribute Details
.cache ⇒ Object
Returns the value of attribute cache.
8
9
10
|
# File 'lib/feed_cache.rb', line 8
def cache
@cache
end
|
.default_entries_limit ⇒ Object
11
12
13
|
# File 'lib/feed_cache.rb', line 11
def default_entries_limit
@default_entries_limit || DEFAULT_ENTRIES_LIMIT
end
|
.default_expires_in ⇒ Object
15
16
17
|
# File 'lib/feed_cache.rb', line 15
def default_expires_in
@default_expires_in || DEFAULT_EXPIRES_IN
end
|
Class Method Details
19
20
21
|
# File 'lib/feed_cache.rb', line 19
def configure(&block)
yield self
end
|
.entries_for(url, options = {}) ⇒ Object
31
32
33
34
35
36
37
38
39
|
# File 'lib/feed_cache.rb', line 31
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
|
.fetch(url, options = {}) ⇒ Object
25
26
27
28
29
|
# File 'lib/feed_cache.rb', line 25
def self.fetch(url, options = {})
feed = FeedCache::Fetcher.new(url, options)
feed.fetch
feed.valid_feed? ? feed : nil
end
|