Module: Julewire::Core::Integration::Values::Read
- Defined in:
- lib/julewire/core/integration/values.rb
Class Method Summary collapse
- .blank?(value) ⇒ Boolean
- .first_value(source, keys:) ⇒ Object
- .hash_value(hash, key, default: nil) ⇒ Object
- .nested_value(object, *keys, default: nil) ⇒ Object
- .path_value(object, path, default: nil) ⇒ Object
- .value(object, key, default: nil) ⇒ Object
Class Method Details
.blank?(value) ⇒ Boolean
29 30 31 |
# File 'lib/julewire/core/integration/values.rb', line 29 def blank?(value) blank_value?(value) end |
.first_value(source, keys:) ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/julewire/core/integration/values.rb', line 70 def first_value(source, keys:) if source.is_a?(Hash) found = direct_hash_first_value(source, keys) return found unless found.equal?(MISSING) end keys.each do |key| found = indexed_value(source, key) return found unless found.equal?(MISSING) || blank_value?(found) end nil end |
.hash_value(hash, key, default: nil) ⇒ Object
33 34 35 36 37 |
# File 'lib/julewire/core/integration/values.rb', line 33 def hash_value(hash, key, default: nil) return default unless hash.is_a?(Hash) direct_hash_value(hash, key, default) end |
.nested_value(object, *keys, default: nil) ⇒ Object
49 50 51 52 53 54 55 56 57 |
# File 'lib/julewire/core/integration/values.rb', line 49 def nested_value(object, *keys, default: nil) current = object keys.each do |key| return default if current.nil? current = value(current, key) end current.nil? ? default : current end |
.path_value(object, path, default: nil) ⇒ Object
59 60 61 62 63 64 65 66 67 68 |
# File 'lib/julewire/core/integration/values.rb', line 59 def path_value(object, path, default: nil) current = object Array(path).each do |key| return default if current.nil? current = indexed_value(current, key) return default if current.equal?(MISSING) end current end |
.value(object, key, default: nil) ⇒ Object
39 40 41 42 43 44 45 46 47 |
# File 'lib/julewire/core/integration/values.rb', line 39 def value(object, key, default: nil) return hash_value(object, key, default: default) if object.is_a?(Hash) return default unless object.respond_to?(key) object.public_send(key) rescue StandardError default end |