Module: Mongoid::Followit::Queryable
- Defined in:
- lib/mongoid_followit/queryable.rb
Overview
Internal: Module that add query capabilities Follower/Followee model.
Examples
module Follower
def self.included(base)
base.class_eval do
include Mongoid::Followit::Queryable
end
end
end
module Followee
def self.included(base)
base.class_eval do
include Mongoid::Followit::Queryable
end
end
end
Constant Summary collapse
- FOLLOW_OPTIONS =
Internal: Hash of options to build a query for the Follow collection.
{ followee: { opposite_class: :follower_class, opposite_id: :follower_id, class: :followee_class, id: :followee_id, exception: 'HasTwoFolloweeTypesError' }, follower: { opposite_class: :followee_class, opposite_id: :followee_id, class: :follower_class, id: :follower_id, exception: 'HasTwoFollowerTypesError' } }.freeze
Instance Method Summary collapse
Instance Method Details
#follow_collection_for_a(behavior, criteria:) ⇒ Object
44 45 46 47 48 49 50 51 52 53 |
# File 'lib/mongoid_followit/queryable.rb', line 44 def follow_collection_for_a(behavior, criteria:) = (behavior) group_class = FOLLOW_OPTIONS[behavior][:class] grouped = Follow.where().group_by { |f| f.send(group_class) } if criteria collection_as_criteria(grouped, behavior) else collection_as_array(grouped, behavior) end end |