Sha256: 5b91a92cf9752ab3a04ba34c01bef5254e9b3034095b4b19c293bc4a49af1368

Contents?: true

Size: 569 Bytes

Versions: 1

Compression:

Stored size: 569 Bytes

Contents

module UnreadMongoid
  module Readable
    module Scopes
      def unread_by(reader)
        UnreadMongoid::Reader.assert_reader(reader)

        self.not_in(id: read_ids(reader))
      end

      def read_by(reader)
        UnreadMongoid::Reader.assert_reader(reader)

        self.in(id: read_ids(reader))
      end

      private
      def read_ids(reader)
        ReadMark.where(
          reader_id: reader.id,
          reader_type: reader.class.name,
          readable_type: self.name
        ).only(:readable_id).map(&:readable_id)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
unread-mongoid-0.1.0 lib/unread_mongoid/scopes.rb