Class: JsonEmitter::Emitter
- Inherits:
-
Object
- Object
- JsonEmitter::Emitter
- Defined in:
- lib/json-emitter/emitter.rb
Overview
Builds Enumerators that yield JSON from Ruby Arrays or Hashes.
Instance Attribute Summary collapse
- #context ⇒ JsonEmitter::Context readonly
Instance Method Summary collapse
-
#array(enum) { ... } ⇒ Enumerator
Generates an Enumerator that will stream out a JSON array.
-
#initialize(rack_env: nil) ⇒ Emitter
constructor
A new instance of Emitter.
-
#object(hash) ⇒ Enumerator
Generates an Enumerator that will stream out a JSON object.
Constructor Details
Instance Attribute Details
#context ⇒ JsonEmitter::Context (readonly)
9 10 11 |
# File 'lib/json-emitter/emitter.rb', line 9 def context @context end |
Instance Method Details
#array(enum) { ... } ⇒ Enumerator
Generates an Enumerator that will stream out a JSON array.
22 23 24 25 26 27 28 29 30 |
# File 'lib/json-emitter/emitter.rb', line 22 def array(enum, &mapper) Enumerator.new { |y| context.execute { array_generator(enum, &mapper).each { |json_val| y << json_val } } } end |
#object(hash) ⇒ Enumerator
Generates an Enumerator that will stream out a JSON object.
38 39 40 41 42 43 44 45 46 |
# File 'lib/json-emitter/emitter.rb', line 38 def object(hash) Enumerator.new { |y| context.execute { object_generator(hash).each { |json_val| y << json_val } } } end |