Module: Julewire::Core::Integration::Values::Shape
- Defined in:
- lib/julewire/core/integration/values.rb
Class Method Summary collapse
- .append_compact_field(fields, key, value) ⇒ Object
- .append_field(fields, key, value, compact_empty: false) ⇒ Object
- .hash_or_empty(value) ⇒ Object
- .payload_hash(value) ⇒ Object
- .source_location_attributes(location) ⇒ Object
- .timestamp(value) ⇒ Object
Class Method Details
.append_compact_field(fields, key, value) ⇒ Object
157 158 159 |
# File 'lib/julewire/core/integration/values.rb', line 157 def append_compact_field(fields, key, value) append_field(fields, key, value, compact_empty: true) end |
.append_field(fields, key, value, compact_empty: false) ⇒ Object
149 150 151 152 153 154 155 |
# File 'lib/julewire/core/integration/values.rb', line 149 def append_field(fields, key, value, compact_empty: false) return if value.nil? return if compact_empty && (value.is_a?(Hash) || value.is_a?(Array)) && value.empty? fields[key] = value nil end |
.hash_or_empty(value) ⇒ Object
142 143 144 145 146 147 |
# File 'lib/julewire/core/integration/values.rb', line 142 def hash_or_empty(value) return empty_hash unless value.is_a?(Hash) return empty_hash if value.empty? Fields::FieldSet.deep_symbolize_keys(value) end |
.payload_hash(value) ⇒ Object
129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/julewire/core/integration/values.rb', line 129 def payload_hash(value) case value when nil empty_hash when Hash return empty_hash if value.empty? Fields::FieldSet.deep_symbolize_keys(value) else { Fields::FieldSet::VALUE_KEY => value } end end |
.source_location_attributes(location) ⇒ Object
161 162 163 164 165 166 167 168 169 |
# File 'lib/julewire/core/integration/values.rb', line 161 def source_location_attributes(location) return {} unless location.is_a?(Hash) Fields::AttributeKeys.fields( Fields::AttributeKeys::CODE_FILE_PATH => Read.first_value(location, keys: %i[filepath path file]), Fields::AttributeKeys::CODE_LINE_NUMBER => Read.first_value(location, keys: %i[lineno line]), Fields::AttributeKeys::CODE_FUNCTION_NAME => Read.first_value(location, keys: %i[label function]) ) end |
.timestamp(value) ⇒ Object
118 119 120 121 122 123 124 125 126 127 |
# File 'lib/julewire/core/integration/values.rb', line 118 def (value) return unless value return value.utc.iso8601(9) if value.respond_to?(:utc) && value.respond_to?(:iso8601) return value unless value.respond_to?(:divmod) seconds, nanoseconds = value.divmod(1_000_000_000) Time.at(seconds, nanoseconds, :nanosecond).utc.iso8601(9) rescue StandardError nil end |