Module: Groupify::ActiveRecord::NamedGroupMember
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/groupify/adapter/active_record/named_group_member.rb
Overview
Usage:
class User < ActiveRecord::Base
acts_as_named_group_member
...
end
user.named_groups << :admin
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
- #in_all_named_groups?(*args) ⇒ Boolean
- #in_any_named_group?(*args) ⇒ Boolean
- #in_named_group?(named_group, opts = {}) ⇒ Boolean
- #in_only_named_groups?(*args) ⇒ Boolean
- #named_groups ⇒ Object
- #named_groups=(groups) ⇒ Object
- #shares_any_named_group?(other, opts = {}) ⇒ Boolean
Instance Method Details
#in_all_named_groups?(*args) ⇒ Boolean
44 45 46 47 48 |
# File 'lib/groupify/adapter/active_record/named_group_member.rb', line 44 def in_all_named_groups?(*args) opts = args. named_groups = args.flatten.to_set named_groups.subset? self.named_groups.as(opts[:as]).to_set end |
#in_any_named_group?(*args) ⇒ Boolean
35 36 37 38 39 40 41 42 |
# File 'lib/groupify/adapter/active_record/named_group_member.rb', line 35 def in_any_named_group?(*args) opts = args. named_groups = args.flatten named_groups.each do |named_group| return true if in_named_group?(named_group, opts) end return false end |
#in_named_group?(named_group, opts = {}) ⇒ Boolean
31 32 33 |
# File 'lib/groupify/adapter/active_record/named_group_member.rb', line 31 def in_named_group?(named_group, opts={}) named_groups.include?(named_group, opts) end |
#in_only_named_groups?(*args) ⇒ Boolean
50 51 52 53 54 |
# File 'lib/groupify/adapter/active_record/named_group_member.rb', line 50 def in_only_named_groups?(*args) opts = args. named_groups = args.flatten.to_set named_groups == self.named_groups.as(opts[:as]).to_set end |
#named_groups ⇒ Object
21 22 23 |
# File 'lib/groupify/adapter/active_record/named_group_member.rb', line 21 def named_groups @named_groups ||= NamedGroupCollection.new(self) end |
#named_groups=(groups) ⇒ Object
25 26 27 28 29 |
# File 'lib/groupify/adapter/active_record/named_group_member.rb', line 25 def named_groups=(groups) groups.each do |group| self.named_groups << group end end |
#shares_any_named_group?(other, opts = {}) ⇒ Boolean
56 57 58 |
# File 'lib/groupify/adapter/active_record/named_group_member.rb', line 56 def shares_any_named_group?(other, opts={}) in_any_named_group?(other.named_groups.to_a, opts) end |