Module: Groupify::ActiveRecord::GroupMember
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/groupify/adapter/active_record/group_member.rb
Overview
Usage:
class User < ActiveRecord::Base
groupify :group_member
...
end
user.groups << group
Defined Under Namespace
Modules: ClassMethods, GroupAssociationExtensions
Instance Method Summary
collapse
Instance Method Details
#in_all_groups?(*args) ⇒ Boolean
80
81
82
83
84
85
|
# File 'lib/groupify/adapter/active_record/group_member.rb', line 80
def in_all_groups?(*args)
opts = args.
groups = args.flatten
groups.to_set.subset? self.groups.as(opts[:as]).to_set
end
|
#in_any_group?(*args) ⇒ Boolean
70
71
72
73
74
75
76
77
78
|
# File 'lib/groupify/adapter/active_record/group_member.rb', line 70
def in_any_group?(*args)
opts = args.
groups = args
groups.flatten.each do |group|
return true if in_group?(group, opts)
end
return false
end
|
#in_group?(group, opts = {}) ⇒ Boolean
60
61
62
63
64
65
66
67
68
|
# File 'lib/groupify/adapter/active_record/group_member.rb', line 60
def in_group?(group, opts={})
criteria = {group_id: group.id}
if opts[:as]
criteria.merge!(membership_type: opts[:as])
end
group_memberships_as_member.exists?(criteria)
end
|
#in_only_groups?(*args) ⇒ Boolean
87
88
89
90
91
92
|
# File 'lib/groupify/adapter/active_record/group_member.rb', line 87
def in_only_groups?(*args)
opts = args.
groups = args.flatten
groups.to_set == self.groups.as(opts[:as]).to_set
end
|
#shares_any_group?(other, opts = {}) ⇒ Boolean
94
95
96
|
# File 'lib/groupify/adapter/active_record/group_member.rb', line 94
def shares_any_group?(other, opts={})
in_any_group?(other.groups, opts)
end
|