Module: TroleGroups::Config::Schema

Includes:
Helpers, RoleGroupHelpers
Defined in:
lib/trole_groups/config/schema.rb,
lib/trole_groups/config/schema/helpers.rb,
lib/trole_groups/config/schema/role_group_helpers.rb

Defined Under Namespace

Modules: Helpers, RoleGroupHelpers

Instance Method Summary collapse

Methods included from RoleGroupHelpers

#rolegroup_class_name

Methods included from Helpers

included

Instance Method Details

#configure_fieldObject

Adapter should customize this as needed



18
19
# File 'lib/trole_groups/config/schema.rb', line 18

def configure_field
end

#configure_genericObject



13
14
15
# File 'lib/trole_groups/config/schema.rb', line 13

def configure_generic                    
  subject_class.send(:attr_accessor, role_field)  if generic? || orm == :generic # create troles accessor      
end

#configure_modelsObject



7
8
9
10
11
# File 'lib/trole_groups/config/schema.rb', line 7

def configure_models
  configure_generic
  configure_field if auto_config?(:fields)
  configure_relation if auto_config?(:relations)
end

#configure_relationObject

Adapter should customize this as needed



22
23
# File 'lib/trole_groups/config/schema.rb', line 22

def configure_relation
end

#rolegroup_modelClass

Gets the role model to be used see (#role_model=)

Returns:

  • (Class)

    the model class (defaults to Role)



36
37
38
39
40
41
42
43
44
# File 'lib/trole_groups/config/schema.rb', line 36

def rolegroup_model
  @rolegroup_model_found ||= begin
    models = [@rolegroup_model, role_group_class_name].select do |class_name|
      try_class(class_name.to_s.camelize)
    end.compact
    raise "No #{role_group_class_name} class defined, define a #{role_group_class_name} class or set which class to use, using the :rolegroup_model option on configuration" if models.empty?
    models.first.to_s.constantize
  end
end

#rolegroup_model=(model_class) ⇒ Object

Sets the role model to use allows different role subject classes (fx User Accounts) to have different role schemas

Parameters:

  • the (Class)

    model class



28
29
30
31
# File 'lib/trole_groups/config/schema.rb', line 28

def rolegroup_model= model_class
  @rolegroup_model = model_class.to_s and return if model_class.any_kind_of?(Class, String, Symbol)
  raise "The rolegroup model must be a Class, was: #{model_class}"
end