json-emitter 0.2.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2c101e09517330bff537ee6584fc20ec6c8785a7aa3fd86936599709de18ab54
4
- data.tar.gz: 8d8cf0d57d66133d17c5cfc787244dfce26fba9c203049894a818381718720d3
3
+ metadata.gz: d2228e23ca76886db68f546e171db2e9c318f35c02e4262b19adf162d43e1151
4
+ data.tar.gz: c137299a78e76f0ffdeba789d9477ef94a4b161d0718287ba074dcbc90f4c82d
5
5
  SHA512:
6
- metadata.gz: 21da8c5d80a1be418a5b402e57a240dc5e0e8477f15818b4d1826a2361008cf93720ff1ecc18f1b10099ce7729bec6acea9865772b869f42fc89f388220d1413
7
- data.tar.gz: ba6d4e57f31d37a71892a4ad34b419d3401a26e447a4c02f3c5444865c75c86f2b0d7cabc9555571ae84c5804c24b108a6306a4ca1d060e2414c0b864559c73a
6
+ metadata.gz: b2a21066822a1e4f84df8facee734dd60951dbd489d5e80444be11546e9851e77f9d8c9edc6f9fd1900fd55407cf96cbc193c4402223aa78459265a119ab75a5
7
+ data.tar.gz: 2b025e42af1069efc578d5138e6535b35b507659e931ce59dd9164d96adc7dd1d1ceec334b22aa710a233198b63d8cad033b67e244d52a78854d553383e41bea
data/README.md CHANGED
@@ -98,6 +98,37 @@ File.open("~/out.json", "w+") { |f|
98
98
  }
99
99
  ```
100
100
 
101
+ # Deailing with errors
102
+
103
+ When streaming an HTTP response, you can't change the response code once you start sending data. So if you hit an error after you start, you need another way to communicate errors to the client.
104
+
105
+ One way is to always steam an object that includes an `errors` field. Any errors will be collected while the `Enumerator` is running. After it's finished, they'll be added to the JSON object.
106
+
107
+ ```ruby
108
+ def get_data
109
+ errors = []
110
+ enum = Enumerator.new { |y|
111
+ finished = false
112
+ until finished
113
+ data, errs, finished = get_data_chunk
114
+ if errs
115
+ errors += errs
116
+ finished = true
117
+ next
118
+ end
119
+ data.each { x| y << x }
120
+ end
121
+ }
122
+ return enum, -> { errors }
123
+ end
124
+
125
+ items_enum, errors_proc = get_data
126
+ JsonEmitter.object({
127
+ items: items_enum,
128
+ errors: errors_proc,
129
+ })
130
+ ```
131
+
101
132
  # License
102
133
 
103
134
  MIT License. See LICENSE for details.
@@ -1,4 +1,4 @@
1
1
  module JsonEmitter
2
2
  # Library version
3
- VERSION = "0.2.0".freeze
3
+ VERSION = "1.0.0".freeze
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: json-emitter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jordan Hollinger
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-04-29 00:00:00.000000000 Z
11
+ date: 2022-07-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: multi_json
@@ -56,7 +56,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
56
56
  - !ruby/object:Gem::Version
57
57
  version: '0'
58
58
  requirements: []
59
- rubygems_version: 3.0.3
59
+ rubygems_version: 3.0.3.1
60
60
  signing_key:
61
61
  specification_version: 4
62
62
  summary: Efficiently generate tons of JSON