Class: Pluto::Model::Feed

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
TextUtils::HypertextHelper
Defined in:
lib/pluto/models/feed.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.latestObject



32
33
34
35
36
37
38
39
# File 'lib/pluto/models/feed.rb', line 32

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_emailObject

alias(2) for email



56
# File 'lib/pluto/models/feed.rb', line 56

def author_email() email;   end

#author_nameObject

alias for author



53
# File 'lib/pluto/models/feed.rb', line 53

def author_name()  author;  end

#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??)


15
# File 'lib/pluto/models/feed.rb', line 15

def debug=(value)  @debug = value;   end

#debug?Boolean

Returns:

  • (Boolean)


16
# File 'lib/pluto/models/feed.rb', line 16

def debug?()       @debug || false;  end

#deep_update_from_struct!(data) ⇒ Object



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
132
133
134
135
136
137
138
139
140
141
142
# File 'lib/pluto/models/feed.rb', line 88

def deep_update_from_struct!( data )

  logger = LogUtils::Logger.root

  ######
  ## 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
      logger.info "** SKIPPING | #{item.title}"
      logger.info "  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
      logger.info "** NEW | #{item.title}"
    else
      ## todo: check if any attribs changed
      logger.info "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

#descObject

alias(2) for summary



48
# File 'lib/pluto/models/feed.rb', line 48

def desc()        summary;  end

#descriptionObject

alias for summary



47
# File 'lib/pluto/models/feed.rb', line 47

def description() summary;  end

#feedObject

alias for feed_url



51
# File 'lib/pluto/models/feed.rb', line 51

def feed()        feed_url; end

#feed_urlObject



66
# File 'lib/pluto/models/feed.rb', line 66

def feed_url() read_attribute_w_fallbacks( :feed_url, :auto_feed_url ); end

#feed_url?Boolean

Returns:

  • (Boolean)


62
# File 'lib/pluto/models/feed.rb', line 62

def feed_url?()      read_attribute(:feed_url).present?;  end

alias for url



50
# File 'lib/pluto/models/feed.rb', line 50

def link()        url;      end

#nameObject

attribute reader aliases

todo: check if we can use alias_method :name, :title   - works for non-existing/on-demand-generated method too??


46
# File 'lib/pluto/models/feed.rb', line 46

def name()        title;    end

#ownerObject

alias(3) for author



55
# File 'lib/pluto/models/feed.rb', line 55

def owner()        author;  end

#owner_nameObject

alias(2) for author



54
# File 'lib/pluto/models/feed.rb', line 54

def owner_name()   author;  end

#publishedObject



80
81
82
83
84
# File 'lib/pluto/models/feed.rb', line 80

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

Returns:

  • (Boolean)


72
# File 'lib/pluto/models/feed.rb', line 72

def published?()  read_attribute(:published).present?;  end

#subtitleObject

alias(3) for summary



49
# File 'lib/pluto/models/feed.rb', line 49

def subtitle()    summary;  end

#summary?Boolean

Returns:

  • (Boolean)


68
# File 'lib/pluto/models/feed.rb', line 68

def summary?()      read_attribute(:summary).present?;  end

#titleObject



65
# File 'lib/pluto/models/feed.rb', line 65

def title()    read_attribute_w_fallbacks( :title,    :auto_title );    end

#title?Boolean

Returns:

  • (Boolean)


61
# File 'lib/pluto/models/feed.rb', line 61

def title?()         read_attribute(:title).present?;     end

#update_from_struct!(data) ⇒ Object



145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
# File 'lib/pluto/models/feed.rb', line 145

def update_from_struct!( data )

  logger = LogUtils::Logger.root

##
# 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
      logger.debug "*** dump feed_attribs w/ class types:"
      feed_attribs.each do |key,value|
        logger.debug "  #{key}: >#{value}< : #{value.class.name}"
      end
  end

  update_attributes!( feed_attribs )
end

#updatedObject



74
75
76
77
78
# File 'lib/pluto/models/feed.rb', line 74

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

Returns:

  • (Boolean)


71
# File 'lib/pluto/models/feed.rb', line 71

def updated?()    read_attribute(:updated).present?;    end

#urlObject



64
# File 'lib/pluto/models/feed.rb', line 64

def url()      read_attribute_w_fallbacks( :url,      :auto_url );      end

#url?Boolean

Returns:

  • (Boolean)


60
# File 'lib/pluto/models/feed.rb', line 60

def url?()           read_attribute(:url).present?;       end