Module: Groupify::ActiveRecord::GroupMember
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/groupify/adapter/active_record/group_member.rb
Overview
Usage:
class User < ActiveRecord::Base
acts_as_group_member
...
end
user.groups << group
Defined Under Namespace
Modules: ClassMethods, GroupAssociationExtensions
Instance Method Summary
collapse
Instance Method Details
#in_all_groups?(*args) ⇒ Boolean
76
77
78
79
80
81
|
# File 'lib/groupify/adapter/active_record/group_member.rb', line 76
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
66
67
68
69
70
71
72
73
74
|
# File 'lib/groupify/adapter/active_record/group_member.rb', line 66
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
56
57
58
59
60
61
62
63
64
|
# File 'lib/groupify/adapter/active_record/group_member.rb', line 56
def in_group?(group, opts={})
criteria = {group_id: group.id}
if opts[:as]
criteria.merge!(membership_type: opts[:as])
end
group_memberships.exists?(criteria)
end
|
#in_only_groups?(*args) ⇒ Boolean
83
84
85
86
87
88
|
# File 'lib/groupify/adapter/active_record/group_member.rb', line 83
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
90
91
92
|
# File 'lib/groupify/adapter/active_record/group_member.rb', line 90
def shares_any_group?(other, opts={})
in_any_group?(other.groups, opts)
end
|