Module: JMESPath::Util Private

Defined in:
lib/jmespath/util.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.

API:

  • private

Class Method Summary collapse

Class Method Details

.as_json(value) ⇒ Object

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.

API:

  • private



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/jmespath/util.rb', line 19

def as_json(value)
  if value.respond_to?(:to_ary)
    value.to_ary.map { |e| as_json(e) }
  elsif value.respond_to?(:to_hash)
    hash = {}
    value.to_hash.each_pair { |k, v| hash[k] = as_json(v) }
    hash
  elsif value.respond_to?(:to_str)
    value.to_str
  else
    value
  end
end

.falsey?(value) ⇒ Boolean

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.

Determines if a value is false as defined by JMESPath:

https://github.com/jmespath/jmespath.site/blob/master/docs/proposals/improved-filters.rst#and-expressions-1

Returns:

API:

  • private



10
11
12
13
14
15
16
17
# File 'lib/jmespath/util.rb', line 10

def falsey?(value)
  !value ||
    (value.respond_to?(:to_ary) && value.to_ary.empty?) ||
    (value.respond_to?(:to_hash) && value.to_hash.empty?) ||
    (value.respond_to?(:to_str) && value.to_str.empty?) ||
    (value.respond_to?(:entries) && !value.entries.any?)
  # final case necessary to support Enumerable and Struct
end