Module: GroupMixins::Import

Extended by:
ActiveSupport::Concern
Included in:
Group
Defined in:
app/models/group_mixins/import.rb

Overview

This module extends the Group model by group import methods. This allows, for example, to import groups from a previous application or to auto-load a certain default group structure.

The module is included in the Group model by ‘include GroupMixins::Import`. The methods of the module can be accessed just like any other Group model methods:

Group.class_method()
g = Group.new()
g.instance_method()

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#import_default_group_structure(yaml_file_title = nil) ⇒ Object

Import the default group structure. This is called after creation of the group.

The structure is to be placed in a file at

#{Rails.root}/import/default_group_sub_structures/#{self.name}.yml

and is to be formatted in yaml, like this:

- Group 1
- Group 2:
    - Group 2.1:
        - Group 2.1.1
        - Group 2.1.2
    - Group 2.2
- Group 3:
    - Group 3.1


277
278
279
280
281
282
# File 'app/models/group_mixins/import.rb', line 277

def import_default_group_structure( yaml_file_title = nil )
  yaml_file_title ||= yaml_file_title = File.join( "default_group_sub_structures",
                                                   "#{self.name}.yml" )
  parent_group = self
  Group.yaml_import_groups_into_parent_group( yaml_file_title, parent_group )
end

#set_flag_based_on_name(name) ⇒ Object



309
310
311
312
313
314
315
316
317
318
319
# File 'app/models/group_mixins/import.rb', line 309

def set_flag_based_on_name( name )
  translations = []
  name = name.to_sym
  I18n.translate( name ) # required to initialize the I18n 
  I18n.backend.send( :translations ).each do |language, translations_hash|
    translations << translations_hash[ name ]
  end
  if self.name.in? translations
    self.add_flag( name )
  end
end

#set_flags_based_on_group_nameObject

When importing group structures, certain group names indicate special group attributes. This method sets these flags based on the group name.

This method is called by the ‘hash_array_import_groups_into_parent_group` method.



293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
# File 'app/models/group_mixins/import.rb', line 293

def set_flags_based_on_group_name 

  # Officers
  set_flag_based_on_name :officers_parent

  # Guests
  set_flag_based_on_name :guests_parent

  # Deceased
  set_flag_based_on_name :deceased_parent
  
  # Former Members
  set_flag_based_on_name :former_members_parent
  
end