Module: Troles::Common::Config::Schema

Includes:
ClassExt, Helpers
Defined in:
lib/troles/common/config/schema.rb,
lib/troles/common/config/schema/helpers.rb

Defined Under Namespace

Modules: Helpers

Instance Method Summary collapse

Methods included from Helpers

#boolean?, #valid_field_name?

Instance Method Details

#configure_fieldObject

Note:

adapter should customize this as needed

configures a single main field on the subject fx if the roles are stored as a Boolean, Integer or String



29
30
# File 'lib/troles/common/config/schema.rb', line 29

def configure_field
end

#configure_genericObject

configures main field (fx role field) as a generic accessor



21
22
23
24
# File 'lib/troles/common/config/schema.rb', line 21

def configure_generic
  raise "Subject class must be a Class" unless subject_class.is_a?(Class)
  subject_class.send(:attr_accessor, main_field) # create troles accessor      
end

#configure_modelsObject

configures the models if set to do so first configures



14
15
16
17
18
# File 'lib/troles/common/config/schema.rb', line 14

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

#configure_relationObject

Note:

adapter should customize this as needed

configures model relationships for roles fx if the roles are stored in an model, either embedded or referenced



35
36
# File 'lib/troles/common/config/schema.rb', line 35

def configure_relation
end

#object_modelClass Also known as: role_model

Gets the object model to be used see (#object_model=) see(#default_object_model_class_name)

Returns:

  • (Class)

    the model class



52
53
54
# File 'lib/troles/common/config/schema.rb', line 52

def object_model
  @object_model_found ||= find_first_class(@object_model, default_object_model_class_name)
end

#object_model=(model_class) ⇒ Object Also known as: role_mode=

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

Parameters:

  • the (Class, String, Symbol)

    model class



41
42
43
44
# File 'lib/troles/common/config/schema.rb', line 41

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