Module: Soda::Tools

Included in:
CLI, Fetcher, Logger::Formatter, Logger::JobLogger, Processor, Queue, Queue::Message, Retrier
Defined in:
lib/soda/tools.rb

Constant Summary collapse

TID_KEY =
:_soda_tid

Instance Method Summary collapse

Instance Method Details

#deep_symbolize_keys(hash) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/soda/tools.rb', line 23

def deep_symbolize_keys(hash)
  transform_value = -> (value) {
    case value
    when Hash
      deep_symbolize_keys(value)
    when Array
      value.map { |val| transform_value.call(val) }
    else
      value
    end
  }

  {}.tap do |memo|
    hash.each do |key, value|
      memo.merge!(key.to_sym => transform_value.call(value))
    end
  end
end

#loggerObject



5
6
7
# File 'lib/soda/tools.rb', line 5

def logger
  ::Soda.logger
end

#nowObject



19
20
21
# File 'lib/soda/tools.rb', line 19

def now
  Process.clock_gettime(Process::CLOCK_MONOTONIC)
end

#sqs(&block) ⇒ Object



9
10
11
# File 'lib/soda/tools.rb', line 9

def sqs(&block)
  ::Soda.sqs(&block)
end

#tidObject



15
16
17
# File 'lib/soda/tools.rb', line 15

def tid
  Thread.current[TID_KEY] ||= (Thread.current.object_id ^ ::Process.pid).to_s(36)
end