Module: Mongoid::Criteria::Queryable::Extensions::String
- Defined in:
- build/mongoid-7.3/lib/mongoid/criteria/queryable/extensions/string.rb
Overview
This module contains additional object behavior.
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
-
#__evolve_date__ ⇒ Time
Evolve the string into a mongodb friendly date.
-
#__evolve_time__ ⇒ Time
Evolve the string into a mongodb friendly time.
-
#__expr_part__(value, negating = false) ⇒ Hash
Get the string as a specification.
-
#__mongo_expression__ ⇒ String
Get the string as a mongo expression, adding $ to the front.
-
#__sort_option__ ⇒ Hash
Get the string as a sort option.
-
#to_direction ⇒ Integer
Get the string as a sort direction.
Instance Method Details
#__evolve_date__ ⇒ Time
Evolve the string into a mongodb friendly date.
20 21 22 23 |
# File 'build/mongoid-7.3/lib/mongoid/criteria/queryable/extensions/string.rb', line 20 def __evolve_date__ time = ::Time.parse(self) ::Time.utc(time.year, time.month, time.day, 0, 0, 0, 0) end |
#__evolve_time__ ⇒ Time
Evolve the string into a mongodb friendly time.
33 34 35 |
# File 'build/mongoid-7.3/lib/mongoid/criteria/queryable/extensions/string.rb', line 33 def __evolve_time__ __mongoize_time__.utc end |
#__expr_part__(value, negating = false) ⇒ Hash
Get the string as a specification.
77 78 79 |
# File 'build/mongoid-7.3/lib/mongoid/criteria/queryable/extensions/string.rb', line 77 def __expr_part__(value, negating = false) ::String.__expr_part__(self, value, negating) end |
#__mongo_expression__ ⇒ String
Get the string as a mongo expression, adding $ to the front.
45 46 47 |
# File 'build/mongoid-7.3/lib/mongoid/criteria/queryable/extensions/string.rb', line 45 def __mongo_expression__ start_with?("$") ? self : "$#{self}" end |
#__sort_option__ ⇒ Hash
Get the string as a sort option.
57 58 59 60 61 62 63 64 |
# File 'build/mongoid-7.3/lib/mongoid/criteria/queryable/extensions/string.rb', line 57 def __sort_option__ split(/,/).inject({}) do |hash, spec| hash.tap do |_hash| field, direction = spec.strip.split(/\s/) _hash[field.to_sym] = direction.to_direction end end end |
#to_direction ⇒ Integer
Get the string as a sort direction.
89 90 91 |
# File 'build/mongoid-7.3/lib/mongoid/criteria/queryable/extensions/string.rb', line 89 def to_direction self =~ /desc/i ? -1 : 1 end |