Module: Unread::Reader::Scopes
- Defined in:
- lib/unread/reader_scopes.rb
Instance Method Summary collapse
- #have_not_read(readable) ⇒ Object
- #have_read(readable) ⇒ Object
- #join_read_marks(readable) ⇒ Object
-
#reader_scope ⇒ Object
This class method may be overriden to restrict readers to a subset of records It must return self or a ActiveRecord::Relation.
- #with_read_marks_for(readable) ⇒ Object
Instance Method Details
#have_not_read(readable) ⇒ Object
21 22 23 |
# File 'lib/unread/reader_scopes.rb', line 21 def have_not_read(readable) join_read_marks(readable).where("#{ReadMark.quoted_table_name}.id IS NULL") end |
#have_read(readable) ⇒ Object
25 26 27 |
# File 'lib/unread/reader_scopes.rb', line 25 def have_read(readable) join_read_marks(readable).where("#{ReadMark.quoted_table_name}.id IS NOT NULL") end |
#join_read_marks(readable) ⇒ Object
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/unread/reader_scopes.rb', line 10 def join_read_marks(readable) assert_readable(readable) joins "LEFT JOIN #{ReadMark.quoted_table_name} ON #{ReadMark.quoted_table_name}.readable_type = '#{readable.class.readable_parent.name}' AND (#{ReadMark.quoted_table_name}.readable_id = #{quote_bound_value(readable.id)} OR #{ReadMark.quoted_table_name}.readable_id IS NULL) AND #{ReadMark.quoted_table_name}.reader_id = #{quoted_table_name}.#{quoted_primary_key} AND #{ReadMark.quoted_table_name}.reader_type = '#{connection.quote_string base_class.name}' AND #{ReadMark.quoted_table_name}.timestamp >= '#{connection.quoted_date readable.send(readable.class.[:on])}'" end |
#reader_scope ⇒ Object
This class method may be overriden to restrict readers to a subset of records It must return self or a ActiveRecord::Relation
6 7 8 |
# File 'lib/unread/reader_scopes.rb', line 6 def reader_scope self end |
#with_read_marks_for(readable) ⇒ Object
29 30 31 32 33 34 35 36 |
# File 'lib/unread/reader_scopes.rb', line 29 def with_read_marks_for(readable) postgresql_string_cast = using_postgresql? ? '::varchar' : '' join_read_marks(readable).select("#{quoted_table_name}.*, #{ReadMark.quoted_table_name}.id AS read_mark_id, #{quote_bound_value(readable.class.name)}#{postgresql_string_cast} AS read_mark_readable_type, #{quote_bound_value(readable.id)} AS read_mark_readable_id") end |