class Pluto::Model::Item

Public Class Methods

latest() click to toggle source
# 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 1970-01-01 for now
  order( Arel.sql( "coalesce(items.updated,items.published,'1970-01-01') desc" ) )
end

Public Instance Methods

data() click to toggle source

use a different name for data - why? why not?

e.g. inner, internal, readonly or r, raw, table, direct, or ???
# File lib/pluto/models/item.rb, line 84
def data()   @data ||= Data.new( self ); end
date() click to toggle source
add convenience date attribute helpers / readers
- what to return if date is nil? - return nil or empty string or 'n/a' or '?' - why? why not?

date date_iso | date_iso8601 date_822 | date_rfc2822 | date_rfc822

# File lib/pluto/models/item.rb, line 60
def date()        updated; end
date_822() click to toggle source
# File lib/pluto/models/item.rb, line 65
def date_822()    date ? date.rfc822 : ''; end
Also aliased as: date_rfc2822, date_rfc822
date_iso() click to toggle source
# File lib/pluto/models/item.rb, line 62
def date_iso()    date ? date.iso8601 : ''; end
Also aliased as: date_iso8601
date_iso8601()
Alias for: date_iso
date_rfc2822()
Alias for: date_822
date_rfc822()
Alias for: date_822
debug?() click to toggle source

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??)
# File lib/pluto/models/item.rb, line 14
def debug?()  Pluto.config.debug?;  end
published() click to toggle source
# File lib/pluto/models/item.rb, line 47
def published()  read_attribute_w_fallbacks( :published, :updated ); end
published?() click to toggle source
# File lib/pluto/models/item.rb, line 50
def published?() published.present?; end
update_from_struct!( data ) click to toggle source
# File lib/pluto/models/item.rb, line 87
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 ? strip_tags(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!( item_attribs )
end
updated() click to toggle source

note:

only use fallback for updated, that is, updated (or published)
 ~~do NOT use fallback for published / created    -- why? why not?~~
# File lib/pluto/models/item.rb, line 46
def updated()    read_attribute_w_fallbacks( :updated, :published ); end
updated?() click to toggle source
# File lib/pluto/models/item.rb, line 49
def updated?()   updated.present?;   end