Skip to content

Commit

Permalink
Added: database_type to configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
lizdeika committed Apr 4, 2019
1 parent 9babda8 commit c92002c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/closure_tree/configuration.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module ClosureTree
class Configuration # :nodoc:
attr_accessor :database_less
attr_accessor :database_type

def initialize
@database_less = ENV['DATABASE_URL'].to_s.include?('//user:[email protected]/')
Expand Down
11 changes: 11 additions & 0 deletions lib/closure_tree/numeric_order_support.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,17 @@ def self.adapter_for_connection(connection)
end
end

def self.adapter_for_database_type(database_type)
case database_type
when :postgresql
::ClosureTree::NumericOrderSupport::PostgreSQLAdapter
when :mysql
::ClosureTree::NumericOrderSupport::MysqlAdapter
else
::ClosureTree::NumericOrderSupport::GenericAdapter
end
end

module MysqlAdapter
def reorder_with_parent_id(parent_id, minimum_sort_order_value = nil)
return if parent_id.nil? && dont_order_roots
Expand Down
6 changes: 5 additions & 1 deletion lib/closure_tree/support.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ def initialize(model_class, options)
}.merge(options)
raise ArgumentError, "name_column can't be 'path'" if options[:name_column] == 'path'
if order_is_numeric?
extend NumericOrderSupport.adapter_for_connection(connection)
if ClosureTree.configuration.database_type
extend NumericOrderSupport.adapter_for_database_type(ClosureTree.configuration.database_type)
else
extend NumericOrderSupport.adapter_for_connection(connection)
end
end
end

Expand Down

0 comments on commit c92002c

Please sign in to comment.