Module: SchemaMonkey::CoreExtensions::ActiveRecord::ConnectionAdapters::TableDefinition

Defined in:
lib/schema_monkey/core_extensions/active_record/connection_adapters/table_definition.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



5
6
7
8
9
10
11
12
# File 'lib/schema_monkey/core_extensions/active_record/connection_adapters/table_definition.rb', line 5

def self.included(base)
  base.class_eval do
    alias_method_chain :column, :schema_monkey
    alias_method_chain :references, :schema_monkey
    alias_method_chain :belongs_to, :schema_monkey
    alias_method_chain :index, :schema_monkey
  end
end

Instance Method Details

#belongs_to_with_schema_monkey(name, options = {}) ⇒ Object



26
27
28
29
30
# File 'lib/schema_monkey/core_extensions/active_record/connection_adapters/table_definition.rb', line 26

def belongs_to_with_schema_monkey(name, options = {})
  SchemaMonkey::Middleware::Migration::Column.start(caller: self, operation: :define, table_name: self.name, column_name: "#{name}_id", type: :reference, options: options.deep_dup) do |env|
    belongs_to_without_schema_monkey env.column_name.sub(/_id$/, ''), env.options
  end
end

#column_with_schema_monkey(name, type, options = {}) ⇒ Object



14
15
16
17
18
# File 'lib/schema_monkey/core_extensions/active_record/connection_adapters/table_definition.rb', line 14

def column_with_schema_monkey(name, type, options = {})
  SchemaMonkey::Middleware::Migration::Column.start(caller: self, operation: :define, table_name: self.name, column_name: name, type: type, options: options.deep_dup) do |env|
    column_without_schema_monkey env.column_name, env.type, env.options
  end
end

#index_with_schema_monkey(*args) ⇒ Object



32
33
34
35
36
37
38
# File 'lib/schema_monkey/core_extensions/active_record/connection_adapters/table_definition.rb', line 32

def index_with_schema_monkey(*args)
  options = args.extract_options!
  column_name = args.first
  SchemaMonkey::Middleware::Migration::Index.start(caller: self, operation: :define, table_name: self.name, column_names: column_name, options: options.deep_dup) do |env|
    index_without_schema_monkey env.column_names, env.options
  end
end

#references_with_schema_monkey(name, options = {}) ⇒ Object



20
21
22
23
24
# File 'lib/schema_monkey/core_extensions/active_record/connection_adapters/table_definition.rb', line 20

def references_with_schema_monkey(name, options = {})
  SchemaMonkey::Middleware::Migration::Column.start(caller: self, operation: :define, table_name: self.name, column_name: "#{name}_id", type: :reference, options: options.deep_dup) do |env|
    references_without_schema_monkey env.column_name.sub(/_id$/, ''), env.options
  end
end