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.



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

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.



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

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

#dupObject

:nodoc:



78
79
80
# File 'lib/schema_associations.rb', line 78

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.



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

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.



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

has_value :except_type, :default => nil

#merge(opts) ⇒ Object

:nodoc:



88
89
90
# File 'lib/schema_associations.rb', line 88

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.



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

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.



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

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.



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

has_value :table_prefix_map, :default => {}

#update_attributes(opts) ⇒ Object

:nodoc:



82
83
84
85
86
# File 'lib/schema_associations.rb', line 82

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