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
-
#configure_field ⇒ Object
configures a single main field on the subject fx if the roles are stored as a Boolean, Integer or String.
-
#configure_generic ⇒ Object
configures main field (fx role field) as a generic accessor.
-
#configure_models ⇒ Object
configures the models if set to do so first configures.
-
#configure_relation ⇒ Object
configures model relationships for roles fx if the roles are stored in an model, either embedded or referenced.
-
#object_model ⇒ Class
(also: #role_model)
Gets the object model to be used see (#object_model=) see(#default_object_model_class_name).
-
#object_model=(model_class) ⇒ Object
(also: #role_mode=)
Sets the object model to use allows different subject classes (fx User Accounts) to have different schemas.
Methods included from Helpers
Instance Method Details
#configure_field ⇒ Object
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_generic ⇒ Object
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_models ⇒ Object
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_relation ⇒ Object
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_model ⇒ Class Also known as: role_model
Gets the object model to be used see (#object_model=) see(#default_object_model_class_name)
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
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 |