Module: Langfuse::Utils

Defined in:
lib/langfuse/utils.rb

Class Method Summary collapse

Class Method Details

.current_timestampObject



12
13
14
# File 'lib/langfuse/utils.rb', line 12

def current_timestamp
  Time.now.utc.iso8601(3)
end

.deep_camelize_keys(hash) ⇒ Object

将哈希的键名转换为小驼峰格式



41
42
43
44
45
46
47
48
49
# File 'lib/langfuse/utils.rb', line 41

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



30
31
32
33
34
35
36
37
38
# File 'lib/langfuse/utils.rb', line 30

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



20
21
22
23
24
25
26
27
28
# File 'lib/langfuse/utils.rb', line 20

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_idObject



8
9
10
# File 'lib/langfuse/utils.rb', line 8

def generate_id
  SecureRandom.uuid
end

.url_encode(string) ⇒ Object



16
17
18
# File 'lib/langfuse/utils.rb', line 16

def url_encode(string)
  ERB::Util.url_encode(string.to_s)
end