1
0
Fork 0
mirror of https://github.com/activerecord-hackery/ransack.git synced 2022-11-09 13:47:45 -05:00

Merge pull request #541 from ASnow/exclusive-adapters

ActiveRecord should exclude Mongoid, extract logic to Ransack::Adapters
This commit is contained in:
Jon Atack 2015-07-26 23:26:48 +02:00
commit d6cb34a72a
5 changed files with 49 additions and 34 deletions

View file

@ -2,11 +2,8 @@ require 'active_support/core_ext'
require 'ransack/configuration' require 'ransack/configuration'
if defined?(::Mongoid) require 'ransack/adapters'
require 'ransack/adapters/mongoid/ransack/constants' Ransack::Adapters.require_constants
else
require 'ransack/adapters/active_record/ransack/constants'
end
module Ransack module Ransack
extend Configuration extend Configuration
@ -29,14 +26,6 @@ require 'action_controller'
require 'ransack/translate' require 'ransack/translate'
if defined?(::ActiveRecord::Base) Ransack::Adapters.require_adapter
require 'ransack/adapters/active_record/ransack/translate'
require 'ransack/adapters/active_record'
end
if defined?(::Mongoid)
require 'ransack/adapters/mongoid/ransack/translate'
require 'ransack/adapters/mongoid'
end
ActionController::Base.helper Ransack::Helpers::FormHelper ActionController::Base.helper Ransack::Helpers::FormHelper

42
lib/ransack/adapters.rb Normal file
View file

@ -0,0 +1,42 @@
module Ransack
module Adapters
def self.current_adapters
@current_adapters ||= {
:active_record => defined?(::ActiveRecord::Base),
:mongoid => defined?(::Mongoid) && !defined?(::ActiveRecord::Base)
}
end
def self.require_constants
require 'ransack/adapters/mongoid/ransack/constants' if current_adapters[:mongoid]
require 'ransack/adapters/active_record/ransack/constants' if current_adapters[:active_record]
end
def self.require_adapter
if current_adapters[:active_record]
require 'ransack/adapters/active_record/ransack/translate'
require 'ransack/adapters/active_record'
end
if current_adapters[:mongoid]
require 'ransack/adapters/mongoid/ransack/translate'
require 'ransack/adapters/mongoid'
end
end
def self.require_context
require 'ransack/adapters/active_record/ransack/visitor' if current_adapters[:active_record]
require 'ransack/adapters/mongoid/ransack/visitor' if current_adapters[:mongoid]
end
def self.require_nodes
require 'ransack/adapters/active_record/ransack/nodes/condition' if current_adapters[:active_record]
require 'ransack/adapters/mongoid/ransack/nodes/condition' if current_adapters[:mongoid]
end
def self.require_search
require 'ransack/adapters/active_record/ransack/context' if current_adapters[:active_record]
require 'ransack/adapters/mongoid/ransack/context' if current_adapters[:mongoid]
end
end
end

View file

@ -1,12 +1,5 @@
require 'ransack/visitor' require 'ransack/visitor'
Ransack::Adapters.require_context
if defined?(::ActiveRecord::Base)
require 'ransack/adapters/active_record/ransack/visitor'
end
if defined?(::Mongoid)
require 'ransack/adapters/mongoid/ransack/visitor'
end
module Ransack module Ransack
class Context class Context

View file

@ -3,7 +3,6 @@ require 'ransack/nodes/node'
require 'ransack/nodes/attribute' require 'ransack/nodes/attribute'
require 'ransack/nodes/value' require 'ransack/nodes/value'
require 'ransack/nodes/condition' require 'ransack/nodes/condition'
require 'ransack/adapters/active_record/ransack/nodes/condition' if defined?(::ActiveRecord::Base) Ransack::Adapters.require_nodes
require 'ransack/adapters/mongoid/ransack/nodes/condition' if defined?(::Mongoid)
require 'ransack/nodes/sort' require 'ransack/nodes/sort'
require 'ransack/nodes/grouping' require 'ransack/nodes/grouping'

View file

@ -1,14 +1,6 @@
require 'ransack/nodes' require 'ransack/nodes'
require 'ransack/context' require 'ransack/context'
Ransack::Adapters.require_search
if defined?(::ActiveRecord::Base)
require 'ransack/adapters/active_record/ransack/context'
end
if defined?(::Mongoid)
require 'ransack/adapters/mongoid/ransack/context'
end
require 'ransack/naming' require 'ransack/naming'
module Ransack module Ransack