Class: Transit::Writer
- Inherits:
-
Object
- Object
- Transit::Writer
- Defined in:
- lib/transit/writer.rb
Overview
Transit::Writer marshals Ruby objects as transit values to an output stream.
Instance Method Summary collapse
-
#initialize(format, io, opts = {}) ⇒ Writer
constructor
Creates a new Writer configured to write to io in format (:json, :json_verbose, :msgpack).
- #write(obj) ⇒ Object
Constructor Details
#initialize(format, io, opts = {}) ⇒ Writer
Creates a new Writer configured to write to io in format (:json, :json_verbose, :msgpack).
Use opts to register custom write handlers, associating each one with its type.
39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/transit/writer.rb', line 39 def initialize(format, io, opts={}) @marshaler = case format when :json Marshaler::Json.new(io, {:handlers => {}, :oj_opts => {:indent => -1}}.merge(opts)) when :json_verbose Marshaler::VerboseJson.new(io, {:handlers => {}}.merge(opts)) else Marshaler::MessagePack.new(io, {:handlers => {}}.merge(opts)) end end |
Instance Method Details
#write(obj) ⇒ Object
59 60 61 |
# File 'lib/transit/writer.rb', line 59 def write(obj) @marshaler.write(obj) end |