Class: Pluto::Models::Item
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Pluto::Models::Item
- Includes:
- ActiveRecordMethods
- Defined in:
- lib/pluto/models/item.rb
Class Method Summary collapse
Instance Method Summary collapse
- #debug=(value) ⇒ Object
- #debug? ⇒ Boolean
-
#description ⇒ Object
alias for summary – also add descr shortcut??.
-
#link ⇒ Object
alias for url.
-
#name ⇒ Object
attribute reader aliases.
- #published ⇒ Object
- #published? ⇒ Boolean
- #update_from_struct!(feed_rec, data) ⇒ Object
Methods included from ActiveRecordMethods
Class Method Details
.latest ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/pluto/models/item.rb', line 17 def self.latest # note: order by first non-null datetime field # coalesce - supported by sqlite (yes), postgres (yes) # note: if not published,touched or built_at use hardcoded 1971-01-01 for now order( "coalesce(items.published,items.touched,'1971-01-01') desc" ) end |
Instance Method Details
#debug=(value) ⇒ Object
39 |
# File 'lib/pluto/models/item.rb', line 39 def debug=(value) @debug = value; end |
#debug? ⇒ Boolean
40 |
# File 'lib/pluto/models/item.rb', line 40 def debug?() @debug || false; end |
#description ⇒ Object
alias for summary – also add descr shortcut??
14 |
# File 'lib/pluto/models/item.rb', line 14 def description() summary; end |
#link ⇒ Object
alias for url
15 |
# File 'lib/pluto/models/item.rb', line 15 def link() url; end |
#name ⇒ Object
attribute reader aliases
13 |
# File 'lib/pluto/models/item.rb', line 13 def name() title; end |
#published ⇒ Object
27 28 29 30 31 32 33 34 35 |
# File 'lib/pluto/models/item.rb', line 27 def published ## todo/fix: use a new name - do NOT squeeze convenience lookup into existing # db backed attribute read_attribute_w_fallbacks( :published, :touched # try touched (aka updated RSS/ATOM) ) end |
#published? ⇒ Boolean
25 |
# File 'lib/pluto/models/item.rb', line 25 def published?() read_attribute(:published).present?; end |
#update_from_struct!(feed_rec, data) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/pluto/models/item.rb', line 42 def update_from_struct!( feed_rec, data ) ## check: new item/record? not saved? add guid # otherwise do not add guid - why? why not? item_attribs = { guid: data.guid, # todo: only add for new records??? title: data.title, url: data.url, summary: data.summary, content: data.content, published: data.published, touched: data.updated, feed_id: feed_rec.id, # add feed_id fk_ref fetched: feed_rec.fetched } if debug? puts "*** dump item_attribs w/ class types:" item_attribs.each do |key,value| next if [:summary,:content].include?( key ) # skip summary n content puts " #{key}: >#{value}< : #{value.class.name}" end end update_attributes!( item_attribs ) end |