Class: TroleGroups::Config

Inherits:
Object show all
Defined in:
lib/trole_groups/config.rb,
lib/trole_groups/config/schema.rb,
lib/trole_groups/config/schema/helpers.rb,
lib/trole_groups/config/valid_role_groups.rb,
lib/trole_groups/config/schema/role_group_helpers.rb

Defined Under Namespace

Modules: Schema, ValidRoleGroups

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.



21
22
23
24
25
# File 'lib/trole_groups/config.rb', line 21

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.



39
40
41
# File 'lib/trole_groups/config.rb', line 39

def auto_load
  @auto_load
end

.default_ormObject

Returns the value of attribute default_orm.



39
40
41
# File 'lib/trole_groups/config.rb', line 39

def default_orm
  @default_orm
end

.log_onObject

Returns the value of attribute log_on.



40
41
42
# File 'lib/trole_groups/config.rb', line 40

def log_on
  @log_on
end

Instance Attribute Details

#auto_relationsObject

Returns the value of attribute auto_relations.



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

def auto_relations
  @auto_relations
end

#genericObject

Returns the value of attribute generic.



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

def generic
  @generic
end

#log_onObject

Returns the value of attribute log_on.



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

def log_on
  @log_on
end

#ormObject



116
117
118
# File 'lib/trole_groups/config.rb', line 116

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

#strategyObject

Returns the value of attribute strategy.



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

def strategy
  @strategy
end

#subject_classObject

Returns the value of attribute subject_class.



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

def subject_class
  @subject_class
end

Class Method Details

.auto_configObject



59
60
61
# File 'lib/trole_groups/config.rb', line 59

def auto_config
  auto_config_setings
end

.auto_config?(name) ⇒ Boolean

Returns:

  • (Boolean)


63
64
65
# File 'lib/trole_groups/config.rb', line 63

def auto_config? name
  auto_config_setings[name]
end

.auto_load?Boolean

Returns:

  • (Boolean)


55
56
57
# File 'lib/trole_groups/config.rb', line 55

def auto_load?
  @auto_load
end

.log_on?Boolean

Returns:

  • (Boolean)


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

def log_on?
  log_on || false
end

.sub_modulesObject



6
7
8
# File 'lib/trole_groups/config.rb', line 6

def self.sub_modules
  [:valid_role_groups, :schema] # , :static_roles, , 
end

Instance Method Details

#apply_options!(options = {}) ⇒ Object



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

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

#auto_configObject



84
85
86
# File 'lib/trole_groups/config.rb', line 84

def auto_config
  auto_config_setings 
end

#auto_config?(name) ⇒ Boolean

Returns:

  • (Boolean)


88
89
90
91
# File 'lib/trole_groups/config.rb', line 88

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

#auto_config_setingsObject



94
95
96
# File 'lib/trole_groups/config.rb', line 94

def auto_config_setings
  @auto_config_setings ||= {}
end

#configure!(options = {}) ⇒ Object



33
34
35
36
# File 'lib/trole_groups/config.rb', line 33

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

#default_role_fieldObject



112
113
114
# File 'lib/trole_groups/config.rb', line 112

def default_role_field
  :trole_groups
end

#generic?Boolean

def singularity= value

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

end

Returns:

  • (Boolean)


129
130
131
132
# File 'lib/trole_groups/config.rb', line 129

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

#log_on?Boolean

Returns:

  • (Boolean)


80
81
82
# File 'lib/trole_groups/config.rb', line 80

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

#role_fieldObject Also known as: rolegroup_field



98
99
100
101
102
# File 'lib/trole_groups/config.rb', line 98

def role_field
  @role_field ||= begin
    default_role_field
  end
end

#role_field=(field_name) ⇒ Object Also known as: rolegroup_field=

Raises:

  • (ArgumentException)


105
106
107
108
109
# File 'lib/trole_groups/config.rb', line 105

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



120
121
122
# File 'lib/trole_groups/config.rb', line 120

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