Sha256: c0a91161ff673835d74342d419f9882d2bfa606b60f99512a26fdd79c9dd3ee7
Contents?: true
Size: 1.74 KB
Versions: 1
Compression:
Stored size: 1.74 KB
Contents
require 'active_support/concern' module ActsAsMessageable module Scopes extend ActiveSupport::Concern included do initialize_scopes end module ClassMethods def initialize_scopes scope :are_from, ->(*args) { where(sent_messageable_id: args.first, sent_messageable_type: args.first.class.name) } scope :are_to, ->(*args) { where(received_messageable_id: args.first, received_messageable_type: args.first.class.name) } scope :search, ->(*args) { where('body like :search_txt or topic like :search_txt', search_txt: "%#{args.first}%") } scope :connected_with, lambda { |*args| where("(sent_messageable_type = :sent_type and sent_messageable_id = :sent_id and sender_delete = :s_delete and sender_permanent_delete = :s_perm_delete) or (received_messageable_type = :received_type and received_messageable_id = :received_id and recipient_delete = :r_delete and recipient_permanent_delete = :r_perm_delete)", sent_type: args.first.class.resolve_active_record_ancestor.to_s, sent_id: args.first.id, received_type: args.first.class.resolve_active_record_ancestor.to_s, received_id: args.first.id, r_delete: args.last, s_delete: args.last, r_perm_delete: false, s_perm_delete: false) } scope :readed, -> { where(opened: true) } scope :unreaded, -> { where(opened: false) } scope :deleted, -> { where(recipient_delete: true, sender_delete: true) } end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
acts-as-messageable-0.4.11 | lib/acts-as-messageable/scopes.rb |