Module: Langfuse::Utils

Defined in:
lib/langfuse/utils.rb

Class Method Summary collapse

Class Method Details

.current_timestampObject



14
15
16
# File 'lib/langfuse/utils.rb', line 14

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

.deep_camelize_keys(hash) ⇒ Object

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



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

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



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

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



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

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



10
11
12
# File 'lib/langfuse/utils.rb', line 10

def generate_id
  SecureRandom.uuid
end

.url_encode(string) ⇒ Object



18
19
20
# File 'lib/langfuse/utils.rb', line 18

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