Class: Pluto::Model::Item
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Pluto::Model::Item
- Includes:
- FeedFilter::AdsFilter, TextUtils::HypertextHelper
- Defined in:
- lib/pluto/models/item.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#debug=(value) ⇒ Object
logging w/ ActiveRecord todo/check: check if logger instance method is present by default? only class method present? what’s the best way to add logging to activerecord (use “builtin” machinery??).
- #debug? ⇒ Boolean
-
#desc ⇒ Object
alias (2) for summary – also add descr shortcut??.
-
#description ⇒ Object
alias for summary – also add descr shortcut??.
-
#link ⇒ Object
alias for url.
-
#name ⇒ Object
attribute reader aliases.
- #published ⇒ Object
-
#published? ⇒ Boolean
note: published is basically an alias for created.
- #update_from_struct!(data) ⇒ Object
- #updated ⇒ Object
- #updated? ⇒ Boolean
Class Method Details
.latest ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/pluto/models/item.rb', line 35 def self.latest # note: order by first non-null datetime field # coalesce - supported by sqlite (yes), postgres (yes) # note: if not updated,published use hardcoded 1971-01-01 for now order( "coalesce(items.updated,items.published,'1971-01-01') desc" ) end |
Instance Method Details
#debug=(value) ⇒ Object
logging w/ ActiveRecord
todo/check: check if logger instance method is present by default?
only class method present?
what's the best way to add logging to activerecord (use "builtin" machinery??)
13 |
# File 'lib/pluto/models/item.rb', line 13 def debug=(value) @debug = value; end |
#debug? ⇒ Boolean
14 |
# File 'lib/pluto/models/item.rb', line 14 def debug?() @debug || false; end |
#desc ⇒ Object
alias (2) for summary – also add descr shortcut??
31 |
# File 'lib/pluto/models/item.rb', line 31 def desc() summary; end |
#description ⇒ Object
alias for summary – also add descr shortcut??
30 |
# File 'lib/pluto/models/item.rb', line 30 def description() summary; end |
#link ⇒ Object
alias for url
32 |
# File 'lib/pluto/models/item.rb', line 32 def link() url; end |
#name ⇒ Object
attribute reader aliases
29 |
# File 'lib/pluto/models/item.rb', line 29 def name() title; end |
#published ⇒ Object
52 53 54 55 56 |
# File 'lib/pluto/models/item.rb', line 52 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
note: published is basically an alias for created
44 |
# File 'lib/pluto/models/item.rb', line 44 def published?() read_attribute(:published).present?; end |
#update_from_struct!(data) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/pluto/models/item.rb', line 60 def update_from_struct!( data ) logger = LogUtils::Logger.root ## check: new item/record? not saved? add guid # otherwise do not add guid - why? why not? ## note: for now also strip ads in summary ## fix/todo: summary (in the future) is supposed to be only plain vanilla text item_attribs = { guid: data.guid, # todo: only add for new records??? title: data.title ? (data.title)[0...255] : data.title, ## limit to 255 chars; strip tags url: data.url, summary: data.summary.blank? ? data.summary : strip_ads( data.summary ).strip, content: data.content.blank? ? data.content : strip_ads( data.content ).strip, updated: data.updated, published: data.published, } if debug? logger.debug "*** dump item_attribs w/ class types:" item_attribs.each do |key,value| next if [:summary,:content].include?( key ) # skip summary n content logger.debug " #{key}: >#{value}< : #{value.class.name}" end end update_attributes!( item_attribs ) end |
#updated ⇒ Object
46 47 48 49 50 |
# File 'lib/pluto/models/item.rb', line 46 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
43 |
# File 'lib/pluto/models/item.rb', line 43 def updated?() read_attribute(:updated).present?; end |