Class: Entry

ApplicationRecord show all
Defined in:


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.


  • (Boolean)

# File 'app/models/entry.rb', line 68

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