Module: Mongoid::Criteria::Queryable::Extensions::Range
Relationships & Source Files | |
Namespace Children | |
Modules:
| |
Defined in: | lib/mongoid/criteria/queryable/extensions/range.rb |
Overview
Adds query type-casting behavior to Range
class.
Instance Method Summary
-
#__array__ ⇒ Array
Get the range as an array.
-
#__evolve_date__ ⇒ Hash
Convert the range to a $gte/$lte mongo friendly query for dates.
-
#__evolve_range__(serializer: nil) ⇒ Hash
Internal use only
Internal use only
Convert the range to a $gte/$lte mongo friendly query.
-
#__evolve_time__ ⇒ Hash
Convert the range to a $gte/$lte mongo friendly query for times.
- #__evolve_range_naive__ private Internal use only Internal use only
Instance Method Details
#__array__ ⇒ Array
Get the range as an array.
# File 'lib/mongoid/criteria/queryable/extensions/range.rb', line 18
def __array__ to_a end
#__evolve_date__ ⇒ Hash
Convert the range to a $gte/$lte mongo friendly query for dates.
# File 'lib/mongoid/criteria/queryable/extensions/range.rb', line 28
def __evolve_date__ __evolve_range_naive__.transform_values! {|v| v&.__evolve_date__ } end
#__evolve_range__(serializer: nil) ⇒ Hash
This method is for internal use only.
Convert the range to a $gte/$lte mongo friendly query.
# File 'lib/mongoid/criteria/queryable/extensions/range.rb', line 52
def __evolve_range__(serializer: nil) __evolve_range_naive__.transform_values! do |value| if serializer serializer.evolve(value) else case value when Time, DateTime then value.__evolve_time__ when Date then value.__evolve_date__ else value end end end end
#__evolve_range_naive__ (private)
This method is for internal use only.
Note:
This method’s return value will be mutated by the _evolve*__ methods, therefore it must always return new objects.
# File 'lib/mongoid/criteria/queryable/extensions/range.rb', line 72
def __evolve_range_naive__ hash = {} hash['$gte'] = self.begin if self.begin hash[exclude_end? ? "$lt" : "$lte"] = self.end if self.end hash end
#__evolve_time__ ⇒ Hash
Convert the range to a $gte/$lte mongo friendly query for times.
# File 'lib/mongoid/criteria/queryable/extensions/range.rb', line 38
def __evolve_time__ __evolve_range_naive__.transform_values! {|v| v&.__evolve_time__ } end