Module: Hyperion::Formats

Includes:
Logger
Included in:
Hyperion, Hyperion, FakeServer, ResultMaker
Defined in:
lib/hyperion/formats.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Logger

#log_result, #log_stub, #logger, #with_request_logging

Class Method Details

.get_from(x) ⇒ Object



39
40
41
# File 'lib/hyperion/formats.rb', line 39

def self.get_from(x)
  x.respond_to?(:format) ? x.format : x
end

Instance Method Details

#read(bytes, format) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/hyperion/formats.rb', line 27

def read(bytes, format)
  return nil if bytes.nil?
  return bytes if format.nil?

  case Formats.get_from(format)
  when :json; read_json(bytes)
  when :protobuf; bytes
  when Multipart.format; bytes # currently only used for testing purposes
  else; fail "Unsupported format: #{format}"
  end
end

#write(obj, format) ⇒ Object



16
17
18
19
20
21
22
23
24
25
# File 'lib/hyperion/formats.rb', line 16

def write(obj, format)
  return obj.body if obj.is_a?(Multipart)
  return obj if obj.is_a?(String) || obj.nil? || format.nil?

  case Formats.get_from(format)
  when :json; write_json(obj)
  when :protobuf; obj
  else; fail "Unsupported format: #{format}"
  end
end