Class: Pluto::Model::Feed
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Pluto::Model::Feed
- Includes:
- TextUtils::HypertextHelper
- Defined in:
- lib/pluto/models/feed.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#author_email ⇒ Object
alias(2) for email.
-
#author_name ⇒ Object
alias for author.
- #debug=(value) ⇒ Object
- #debug? ⇒ Boolean
- #deep_update_from_struct!(data) ⇒ Object
-
#desc ⇒ Object
alias(2) for summary.
-
#description ⇒ Object
alias for summary.
-
#feed ⇒ Object
alias for feed_url.
- #feed_url ⇒ Object
- #feed_url? ⇒ Boolean
-
#link ⇒ Object
alias for url.
-
#name ⇒ Object
attribute reader aliases.
-
#owner ⇒ Object
alias(3) for author.
-
#owner_name ⇒ Object
alias(2) for author.
- #published ⇒ Object
- #published? ⇒ Boolean
-
#subtitle ⇒ Object
alias(3) for summary.
- #summary? ⇒ Boolean
- #title ⇒ Object
- #title? ⇒ Boolean
- #update_from_struct!(data) ⇒ Object
- #updated ⇒ Object
- #updated? ⇒ Boolean
- #url ⇒ Object
- #url? ⇒ Boolean
Class Method Details
.latest ⇒ Object
20 21 22 23 24 25 26 27 |
# File 'lib/pluto/models/feed.rb', line 20 def self.latest # note: order by first non-null datetime field # coalesce - supported by sqlite (yes), postgres (yes) # note: if not updated or published use hardcoded 1971-01-01 for now ## order( "coalesce(updated,published,'1971-01-01') desc" ) order( "coalesce(feeds.items_last_updated,'1971-01-01') desc" ) end |
Instance Method Details
#author_email ⇒ Object
alias(2) for email
44 |
# File 'lib/pluto/models/feed.rb', line 44 def () email; end |
#author_name ⇒ Object
alias for author
41 |
# File 'lib/pluto/models/feed.rb', line 41 def () ; end |
#debug=(value) ⇒ Object
75 |
# File 'lib/pluto/models/feed.rb', line 75 def debug=(value) @debug = value; end |
#debug? ⇒ Boolean
76 |
# File 'lib/pluto/models/feed.rb', line 76 def debug?() @debug || false; end |
#deep_update_from_struct!(data) ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/pluto/models/feed.rb', line 79 def deep_update_from_struct!( data ) ###### ## check for filters (includes/excludes) if present ## for now just check for includes ## if includes.present? includesFilter = FeedFilter::IncludeFilters.new( includes ) else includesFilter = nil end data.items.each do |item| if includesFilter && includesFilter.match_item?( item ) == false puts "** SKIPPING | #{item.title}" puts " no include terms match: #{includes}" next ## skip to next item end item_rec = Item.find_by_guid( item.guid ) if item_rec.nil? item_rec = Item.new puts "** NEW | #{item.title}" else ## todo: check if any attribs changed puts "UPDATE | #{item.title}" end item_rec.debug = debug? ? true : false # pass along debug flag item_rec.feed_id = id # feed_rec.id - add feed_id fk_ref item_rec.fetched = fetched # feed_rec.fetched item_rec.update_from_struct!( item ) end # each item # update cached value last published for item ## todo/check: force reload of items - why? why not?? last_item_rec = items.latest.limit(1).first # note limit(1) will return relation/arrar - use first to get first element or nil from ary if last_item_rec.present? if last_item_rec.updated? self.items_last_updated = last_item_rec.updated ## save! ## note: will get save w/ update_from_struct! - why? why not?? else # try published self.items_last_updated = last_item_rec.published ## save! ## note: will get save w/ update_from_struct! - why? why not?? end end update_from_struct!( data ) end |
#desc ⇒ Object
alias(2) for summary
36 |
# File 'lib/pluto/models/feed.rb', line 36 def desc() summary; end |
#description ⇒ Object
alias for summary
35 |
# File 'lib/pluto/models/feed.rb', line 35 def description() summary; end |
#feed ⇒ Object
alias for feed_url
39 |
# File 'lib/pluto/models/feed.rb', line 39 def feed() feed_url; end |
#feed_url ⇒ Object
54 |
# File 'lib/pluto/models/feed.rb', line 54 def feed_url() read_attribute_w_fallbacks( :feed_url, :auto_feed_url ); end |
#feed_url? ⇒ Boolean
50 |
# File 'lib/pluto/models/feed.rb', line 50 def feed_url?() read_attribute(:feed_url).present?; end |
#link ⇒ Object
alias for url
38 |
# File 'lib/pluto/models/feed.rb', line 38 def link() url; end |
#name ⇒ Object
attribute reader aliases
todo: check if we can use alias_method :name, :title - works for non-existing/on-demand-generated method too??
34 |
# File 'lib/pluto/models/feed.rb', line 34 def name() title; end |
#owner ⇒ Object
alias(3) for author
43 |
# File 'lib/pluto/models/feed.rb', line 43 def owner() ; end |
#owner_name ⇒ Object
alias(2) for author
42 |
# File 'lib/pluto/models/feed.rb', line 42 def owner_name() ; end |
#published ⇒ Object
68 69 70 71 72 |
# File 'lib/pluto/models/feed.rb', line 68 def published ## todo/fix: use a new name - do NOT squeeze convenience lookup into existing # db backed attribute read_attribute_w_fallbacks( :published, :updated ) end |
#published? ⇒ Boolean
60 |
# File 'lib/pluto/models/feed.rb', line 60 def published?() read_attribute(:published).present?; end |
#subtitle ⇒ Object
alias(3) for summary
37 |
# File 'lib/pluto/models/feed.rb', line 37 def subtitle() summary; end |
#summary? ⇒ Boolean
56 |
# File 'lib/pluto/models/feed.rb', line 56 def summary?() read_attribute(:summary).present?; end |
#title ⇒ Object
53 |
# File 'lib/pluto/models/feed.rb', line 53 def title() read_attribute_w_fallbacks( :title, :auto_title ); end |
#title? ⇒ Boolean
49 |
# File 'lib/pluto/models/feed.rb', line 49 def title?() read_attribute(:title).present?; end |
#update_from_struct!(data) ⇒ Object
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 |
# File 'lib/pluto/models/feed.rb', line 134 def update_from_struct!( data ) ## # todo: ## strip all tags from summary (subtitle) ## limit to 255 chars ## e.g. summary (subtitle) such as this exist ## This is a low-traffic announce-only list for people interested ## in hearing news about Polymer (<a href="http://polymer-project.org">http://polymer-project.org</a>). ## The higher-traffic mailing list for all kinds of discussion is ## <a href="https://groups.google.com/group/polymer-dev">https://groups.google.com/group/polymer-dev</a> feed_attribs = { format: data.format, updated: data.updated, published: data.published, summary: data.summary, generator: data.generator.to_s, ## note: use single-line/string generator stringified -- might return null (if no data) ### todo/fix: add/use # auto_title: ???, # auto_url: ???, # auto_feed_url: ???, } if debug? ## puts "*** dump feed_attribs:" ## pp feed_attribs puts "*** dump feed_attribs w/ class types:" feed_attribs.each do |key,value| puts " #{key}: >#{value}< : #{value.class.name}" end end update_attributes!( feed_attribs ) end |
#updated ⇒ Object
62 63 64 65 66 |
# File 'lib/pluto/models/feed.rb', line 62 def updated ## todo/fix: use a new name - do NOT squeeze convenience lookup into existing # db backed attribute read_attribute_w_fallbacks( :updated, :published ) end |
#updated? ⇒ Boolean
59 |
# File 'lib/pluto/models/feed.rb', line 59 def updated?() read_attribute(:updated).present?; end |
#url ⇒ Object
52 |
# File 'lib/pluto/models/feed.rb', line 52 def url() read_attribute_w_fallbacks( :url, :auto_url ); end |
#url? ⇒ Boolean
48 |
# File 'lib/pluto/models/feed.rb', line 48 def url?() read_attribute(:url).present?; end |