Class: Omnom::Feed
- Inherits:
-
Object
- Object
- Omnom::Feed
- Defined in:
- lib/omnom/feed.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Class Method Summary collapse
- .filter(&block) ⇒ Object
- .inherited(child) ⇒ Object
- .key ⇒ Object
- .options ⇒ Object
- .sources(&block) ⇒ Object
- .template(template) ⇒ Object
Instance Method Summary collapse
-
#initialize ⇒ Feed
constructor
A new instance of Feed.
- #key ⇒ Object
- #posts ⇒ Object
- #source_by_source_id(source_id) ⇒ Object
- #source_by_source_key(source_key) ⇒ Object
- #sources ⇒ Object
- #template ⇒ Object
- #title ⇒ Object
- #update ⇒ Object
- #update_by_source_key(source_key = nil) ⇒ Object
- #update_source(source) ⇒ Object
Constructor Details
#initialize ⇒ Feed
Returns a new instance of Feed.
32 33 34 |
# File 'lib/omnom/feed.rb', line 32 def initialize @options = self.class. end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
30 31 32 |
# File 'lib/omnom/feed.rb', line 30 def @options end |
Class Method Details
.filter(&block) ⇒ Object
12 13 14 |
# File 'lib/omnom/feed.rb', line 12 def filter(&block) [:filter] = block end |
.inherited(child) ⇒ Object
4 5 6 |
# File 'lib/omnom/feed.rb', line 4 def inherited(child) Omnom.add_feed(child) end |
.key ⇒ Object
25 26 27 |
# File 'lib/omnom/feed.rb', line 25 def key name.underscore.gsub('/', '__') end |
.options ⇒ Object
8 9 10 |
# File 'lib/omnom/feed.rb', line 8 def @options ||= {key: self.key} end |
.sources(&block) ⇒ Object
16 17 18 19 |
# File 'lib/omnom/feed.rb', line 16 def sources(&block) config = FeedSourcesDSL.new(&block) [:sources] = config.sources end |
.template(template) ⇒ Object
21 22 23 |
# File 'lib/omnom/feed.rb', line 21 def template(template) [:template] = template end |
Instance Method Details
#key ⇒ Object
36 37 38 |
# File 'lib/omnom/feed.rb', line 36 def key self.class.key end |
#posts ⇒ Object
48 49 50 51 52 53 54 |
# File 'lib/omnom/feed.rb', line 48 def posts source_ids = sources.collect(&:source_id) Post.includes(:posts_origins).where( 'omnom_posts_origins.feed_key' => key, 'omnom_posts_origins.source_id' => source_ids ) end |
#source_by_source_id(source_id) ⇒ Object
86 87 88 89 90 91 92 |
# File 'lib/omnom/feed.rb', line 86 def source_by_source_id(source_id) source_id = source_id.to_s sources.each do |source| return source if source.source_id == source_id end nil end |
#source_by_source_key(source_key) ⇒ Object
94 95 96 97 98 99 100 |
# File 'lib/omnom/feed.rb', line 94 def source_by_source_key(source_key) source_key = source_key.to_s sources.each do |source| return source if source.key == source_key end nil end |
#sources ⇒ Object
77 78 79 80 81 82 83 84 |
# File 'lib/omnom/feed.rb', line 77 def sources if @options[:sources] @options[:sources].each do |source| source.feed_key = key end end @options[:sources] end |
#template ⇒ Object
44 45 46 |
# File 'lib/omnom/feed.rb', line 44 def template @options[:template] || :default end |
#title ⇒ Object
40 41 42 |
# File 'lib/omnom/feed.rb', line 40 def title key.gsub(/_feed$/, '').humanize end |
#update ⇒ Object
56 57 58 59 60 |
# File 'lib/omnom/feed.rb', line 56 def update sources.each do |source| source.update end end |
#update_by_source_key(source_key = nil) ⇒ Object
62 63 64 65 66 67 68 69 70 71 |
# File 'lib/omnom/feed.rb', line 62 def update_by_source_key(source_key=nil) if source_key source = source_by_source_key(source_key) raise "Source with source key '#{source_key}' not found in feed #{self.class}" and return if source.nil? source.update else return if sources.nil? sources.each(&:update) end end |
#update_source(source) ⇒ Object
73 74 75 |
# File 'lib/omnom/feed.rb', line 73 def update_source(source) source.update end |