Class: Troles::Common::Config
- Extended by:
- ClassMethods
- Defined in:
- lib/troles/common/config.rb,
lib/troles/common/config/schema.rb,
lib/troles/common/config/valid_roles.rb,
lib/troles/common/config/static_roles.rb,
lib/troles/common/config/class_methods.rb,
lib/troles/common/config/schema/helpers.rb
Direct Known Subclasses
Trole::Adapters::ActiveRecord::Config, Trole::Config, Trole::Mongoid::Config, Adapters::ActiveRecord::Config, Troles::Config, Mongoid::Config
Defined Under Namespace
Modules: ClassMethods, Schema, StaticRoles, ValidRoles
Instance Attribute Summary collapse
-
#generic ⇒ Object
Returns the value of attribute generic.
-
#log_on ⇒ Object
Returns the value of attribute log_on.
-
#orm ⇒ Object
get the orm name.
-
#strategy ⇒ Object
Returns the value of attribute strategy.
-
#subject_class ⇒ Object
Returns the value of attribute subject_class.
Attributes included from ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
-
#apply_options!(options = {}) ⇒ Object
Call setter for each key/value pair.
-
#auto_config ⇒ Object
get the auto configuration settings hash.
-
#auto_config?(name) ⇒ Boolean
is a certain type of auto configuration enabled?.
-
#configure!(options = {}) ⇒ Object
Configure subject with behavior First apply any remaining options needed Then configure models if configured to do do.
-
#default_main_field ⇒ Object
(also: #default_role_field)
get the default name of the main field for roles, it depends on the singularity (one or many) of the strategy see (#singularity).
-
#generic? ⇒ Boolean
is it a generic strategy/orm ?.
-
#initialize(subject_class, options = {}) ⇒ Config
constructor
configure Config object with subject class and various options.
-
#log_on? ⇒ Boolean
is logging on?.
-
#main_field ⇒ Object
(also: #role_field)
Get the main field name that is used for the behavior added, fx :troles for roles behavior.
-
#main_field=(field_name) ⇒ Object
(also: #role_field=)
Set the main field of the behavior.
-
#singularity ⇒ Object
get the singularity (one or many) of the strategy.
Methods included from ClassMethods
Constructor Details
#initialize(subject_class, options = {}) ⇒ Config
configure Config object with subject class and various options
18 19 20 21 22 23 |
# File 'lib/troles/common/config.rb', line 18 def initialize subject_class, = {} raise ArgumentError, "The first argument must be the Class which is the subject of the behavior" unless subject_class.is_a?(Class) @subject_class = subject_class end |
Instance Attribute Details
#generic ⇒ Object
Returns the value of attribute generic.
14 15 16 |
# File 'lib/troles/common/config.rb', line 14 def generic @generic end |
#log_on ⇒ Object
Returns the value of attribute log_on.
14 15 16 |
# File 'lib/troles/common/config.rb', line 14 def log_on @log_on end |
#orm ⇒ Object
get the orm name
83 84 85 |
# File 'lib/troles/common/config.rb', line 83 def orm @orm || self.class.default_orm end |
#strategy ⇒ Object
Returns the value of attribute strategy.
14 15 16 |
# File 'lib/troles/common/config.rb', line 14 def strategy @strategy end |
#subject_class ⇒ Object
Returns the value of attribute subject_class.
14 15 16 |
# File 'lib/troles/common/config.rb', line 14 def subject_class @subject_class end |
Class Method Details
.sub_modules ⇒ Object
5 6 7 |
# File 'lib/troles/common/config.rb', line 5 def self.sub_modules [:valid_roles, :static_roles, :schema] end |
Instance Method Details
#apply_options!(options = {}) ⇒ Object
Call setter for each key/value pair
28 29 30 31 32 |
# File 'lib/troles/common/config.rb', line 28 def = {} .each_pair do |key, value| send("#{key}=", value) if self.respond_to?(:"#{key}=") end end |
#auto_config ⇒ Object
get the auto configuration settings hash
48 49 50 |
# File 'lib/troles/common/config.rb', line 48 def auto_config @auto_config ||= {} end |
#auto_config?(name) ⇒ Boolean
is a certain type of auto configuration enabled?
53 54 55 56 |
# File 'lib/troles/common/config.rb', line 53 def auto_config? name return auto_config[name] if !auto_config[name].nil? Troles::Config.auto_config?(name) end |
#configure!(options = {}) ⇒ Object
Configure subject with behavior First apply any remaining options needed Then configure models if configured to do do
37 38 39 40 |
# File 'lib/troles/common/config.rb', line 37 def configure! = {} configure_models if auto_config?(:models) end |
#default_main_field ⇒ Object Also known as: default_role_field
get the default name of the main field for roles, it depends on the singularity (one or many) of the strategy see (#singularity)
77 78 79 |
# File 'lib/troles/common/config.rb', line 77 def default_main_field @default_main_field ||= (singularity == :many) ? :troles : :trole end |
#generic? ⇒ Boolean
is it a generic strategy/orm ?
93 94 95 96 |
# File 'lib/troles/common/config.rb', line 93 def generic? return true if orm.nil? || orm == :generic @generic.nil? ? false : @generic end |
#log_on? ⇒ Boolean
is logging on?
43 44 45 |
# File 'lib/troles/common/config.rb', line 43 def log_on? log_on || Troles::Config.log_on end |
#main_field ⇒ Object Also known as: role_field
Get the main field name that is used for the behavior added, fx :troles for roles behavior
59 60 61 62 63 |
# File 'lib/troles/common/config.rb', line 59 def main_field @main_field ||= begin default_main_field end end |
#main_field=(field_name) ⇒ Object Also known as: role_field=
Set the main field of the behavior
67 68 69 70 71 |
# File 'lib/troles/common/config.rb', line 67 def main_field= field_name name = field_name.to_s.alpha_numeric.to_sym raise ArgumentException, "Not a valid field name: #{field_name}" if !valid_field_name?(name) @main_field ||= name end |
#singularity ⇒ Object
get the singularity (one or many) of the strategy
88 89 90 |
# File 'lib/troles/common/config.rb', line 88 def singularity @singularity ||= (strategy =~ /_many$/) ? :many : :one end |