Module: StructureableMixins::HasSpecialGroups

Extended by:
ActiveSupport::Concern
Defined in:
app/models/structureable_mixins/has_special_groups.rb

Overview

This module extends the Structureable models by methods for the interaction with special_groups that are descendants of the structureable object.

For example,

class Page
  is_structureable ...
  ...
end

one would want to access the ‘officers_parent` group, which contains all officers of the structureable object.

some_page.find_officers_parent_group
some_page.create_officers_parent_group
some_page.find_or_create_officers_parent_group
some_page.officers_parent
some_page.officers_parent!
some_page.officers
some_page.officers << some_users

Or, globally, one would use this mechanism to define, let’s say, global special groups like the group ‘everyone’, which contains each and every user.

class Group
  is_structureable ...
  ...
end

Group.find_everyone_group
Group.create_everyone_group
Group.find_or_create_everyone_group
Group.everyone
Group.everyone!

The ‘officers_parent` special group is actually defined in `StructureableMixins::Roles`, the `everyone` group in `GroupMixins::GlobalSpecialGroups`, whereas the helper methods that are used by those definitions are defined here in this mixin below.

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#create_special_group(group_flag, options = {}) ⇒ Object



118
119
120
# File 'app/models/structureable_mixins/has_special_groups.rb', line 118

def create_special_group( group_flag, options = {} )
  self.class.create_special_group( group_flag, { parent_element: self, local: true }.merge(options) )
end

#find_or_create_special_group(group_flag, options = {}) ⇒ Object



122
123
124
# File 'app/models/structureable_mixins/has_special_groups.rb', line 122

def find_or_create_special_group( group_flag, options = {} )
  self.class.find_or_create_special_group( group_flag, { parent_element: self, local: true }.merge(options) ) 
end

#find_special_group(group_flag, options = {}) ⇒ Object

Local Special Groups i.e. descendants of structureables, e.g. officers groups: ‘group_xy.officers_parent`

These instance methods may be called on each structureable model instance. For example, one may call ‘my_group.find_or_create_special_group(:officers_parent)`.

These methods use the same mechanism as for the global special groups above by specifying ‘self` (i.e. the structureable instance) as the `parent_element`.



114
115
116
# File 'app/models/structureable_mixins/has_special_groups.rb', line 114

def find_special_group( group_flag, options = {} )
  self.class.find_special_group( group_flag, { parent_element: self, local: true }.merge(options) )
end