Module: Langfuse::Utils
- Defined in:
- lib/langfuse/utils.rb
Class Method Summary collapse
- .current_timestamp ⇒ Object
-
.deep_camelize_keys(hash) ⇒ Object
将哈希的键名转换为小驼峰格式.
- .deep_stringify_keys(hash) ⇒ Object
- .deep_symbolize_keys(hash) ⇒ Object
- .generate_id ⇒ Object
Class Method Details
.current_timestamp ⇒ Object
11 12 13 |
# File 'lib/langfuse/utils.rb', line 11 def Time.now.utc.iso8601(3) end |
.deep_camelize_keys(hash) ⇒ Object
将哈希的键名转换为小驼峰格式
36 37 38 39 40 41 42 43 44 |
# File 'lib/langfuse/utils.rb', line 36 def deep_camelize_keys(hash) return hash unless hash.is_a?(Hash) hash.each_with_object({}) do |(key, value), result| new_key = camelize_key(key.to_s) new_value = value.is_a?(Hash) ? deep_camelize_keys(value) : value result[new_key] = new_value end end |
.deep_stringify_keys(hash) ⇒ Object
25 26 27 28 29 30 31 32 33 |
# File 'lib/langfuse/utils.rb', line 25 def deep_stringify_keys(hash) return hash unless hash.is_a?(Hash) hash.each_with_object({}) do |(key, value), result| new_key = camelize_key(key.to_s) new_value = value.is_a?(Hash) ? deep_stringify_keys(value) : value result[new_key] = new_value end end |
.deep_symbolize_keys(hash) ⇒ Object
15 16 17 18 19 20 21 22 23 |
# File 'lib/langfuse/utils.rb', line 15 def deep_symbolize_keys(hash) return hash unless hash.is_a?(Hash) hash.each_with_object({}) do |(key, value), result| new_key = key.is_a?(String) ? key.to_sym : key new_value = value.is_a?(Hash) ? deep_symbolize_keys(value) : value result[new_key] = new_value end end |
.generate_id ⇒ Object
7 8 9 |
# File 'lib/langfuse/utils.rb', line 7 def generate_id SecureRandom.uuid end |