Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added: database_type to configuration #344

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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