Class: Troles::Common::Config

Inherits:
Object
  • Object
show all
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/schema/helpers.rb,
lib/troles/common/config/schema/role_helpers.rb

Defined Under Namespace

Modules: Schema, StaticRoles, ValidRoles

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(subject_class, options = {}) ⇒ Config

Returns a new instance of Config.



19
20
21
22
23
# File 'lib/troles/common/config.rb', line 19

def initialize subject_class, options = {}
  @subject_class = subject_class
  # set instance var for each pair in options
  apply_options! options
end

Class Attribute Details

.auto_loadObject

Returns the value of attribute auto_load.



26
27
28
# File 'lib/troles/common/config.rb', line 26

def auto_load
  @auto_load
end

.default_ormObject

Returns the value of attribute default_orm.



26
27
28
# File 'lib/troles/common/config.rb', line 26

def default_orm
  @default_orm
end

.log_onObject

Returns the value of attribute log_on.



27
28
29
# File 'lib/troles/common/config.rb', line 27

def log_on
  @log_on
end

Instance Attribute Details

#auto_relationsObject

Returns the value of attribute auto_relations.



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

def auto_relations
  @auto_relations
end

#genericObject

Returns the value of attribute generic.



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

def generic
  @generic
end

#log_onObject

Returns the value of attribute log_on.



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

def log_on
  @log_on
end

#ormObject



113
114
115
# File 'lib/troles/common/config.rb', line 113

def orm
  @orm || self.class.default_orm
end

#strategyObject

Returns the value of attribute strategy.



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

def strategy
  @strategy
end

#subject_classObject

Returns the value of attribute subject_class.



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

def subject_class
  @subject_class
end

Class Method Details

.auto_configObject



46
47
48
# File 'lib/troles/common/config.rb', line 46

def auto_config
  auto_config_setings
end

.auto_config?(name) ⇒ Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/troles/common/config.rb', line 50

def auto_config? name
  auto_config_setings[name]
end

.auto_load?Boolean

Returns:

  • (Boolean)


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

def auto_load?
  @auto_load
end

.log_on?Boolean

Returns:

  • (Boolean)


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

def log_on?
  log_on || false
end

.sub_modulesObject



8
9
10
# File 'lib/troles/common/config.rb', line 8

def self.sub_modules
  [:valid_roles, :static_roles, :schema]
end

Instance Method Details

#apply_options!(options = {}) ⇒ Object



80
81
82
83
84
# File 'lib/troles/common/config.rb', line 80

def apply_options! options = {}
  options.each_pair do |key, value| 
    send("#{key}=", value) if self.respond_to?(:"#{key}")
  end      
end

#auto_configObject



71
72
73
# File 'lib/troles/common/config.rb', line 71

def auto_config
  auto_config_setings 
end

#auto_config?(name) ⇒ Boolean

Returns:

  • (Boolean)


75
76
77
78
# File 'lib/troles/common/config.rb', line 75

def auto_config? name
  return auto_config_setings[name] if !auto_config_setings[name].nil?
  Troles::Config.auto_config?(name)
end

#auto_config_setingsObject

protected



93
94
95
# File 'lib/troles/common/config.rb', line 93

def auto_config_setings
  @auto_config_setings ||= {}
end

#configure!(options = {}) ⇒ Object



86
87
88
89
# File 'lib/troles/common/config.rb', line 86

def configure! options = {}
  apply_options! options
  configure_models if auto_config?(:models)
end

#default_role_fieldObject



109
110
111
# File 'lib/troles/common/config.rb', line 109

def default_role_field
  singularity == :many ? :troles : :trole
end

#generic?Boolean

def singularity= value

raise ArgumentError, "Must be :many or :one" if ![:one, :many].include?(value)      
@singularity ||= value

end

Returns:

  • (Boolean)


126
127
128
129
# File 'lib/troles/common/config.rb', line 126

def generic?
  return true if orm.nil?
  @generic.nil? ? false : @generic
end

#log_on?Boolean

Returns:

  • (Boolean)


67
68
69
# File 'lib/troles/common/config.rb', line 67

def log_on?
  log_on || Troles::Config.log_on
end

#role_fieldObject



97
98
99
100
101
# File 'lib/troles/common/config.rb', line 97

def role_field
  @role_field ||= begin
    default_role_field
  end
end

#role_field=(field_name) ⇒ Object

Raises:

  • (ArgumentException)


103
104
105
106
107
# File 'lib/troles/common/config.rb', line 103

def role_field= field_name
  name = field_name.to_s.alpha_numeric.to_sym
  raise ArgumentException, "Not a valid role field name: #{field_name}"  if !valid_field_name?(name)
  @role_field ||= name
end

#singularityObject



117
118
119
# File 'lib/troles/common/config.rb', line 117

def singularity
  @singularity ||= (strategy =~ /_many$/) ? :many : :one
end