Class: SchemaAssociations::Config

Inherits:
Valuable
  • Object
show all
Defined in:
lib/schema_associations.rb

Overview

The configuation options for SchemaAssociations. Set them globally in config/initializers/schema_associations.rb, e.g.:

SchemaAssociations.setup do |config|
   config.concise_names = false
end

or override them per-model, e.g.:

class MyModel < ActiveRecord::Base
   schema_associations :concise_names => false
end

Instance Method Summary collapse

Instance Method Details

#auto_createObject

:attr_accessor: auto_create

Whether to automatically create associations based on foreign keys. Boolean, default is true.



29
# File 'lib/schema_associations.rb', line 29

has_value :auto_create, :klass => :boolean, :default => true

#concise_namesObject

:attr_accessor: concise_names

Whether to use concise naming (strip out common prefixes from class names). Boolean, default is true.



36
# File 'lib/schema_associations.rb', line 36

has_value :concise_names, :klass => :boolean, :default => true

#dupObject

:nodoc:



76
77
78
# File 'lib/schema_associations.rb', line 76

def dup # :nodoc:
  self.class.new(Hash[attributes.collect{ |key, val| [key, Valuable === val ?  val.class.new(val.attributes) : val] }])
end

#exceptObject

:attr_accessor: except

List of association names to exclude from automatic creation. Value is a single name, an array of names, or nil. Default is nil.



43
# File 'lib/schema_associations.rb', line 43

has_value :except, :default => nil

#except_typeObject

:attr_accessor: except_type

List of association types to exclude from automatic creation. Value is one or an array of :belongs_to, :has_many, :has_one, and/or :has_and_belongs_to_many, or nil. Default is nil.



58
# File 'lib/schema_associations.rb', line 58

has_value :except_type, :default => nil

#merge(opts) ⇒ Object

:nodoc:



86
87
88
# File 'lib/schema_associations.rb', line 86

def merge(opts)#:nodoc:
  dup.update_attributes(opts)
end

#onlyObject

:attr_accessor: only

List of association names to include in automatic creation. Value is a single name, and array of names, or nil. Default is nil.



50
# File 'lib/schema_associations.rb', line 50

has_value :only, :default => nil

#only_typeObject

:attr_accessor: only_type

List of association types to include from automatic creation. Value is one or an array of :belongs_to, :has_many, :has_one, and/or :has_and_belongs_to_many, or nil. Default is nil.



66
# File 'lib/schema_associations.rb', line 66

has_value :only_type, :default => nil

#table_prefix_mapObject

:attr_accessor: table_prefix_map

Hash whose keys are possible matches at the start of table names, and whose corresponding values are the prefix to use in front of class names.



74
# File 'lib/schema_associations.rb', line 74

has_value :table_prefix_map, :default => {}

#update_attributes(opts) ⇒ Object

:nodoc:



80
81
82
83
84
# File 'lib/schema_associations.rb', line 80

def update_attributes(opts)#:nodoc:
  opts = opts.dup
  super(opts)
  self
end