Module: SchemaPlus

Defined in:
lib/schema_plus.rb,
lib/schema_plus/railtie.rb,
lib/schema_plus/version.rb,
lib/schema_plus/active_record/base.rb,
lib/schema_plus/active_record/schema.rb,
lib/schema_plus/active_record/attribute.rb,
lib/schema_plus/active_record/db_default.rb,
lib/schema_plus/active_record/schema_dumper.rb,
lib/schema_plus/active_record/connection_adapters/column.rb,
lib/schema_plus/active_record/migration/command_recorder.rb,
lib/schema_plus/active_record/connection_adapters/mysql_adapter.rb,
lib/schema_plus/active_record/connection_adapters/sqlite3_adapter.rb,
lib/schema_plus/active_record/connection_adapters/abstract_adapter.rb,
lib/schema_plus/active_record/connection_adapters/index_definition.rb,
lib/schema_plus/active_record/connection_adapters/postgresql_adapter.rb,
lib/schema_plus/active_record/connection_adapters/foreign_key_definition.rb

Defined Under Namespace

Modules: ActiveRecord Classes: Config, Railtie

Constant Summary collapse

VERSION =
"1.8.9"

Class Method Summary collapse

Class Method Details

.configObject

Returns the global configuration, i.e., the singleton instance of Config


105
106
107
# File 'lib/schema_plus.rb', line 105

def self.config
  @config ||= Config.new
end

.insertObject

:nodoc:


148
149
150
151
152
153
154
155
156
157
# File 'lib/schema_plus.rb', line 148

def self.insert #:nodoc:
  return if @inserted
  @inserted = true
  insert_connection_adapters
  ::ActiveRecord::Base.send(:include, SchemaPlus::ActiveRecord::Base)
  ::ActiveRecord::Schema.send(:include, SchemaPlus::ActiveRecord::Schema)
  ::ActiveRecord::SchemaDumper.send(:include, SchemaPlus::ActiveRecord::SchemaDumper)
  ::ActiveRecord.const_set(:DB_DEFAULT, SchemaPlus::ActiveRecord::DB_DEFAULT)
  ::ActiveRecord::Attribute.send(:include, SchemaPlus::ActiveRecord::Attribute) if defined? ::ActiveRecord::Attribute
end

.insert_connection_adaptersObject

:nodoc:


122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# File 'lib/schema_plus.rb', line 122

def self.insert_connection_adapters #:nodoc:
  return if @inserted_connection_adapters
  @inserted_connection_adapters = true
  ::ActiveRecord::ConnectionAdapters::AbstractAdapter.send(:include, SchemaPlus::ActiveRecord::ConnectionAdapters::AbstractAdapter)
  ::ActiveRecord::ConnectionAdapters::Column.send(:include, SchemaPlus::ActiveRecord::ConnectionAdapters::Column)
  ::ActiveRecord::ConnectionAdapters::IndexDefinition.send(:include, SchemaPlus::ActiveRecord::ConnectionAdapters::IndexDefinition)
  ::ActiveRecord::ConnectionAdapters::SchemaStatements.send(:include, SchemaPlus::ActiveRecord::ConnectionAdapters::SchemaStatements)
  ::ActiveRecord::ConnectionAdapters::TableDefinition.send(:include, SchemaPlus::ActiveRecord::ConnectionAdapters::TableDefinition)
  ::ActiveRecord::Migration::CommandRecorder.send(:include, SchemaPlus::ActiveRecord::Migration::CommandRecorder)

  if "#{::ActiveRecord::VERSION::MAJOR}.#{::ActiveRecord::VERSION::MINOR}".to_r >= "4.1".to_r
    ::ActiveRecord::ConnectionAdapters::AbstractAdapter::SchemaCreation.send(:include, SchemaPlus::ActiveRecord::ConnectionAdapters::AbstractAdapter::AddColumnOptions)
  else
    ::ActiveRecord::ConnectionAdapters::AbstractAdapter.send(:include, SchemaPlus::ActiveRecord::ConnectionAdapters::AbstractAdapter::AddColumnOptions)
  end

  if ::ActiveRecord::VERSION::MAJOR.to_i >= 4
    ::ActiveRecord::ConnectionAdapters::AbstractAdapter::SchemaCreation.send(:include, SchemaPlus::ActiveRecord::ConnectionAdapters::AbstractAdapter::VisitTableDefinition)
  end

  if "#{::ActiveRecord::VERSION::MAJOR}.#{::ActiveRecord::VERSION::MINOR}".to_r >= "4.2".to_r
    require 'active_record/connection_adapters/abstract_mysql_adapter'
    ::ActiveRecord::ConnectionAdapters::AbstractMysqlAdapter::SchemaCreation.send(:include, SchemaPlus::ActiveRecord::ConnectionAdapters::AbstractAdapter::VisitTableDefinition)
  end
end

.setup {|config| ... } ⇒ Object

Initialization block is passed a global Config instance that can be used to configure SchemaPlus behavior. E.g., if you want to disable automation creation of foreign key constraints for columns name *_id, put the following in config/initializers/schema_plus.rb :

SchemaPlus.setup do |config|
   config.foreign_keys.auto_create = false
end

Yields:


118
119
120
# File 'lib/schema_plus.rb', line 118

def self.setup # :yields: config
  yield config
end