class Troles::Common::Config

Attributes

generic[RW]
log_on[RW]
orm[W]
strategy[RW]
subject_class[RW]

Public Class Methods

new(subject_class, options = {}) click to toggle source

configure Config object with subject class and various options

# File lib/troles/common/config.rb, line 18
def initialize subject_class, options = {}
  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

  apply_options! options
end
sub_modules() click to toggle source
# File lib/troles/common/config.rb, line 5
def self.sub_modules
  [:valid_roles, :static_roles, :schema]
end

Public Instance Methods

apply_options!(options = {}) click to toggle source

Call setter for each key/value pair

# File lib/troles/common/config.rb, line 28
def apply_options! options = {}
  options.each_pair do |key, value| 
    send("#{key}=", value) if self.respond_to?(:"#{key}=")
  end      
end
auto_config() click to toggle source

get the auto configuration settings hash

# File lib/troles/common/config.rb, line 48
def auto_config
  @auto_config ||= {}
end
auto_config?(name) click to toggle source

is a certain type of auto configuration enabled?

# 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 = {}) click to toggle source

Configure subject with behavior First apply any remaining options needed Then configure models if configured to do do

# File lib/troles/common/config.rb, line 37
def configure! options = {}
  apply_options! options
  configure_models if auto_config?(:models)
end
default_main_field() click to toggle source

get the default name of the main field for roles, it depends on the singularity (one or many) of the strategy see (singularity)

# File lib/troles/common/config.rb, line 77
def default_main_field
  @default_main_field ||= (singularity == :many) ? :troles : :trole
end
Also aliased as: default_role_field
default_role_field()
Alias for: default_main_field
generic?() click to toggle source

is it a generic strategy/orm ?

# File lib/troles/common/config.rb, line 93
def generic?
  return true if orm.nil? || orm == :generic
  @generic.nil? ? false : @generic
end
log_on?() click to toggle source

is logging on?

# File lib/troles/common/config.rb, line 43
def log_on?
  log_on || Troles::Config.log_on
end
main_field() click to toggle source

Get the main field name that is used for the behavior added, fx :troles for roles behavior

# File lib/troles/common/config.rb, line 59
def main_field
  @main_field ||= begin
    default_main_field
  end
end
Also aliased as: role_field
main_field=(field_name) click to toggle source

Set the main field of the behavior

# 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
Also aliased as: role_field=
orm() click to toggle source

get the orm name

# File lib/troles/common/config.rb, line 83
def orm
  @orm || self.class.default_orm
end
role_field()
Alias for: main_field
role_field=(field_name)
Alias for: main_field=
singularity() click to toggle source

get the singularity (one or many) of the strategy

# File lib/troles/common/config.rb, line 88
def singularity
  @singularity ||= (strategy =~ /_many$/) ? :many : :one
end