Class: Entry

Inherits:
ApplicationRecord show all
Defined in:
app/models/entry.rb

Overview

Feed entry model. Each instance of this class represents an entry in an RSS or Atom feed.

Instances of this class are saved in the database when fetching and parsing feeds. It's not intended to be instanced by the user.

Each entry belongs to exactly one feed.

Each entry has many entry-states, exactly one for each user subscribed to the feed. Each entry-state indicates whether each user has read or not this entry.

When a new entry is saved in the database for the first time, it is marked as unread for all users subscribed to its feed (by saving as many entry_state instances as subscribed users into the database, all of them with the attribute “read” set to false).

Each entry is uniquely identified by its guid within the scope of a given feed. Duplicate guids are not allowed for the same feed.

When entries are deleted by an automated cleanup (because they are too old or the feed had too many entries), a new DeletedEntry instance is saved in the database with the same feed_id and guid as the deleted entry. An entry with the same guid and feed_id as an already existing DeletedEntry is not valid and won't be saved in the database (it would indicate an entry that is at once deleted and not deleted).

Attributes of the model:

  • feed_id

  • title

  • url

  • author

  • content

  • summary

  • published

  • guid

All fields except “published” and “feed_id” are sanitized before validation; this is, before saving/updating each instance in the database.

Instance Method Summary collapse

Instance Method Details

#read_by?(user) ⇒ Boolean

Return a boolean that indicates whether this entry has been marked as read by the passed user.

Receives as argument the user for which the read/unread state will be retrieved.

If the user is not actually subscribed to the feed, raises a NotSubscribedError.

Returns:

  • (Boolean)

68
69
70
71
72
73
74
75
# File 'app/models/entry.rb', line 68

def read_by?(user)
  state = EntryState.find_by entry_id: self.id, user_id: user.id
  if state.blank?
    Rails.logger.warn "Tried to find out if user #{user.id} - #{user.email} has read entry #{self.id} from feed #{self.feed_id} to which he is not subscribed. Raising an error."
    raise NotSubscribedError.new
  end
  return state.read
end