Module: RedhillonrailsCore::ActiveRecord::ConnectionAdapters::AbstractAdapter

Defined in:
lib/redhillonrails_core/active_record/connection_adapters/abstract_adapter.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



5
6
7
8
# File 'lib/redhillonrails_core/active_record/connection_adapters/abstract_adapter.rb', line 5

def self.included(base)
  base.alias_method_chain :initialize, :redhillonrails_core
  base.alias_method_chain :drop_table, :redhillonrails_core
end

Instance Method Details

#add_foreign_key(table_name, column_names, references_table_name, references_column_names, options = {}) ⇒ Object



54
55
56
57
# File 'lib/redhillonrails_core/active_record/connection_adapters/abstract_adapter.rb', line 54

def add_foreign_key(table_name, column_names, references_table_name, references_column_names, options = {})
  foreign_key = ForeignKeyDefinition.new(options[:name], table_name, column_names, ::ActiveRecord::Migrator.proper_table_name(references_table_name), references_column_names, options[:on_update], options[:on_delete], options[:deferrable])
  execute "ALTER TABLE #{quote_table_name(table_name)} ADD #{foreign_key}"
end

#create_view(view_name, definition) ⇒ Object



31
32
33
# File 'lib/redhillonrails_core/active_record/connection_adapters/abstract_adapter.rb', line 31

def create_view(view_name, definition)
  execute "CREATE VIEW #{view_name} AS #{definition}"
end

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



63
64
65
66
# File 'lib/redhillonrails_core/active_record/connection_adapters/abstract_adapter.rb', line 63

def drop_table_with_redhillonrails_core(name, options = {})
  reverse_foreign_keys(name).each { |foreign_key| remove_foreign_key(foreign_key.table_name, foreign_key.name, options) }
  drop_table_without_redhillonrails_core(name, options)
end

#drop_view(view_name) ⇒ Object



35
36
37
# File 'lib/redhillonrails_core/active_record/connection_adapters/abstract_adapter.rb', line 35

def drop_view(view_name)
  execute "DROP VIEW #{view_name}"
end

#foreign_keys(table_name, name = nil) ⇒ Object



46
47
48
# File 'lib/redhillonrails_core/active_record/connection_adapters/abstract_adapter.rb', line 46

def foreign_keys(table_name, name = nil)
  []
end

#initialize_with_redhillonrails_core(*args) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/redhillonrails_core/active_record/connection_adapters/abstract_adapter.rb', line 10

def initialize_with_redhillonrails_core(*args)
  initialize_without_redhillonrails_core(*args)
  adapter = nil
  case adapter_name
    # name of MySQL adapter depends on mysql gem
    # * with mysql gem adapter is named MySQL
    # * with mysql2 gem adapter is named Mysql2
    # Here we handle this and hopefully futher adapter names
  when /^MySQL/i 
    adapter = 'MysqlAdapter'
  when 'PostgreSQL' 
    adapter = 'PostgresqlAdapter'
  when 'SQLite' 
    adapter = 'Sqlite3Adapter'
  end
  if adapter 
    adapter_module = RedhillonrailsCore::ActiveRecord::ConnectionAdapters.const_get(adapter)
    self.class.send(:include, adapter_module) unless self.class.include?(adapter_module)
  end
end

#remove_foreign_key(table_name, foreign_key_name, options = {}) ⇒ Object



59
60
61
# File 'lib/redhillonrails_core/active_record/connection_adapters/abstract_adapter.rb', line 59

def remove_foreign_key(table_name, foreign_key_name, options = {})
  execute "ALTER TABLE #{quote_table_name(table_name)} DROP CONSTRAINT #{foreign_key_name}"
end

#reverse_foreign_keys(table_name, name = nil) ⇒ Object



50
51
52
# File 'lib/redhillonrails_core/active_record/connection_adapters/abstract_adapter.rb', line 50

def reverse_foreign_keys(table_name, name = nil)
  []
end

#supports_partial_indexes?Boolean

Returns:

  • (Boolean)


68
69
70
# File 'lib/redhillonrails_core/active_record/connection_adapters/abstract_adapter.rb', line 68

def supports_partial_indexes?
  false
end

#view_definition(view_name, name = nil) ⇒ Object



43
44
# File 'lib/redhillonrails_core/active_record/connection_adapters/abstract_adapter.rb', line 43

def view_definition(view_name, name = nil)
end

#views(name = nil) ⇒ Object



39
40
41
# File 'lib/redhillonrails_core/active_record/connection_adapters/abstract_adapter.rb', line 39

def views(name = nil)
  []
end