Module: Upperkut::Util

Included in:
BatchExecution, Strategies::BufferedQueue, Strategies::ScheduledQueue
Defined in:
lib/upperkut/util.rb

Instance Method Summary collapse

Instance Method Details

#decode_json_items(items) ⇒ Object



24
25
26
27
28
29
30
31
# File 'lib/upperkut/util.rb', line 24

def decode_json_items(items)
  items.collect! do |i|
    JSON.parse(i) if i
  end

  items.compact!
  items
end

#encode_json_items(items) ⇒ Object



15
16
17
18
19
20
21
22
# File 'lib/upperkut/util.rb', line 15

def encode_json_items(items)
  items = items.collect do |i|
    JSON.generate(
      'enqueued_at' => Time.now.to_i,
      'body' => i
    )
  end
end

#to_underscore(object) ⇒ Object



5
6
7
8
9
10
11
12
13
# File 'lib/upperkut/util.rb', line 5

def to_underscore(object)
  klass_name = object
  klass_name.gsub!(/::/, '_')
  klass_name.gsub!(/([A-Z\d]+)([A-Z][a-z])/, '\1_\2')
  klass_name.gsub!(/([a-z\d])([A-Z])/, '\1_\2')
  klass_name.tr!('-', '_')
  klass_name.downcase!
  klass_name
end