module Unread::Readable::Scopes
Public Instance Methods
join_read_marks(reader)
click to toggle source
# File lib/unread/readable_scopes.rb, line 4 def join_read_marks(reader) assert_reader(reader) joins "LEFT JOIN #{ReadMark.quoted_table_name} ON #{ReadMark.quoted_table_name}.readable_type = '#{readable_parent.name}' AND #{ReadMark.quoted_table_name}.readable_id = #{quoted_table_name}.#{quoted_primary_key} AND #{ReadMark.quoted_table_name}.reader_id = #{quote_bound_value(reader.id)} AND #{ReadMark.quoted_table_name}.reader_type = #{quote_bound_value(reader.class.base_class.name)} AND #{ReadMark.quoted_table_name}.timestamp >= #{quoted_table_name}.#{connection.quote_column_name(readable_options[:on])}" end
read_by(reader)
click to toggle source
# File lib/unread/readable_scopes.rb, line 26 def read_by(reader) result = join_read_marks(reader) if global_time_stamp = reader.read_mark_global(self).try(:timestamp) result.where("#{ReadMark.quoted_table_name}.id IS NOT NULL OR #{quoted_table_name}.#{connection.quote_column_name(readable_options[:on])} <= ?", global_time_stamp) else result.where("#{ReadMark.quoted_table_name}.id IS NOT NULL") end end
unread_by(reader)
click to toggle source
# File lib/unread/readable_scopes.rb, line 15 def unread_by(reader) result = join_read_marks(reader) if global_time_stamp = reader.read_mark_global(self).try(:timestamp) result.where("#{ReadMark.quoted_table_name}.id IS NULL AND #{quoted_table_name}.#{connection.quote_column_name(readable_options[:on])} > ?", global_time_stamp) else result.where("#{ReadMark.quoted_table_name}.id IS NULL") end end
with_read_marks_for(reader)
click to toggle source
# File lib/unread/readable_scopes.rb, line 37 def with_read_marks_for(reader) postgresql_string_cast = using_postgresql? ? '::varchar' : '' join_read_marks(reader).select("#{quoted_table_name}.*, #{ReadMark.quoted_table_name}.id AS read_mark_id, #{quote_bound_value(reader.class.base_class.name)}#{postgresql_string_cast} AS read_mark_reader_type, #{quote_bound_value(reader.id)} AS read_mark_reader_id") end