aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/relation/predicate_builder
diff options
context:
space:
mode:
authorSean Griffin <sean@thoughtbot.com>2014-12-26 15:52:20 -0700
committerSean Griffin <sean@thoughtbot.com>2014-12-26 15:52:57 -0700
commiteac4658bb2b4f27ab0219b4986b711801583c39f (patch)
tree1c0cd0c608b0cc5f8bbf4f2d50ad56820d625b63 /activerecord/lib/active_record/relation/predicate_builder
parent3179b4a868c370bf879c15c53b78f25fadec9b41 (diff)
downloadrails-eac4658bb2b4f27ab0219b4986b711801583c39f.tar.gz
rails-eac4658bb2b4f27ab0219b4986b711801583c39f.tar.bz2
rails-eac4658bb2b4f27ab0219b4986b711801583c39f.zip
Eagerly cast range values in the predicate builder
A custom object is required for this, as you cannot build a range object out of `Arel::Nodes::Quoted` objects. Depends on the changes introduced in https://github.com/rails/arel/commit/cf03bd45e39def057a2f63e42a3391b7d750dece /cc @mrgilman
Diffstat (limited to 'activerecord/lib/active_record/relation/predicate_builder')
-rw-r--r--activerecord/lib/active_record/relation/predicate_builder/range_handler.rb24
1 files changed, 24 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/relation/predicate_builder/range_handler.rb b/activerecord/lib/active_record/relation/predicate_builder/range_handler.rb
index 47dc46bb4b..a6638738fa 100644
--- a/activerecord/lib/active_record/relation/predicate_builder/range_handler.rb
+++ b/activerecord/lib/active_record/relation/predicate_builder/range_handler.rb
@@ -1,9 +1,33 @@
module ActiveRecord
class PredicateBuilder
class RangeHandler # :nodoc:
+ def initialize(predicate_builder)
+ @predicate_builder = predicate_builder
+ end
+
def call(attribute, value)
+ value = QuotedRange.new(
+ predicate_builder.type_cast_for_database(attribute.name, value.begin),
+ predicate_builder.type_cast_for_database(attribute.name, value.end),
+ value.exclude_end?,
+ )
attribute.between(value)
end
+
+ protected
+
+ attr_reader :predicate_builder
+ end
+
+ class QuotedRange # :nodoc:
+ attr_reader :begin, :end, :exclude_end
+ alias_method :exclude_end?, :exclude_end
+
+ def initialize(begin_val, end_val, exclude)
+ @begin = begin_val
+ @end = end_val
+ @exclude_end = exclude
+ end
end
end
end