Class: Hoth::Transport::Bert::TuplePreparer

Inherits:
Object
  • Object
show all
Defined in:
lib/hoth/transport/bert.rb

Class Method Summary collapse

Class Method Details

.prepare(obj) ⇒ Object



9
10
11
12
13
14
15
16
17
18
# File 'lib/hoth/transport/bert.rb', line 9

def self.prepare(obj)
  case obj
  when Array
    obj.collect { |o| prepare o }
  when Hash
    obj.each { |k,v| obj[k] = prepare(v) }
  else
    ruby2tuple obj
  end
end

.ruby2tuple(ruby) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/hoth/transport/bert.rb', line 20

def self.ruby2tuple(ruby)
  if ruby.respond_to? :to_serialize
    tuple = t[ruby.class.name.underscore, {}]
    ruby.to_serialize.each do |field|
      tuple.last[field] = prepare(ruby.send(field))
    end
    tuple
  else
    ruby
  end
end