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

Instance Method Details

#in_all_named_groups?(*args) ⇒ Boolean

Returns:

  • (Boolean)


48
49
50
51
52
# File 'lib/groupify/adapter/active_record/named_group_member.rb', line 48

def in_all_named_groups?(*args)
  opts = args.extract_options!
  named_groups = args.flatten.to_set
  named_groups.subset? self.named_groups.as(opts[:as]).to_set
end

#in_any_named_group?(*args) ⇒ Boolean

Returns:

  • (Boolean)


39
40
41
42
43
44
45
46
# File 'lib/groupify/adapter/active_record/named_group_member.rb', line 39

def in_any_named_group?(*args)
  opts = args.extract_options!
  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

Returns:

  • (Boolean)


35
36
37
# File 'lib/groupify/adapter/active_record/named_group_member.rb', line 35

def in_named_group?(named_group, opts={})
  named_groups.include?(named_group, opts)
end

#in_only_named_groups?(*args) ⇒ Boolean

Returns:

  • (Boolean)


54
55
56
57
58
# File 'lib/groupify/adapter/active_record/named_group_member.rb', line 54

def in_only_named_groups?(*args)
  opts = args.extract_options!
  named_groups = args.flatten.to_set
  named_groups == self.named_groups.as(opts[:as]).to_set
end

#named_groupsObject



25
26
27
# File 'lib/groupify/adapter/active_record/named_group_member.rb', line 25

def named_groups
  @named_groups ||= NamedGroupCollection.new(self)
end

#named_groups=(groups) ⇒ Object



29
30
31
32
33
# File 'lib/groupify/adapter/active_record/named_group_member.rb', line 29

def named_groups=(groups)
  groups.each do |group|
    self.named_groups << group
  end
end

#shares_any_named_group?(other, opts = {}) ⇒ Boolean

Returns:

  • (Boolean)


60
61
62
# File 'lib/groupify/adapter/active_record/named_group_member.rb', line 60

def shares_any_named_group?(other, opts={})
  in_any_named_group?(other.named_groups.to_a, opts)
end