Module: Mongoid::Utils Private
Relationships & Source Files | |
Defined in: | lib/mongoid/utils.rb |
Overview
Utility functions for ::Mongoid
.
Constant Summary
-
PLACEHOLDER =
A unique placeholder value that will never accidentally collide with valid values. This is useful as a default keyword argument value when you want the argument to be optional, but you also want to be able to recognize that the caller did not provide a value for it.
Object.new.freeze
Instance Method Summary
-
#monotonic_time ⇒ Float
Internal use only
This function should be used if you need to measure time.
-
#placeholder?(value) ⇒ true | false
Internal use only
Asks if the given value is a placeholder or not.
-
#truthy_string?(string) ⇒ true | false
Internal use only
Returns true if the string is any of the following values: “1”, “yes”, “true”, “on”.
Instance Method Details
#monotonic_time ⇒ Float
This function should be used if you need to measure time.
# File 'lib/mongoid/utils.rb', line 37
def monotonic_time Process.clock_gettime(Process::CLOCK_MONOTONIC) end
#placeholder?(value) ⇒ true
| false
Asks if the given value is a placeholder or not.
# File 'lib/mongoid/utils.rb', line 21
def placeholder?(value) value == PLACEHOLDER end
#truthy_string?(string) ⇒ true
| false
Returns true if the string is any of the following values: “1”, “yes”, “true”, “on”. Anything else is assumed to be false. Case is ignored, as are leading or trailing spaces.
# File 'lib/mongoid/utils.rb', line 48
def truthy_string?(string) %w[ 1 yes true on ].include?(string.strip.downcase) end