turbostreamer 1.1.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 69bc4c5ae74ca34c77d4efec5dcea7f3cc13121d
4
- data.tar.gz: 8061f78d59db2cbab4fbab6903e690f499b63bbc
2
+ SHA256:
3
+ metadata.gz: e135edfd638899e0bb26aab00a6cc7f63d702c53757b0f3f7aeb1500762fd6b2
4
+ data.tar.gz: 7a77931cabed9f76dec5925e5309fd8af550c2f5d829ed4472bf158e4e4555c4
5
5
  SHA512:
6
- metadata.gz: b921bb41799b13110dd30b3be833312f6a8049ee31dae19559ce7016b38b84b43bf304199172b10c932b0e8211ecd8574e2081100f109cf93d7ab27416fdf153
7
- data.tar.gz: 1bf7d693f46fd09c78b2f7c3339acda1978a52356177ff0ddf1a1e680d4c5621cd9a1d7047ebd83d12354790b9f03237cf478f47e446303d3893c9b95eb833ab
6
+ metadata.gz: 48b0c24c3e052f91ad2f82455698f3640b6fb0048c5d5a58da8f2332e4f7af79f26ba72e65073fd48f64049e3cd36ecd1674cd357c9030c4e849d3865cf567d3
7
+ data.tar.gz: 9c90fe729ce30b82f15919ded942519cef4436b2b5675711c549972e527210f1d7df173dfc92a45bea060273c2e92c7790a148314d2f78bfdb75c9cc2bb54ebc
data/README.md CHANGED
@@ -267,19 +267,39 @@ Syntax Differences from Jbuilder
267
267
  Backends
268
268
  --------
269
269
 
270
- Currently TurboStreamer only uses the [Wankel JSON backend](https://github.com/malomalo/wankel),
271
- which supports streaming parsing and encoding.
270
+ Currently TurboStreamer supports [Wankel](https://github.com/malomalo/wankel) and
271
+ [Oj](https://github.com/ohler55/oj) for JSON encoding.
272
272
 
273
- The idea was to also support [Oj](https://github.com/ohler55/oj) and
274
- [MessagePack](http://msgpack.org/).
273
+ By default TurboStreamer will look for `Oj` and `Wankel` and use the first
274
+ available option.
275
275
 
276
- Oj should be relatively easily to do, you just need to figure out how to switch
277
- out the io so it can be captured for caching.
276
+ You can also set the encoder when initializing:
278
277
 
279
- MessagePack would require a bit more work as you would need a change in the
280
- protocol. We do not know how big an array or map/object will be when we
278
+ ```ruby
279
+ TurboStreamer.encode(encoder: :oj)
280
+ # Or
281
+ TurboStreamer.encode(encoder: :wankel)
282
+
283
+ # You can also pass the class
284
+ TurboStreamer.encode(encoder: TurboStreamer::WankelEncoder)
285
+
286
+ # Or your own encoder
287
+ TurboStreamer.encode(encoder: MyEncoder)
288
+ ```
289
+
290
+ If you need explicitly set the default:
291
+
292
+ ```ruby
293
+ TurboStreamer.set_default_encoder(:json, :oj)
294
+ ```
295
+
296
+ The idea was to also support [MessagePack](http://msgpack.org/), hence requring
297
+ the mime type when setting a default encoder.
298
+
299
+ Implementing MessagePack would require a bit of work as you would need a change
300
+ in the protocol. We do not know how big an array or map/object will be when we
281
301
  start emitting it and MessagePack require we know it. It seems like a relatively
282
- small change, instead of a marker followed by number of elements there would be
302
+ small change, instead of a marker followed by number of lements there would be
283
303
  a start marker followed by the elements and then an end marker.
284
304
 
285
305
  All backends must have the following functions:
@@ -0,0 +1,12 @@
1
+
2
+
3
+ class TurboStreamer
4
+ module Errors
5
+ class MergeError < ::StandardError
6
+ def self.build(updates)
7
+ message = "Can't merge #{updates.inspect} which isn't Hash or Array"
8
+ new(message)
9
+ end
10
+ end
11
+ end
12
+ end
@@ -1,3 +1,3 @@
1
1
  class TurboStreamer
2
- VERSION = '1.1.0'
2
+ VERSION = '1.2.0'
3
3
  end
data/lib/turbostreamer.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'stringio'
2
2
  require 'turbostreamer/key_formatter'
3
+ require 'turbostreamer/errors'
3
4
 
4
5
  class TurboStreamer
5
6
 
@@ -160,6 +161,21 @@ class TurboStreamer
160
161
  end
161
162
  end
162
163
 
164
+ def merge!(hash_or_array)
165
+ if ::Array === hash_or_array
166
+ hash_or_array.each do |array_element|
167
+ value!(array_element)
168
+ end
169
+ elsif ::Hash === hash_or_array
170
+ hash_or_array.each_pair do |key, value|
171
+ key!(key)
172
+ value!(value)
173
+ end
174
+ else
175
+ raise Errors::MergeError.build(hash_or_array)
176
+ end
177
+ end
178
+
163
179
  alias_method :method_missing, :set!
164
180
  private :method_missing
165
181
 
@@ -297,7 +313,7 @@ class TurboStreamer
297
313
  # Encodes the current builder as JSON.
298
314
  def target!
299
315
  @encoder.flush
300
-
316
+
301
317
  if @encoder.output.is_a?(::StringIO)
302
318
  @encoder.output.string
303
319
  else
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: turbostreamer
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jon Bracy
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-12-09 00:00:00.000000000 Z
11
+ date: 2018-01-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -199,6 +199,7 @@ files:
199
199
  - lib/turbostreamer/dependency_tracker.rb
200
200
  - lib/turbostreamer/encoders/oj.rb
201
201
  - lib/turbostreamer/encoders/wankel.rb
202
+ - lib/turbostreamer/errors.rb
202
203
  - lib/turbostreamer/handler.rb
203
204
  - lib/turbostreamer/key_formatter.rb
204
205
  - lib/turbostreamer/railtie.rb
@@ -226,7 +227,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
226
227
  version: '0'
227
228
  requirements: []
228
229
  rubyforge_project:
229
- rubygems_version: 2.6.11
230
+ rubygems_version: 2.7.4
230
231
  signing_key:
231
232
  specification_version: 4
232
233
  summary: Stream JSON via a Builder-style DSL