Skip to content

Commit

Permalink
DRY up: Extract #remove_index override into Module
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Coles <alex@alexbcoles.com>
  • Loading branch information
myabc committed Aug 18, 2016
1 parent 1b4cfee commit 0c9d021
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 33 deletions.
1 change: 1 addition & 0 deletions lib/schema_plus/indexes.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
require 'schema_plus/core'
require 'its-it'

require_relative 'indexes/remove_if_exists'
require_relative 'indexes/active_record/base'
require_relative 'indexes/active_record/connection_adapters/abstract_adapter'
require_relative 'indexes/active_record/connection_adapters/postgresql_adapter'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,7 @@ module SchemaPlus::Indexes
module ActiveRecord
module ConnectionAdapters
module AbstractAdapter

# Extends rails' remove_index to include this options:
# :if_exists
def remove_index(table_name, *args)
options = args.extract_options!
if_exists = options.delete(:if_exists)
args << options if options.any?
return if if_exists and not index_name_exists?(table_name, options[:name] || index_name(table_name, *args), false)
super table_name, *args
end

include ::SchemaPlus::Indexes::RemoveIfExists
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,7 @@ module SchemaPlus::Indexes
module ActiveRecord
module ConnectionAdapters
module PostgresqlAdapter

# Extends rails' remove_index to include this options:
# :if_exists
def remove_index(table_name, *args)
options = args.extract_options!
if_exists = options.delete(:if_exists)
args << options if options.any?
return if if_exists and not index_name_exists?(table_name, options[:name] || index_name(table_name, *args), false)
super table_name, *args
end

include ::SchemaPlus::Indexes::RemoveIfExists
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,7 @@ module SchemaPlus::Indexes
module ActiveRecord
module ConnectionAdapters
module Sqlite3Adapter

# Extends rails' remove_index to include this options:
# :if_exists
def remove_index(table_name, *args)
options = args.extract_options!
if_exists = options.delete(:if_exists)
args << options if options.any?
return if if_exists and not index_name_exists?(table_name, options[:name] || index_name(table_name, *args), false)
super table_name, *args
end

include ::SchemaPlus::Indexes::RemoveIfExists
end
end
end
Expand Down
13 changes: 13 additions & 0 deletions lib/schema_plus/indexes/remove_if_exists.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module SchemaPlus::Indexes
module RemoveIfExists
# Extends rails' remove_index to include this options:
# :if_exists
def remove_index(table_name, *args)
options = args.extract_options!
if_exists = options.delete(:if_exists)
args << options if options.any?
return if if_exists && !index_name_exists?(table_name, options[:name] || index_name(table_name, *args), false)
super table_name, *args
end
end
end

0 comments on commit 0c9d021

Please sign in to comment.