Module: Mongoid::Utils Private

Extended by:
Utils
Included in:
Utils
Defined in:
lib/mongoid/utils.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Utility functions for Mongoid.

Constant Summary collapse

PLACEHOLDER =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

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 collapse

Instance Method Details

#monotonic_timeFloat

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This function should be used if you need to measure time.

Examples:

Calculate elapsed time.

starting = Utils.monotonic_time
# do something time consuming
ending = Utils.monotonic_time
puts "It took #{(ending - starting).to_i} seconds"

Returns:

  • (Float)

    seconds according to monotonic clock

See Also:



37
38
39
# File 'lib/mongoid/utils.rb', line 37

def monotonic_time
  Process.clock_gettime(Process::CLOCK_MONOTONIC)
end

#placeholder?(value) ⇒ true | false

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Asks if the given value is a placeholder or not.

Parameters:

  • value (Object)

    the value to compare

Returns:

  • (true | false)

    if the value is a placeholder or not.



21
22
23
# File 'lib/mongoid/utils.rb', line 21

def placeholder?(value)
  value == PLACEHOLDER
end

#truthy_string?(string) ⇒ true | false

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

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.

Parameters:

  • string (String)

    the string value to consider

Returns:

  • (true | false)


48
49
50
# File 'lib/mongoid/utils.rb', line 48

def truthy_string?(string)
  %w[ 1 yes true on ].include?(string.strip.downcase)
end