Class: Incline::AccessGroup
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Incline::AccessGroup
- Defined in:
- app/models/incline/access_group.rb
Instance Method Summary collapse
-
#belongs_to?(group) ⇒ Boolean
Determines if this group belongs to the specified group.
-
#effective_groups ⇒ Object
Gets a list of all the groups this group provides effective membership to.
-
#group_ids ⇒ Object
Gets the group IDs for the members of this group.
-
#group_ids=(values) ⇒ Object
Sets the group IDs for the members of this group.
-
#members(refresh = false) ⇒ Object
Gets a list of all of the member users for this group.
-
#memberships(refresh = false) ⇒ Object
Gets a list of memberships for this group.
-
#user_ids ⇒ Object
Gets the user IDs for the members of this group.
-
#user_ids=(values) ⇒ Object
Sets the user IDs for the members of this group.
Instance Method Details
#belongs_to?(group) ⇒ Boolean
Determines if this group belongs to the specified group.
44 45 46 47 48 |
# File 'app/models/incline/access_group.rb', line 44 def belongs_to?(group) group = AccessGroup.get(group) unless group.is_a?(::Incline::AccessGroup) return false unless group safe_belongs_to?(group) end |
#effective_groups ⇒ Object
Gets a list of all the groups this group provides effective membership to.
52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'app/models/incline/access_group.rb', line 52 def effective_groups ret = [ self ] memberships.each do |m| unless ret.include?(m) # prevent infinite recursion tmp = m.effective_groups tmp.each do |g| ret << g unless ret.include?(g) end end end ret.sort{|a,b| a.name <=> b.name} end |
#group_ids ⇒ Object
Gets the group IDs for the members of this group.
73 74 75 |
# File 'app/models/incline/access_group.rb', line 73 def group_ids groups.pluck(:id) end |
#group_ids=(values) ⇒ Object
Sets the group IDs for the members of this group.
88 89 90 91 92 93 |
# File 'app/models/incline/access_group.rb', line 88 def group_ids=(values) values ||= [] values = [ values ] unless values.is_a?(::Array) values = values.reject{|v| v.blank?}.map{|v| v.to_i} self.groups = Incline::AccessGroup.where(id: values).to_a end |
#members(refresh = false) ⇒ Object
Gets a list of all of the member users for this group. (Read-only)
30 31 32 33 |
# File 'app/models/incline/access_group.rb', line 30 def members(refresh = false) @members = nil if refresh @members ||= safe_members.sort{|a,b| a.to_s <=> b.to_s} end |
#memberships(refresh = false) ⇒ Object
Gets a list of memberships for this group. (Read-only)
23 24 25 26 |
# File 'app/models/incline/access_group.rb', line 23 def memberships(refresh = false) @memberships = nil if refresh @memberships ||= AccessGroupGroupMember.where(member_id: id).includes(:group).map{|v| v.group}.to_a.freeze end |
#user_ids ⇒ Object
Gets the user IDs for the members of this group.
67 68 69 |
# File 'app/models/incline/access_group.rb', line 67 def user_ids users.pluck(:id) end |
#user_ids=(values) ⇒ Object
Sets the user IDs for the members of this group.
79 80 81 82 83 84 |
# File 'app/models/incline/access_group.rb', line 79 def user_ids=(values) values ||= [] values = [ values ] unless values.is_a?(::Array) values = values.reject{|v| v.blank?}.map{|v| v.to_i} self.users = Incline::User.where(id: values).to_a end |