turbostreamer 1.2.0 → 1.3.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 +4 -4
- data/README.md +12 -0
- data/lib/turbostreamer/encoders/oj.rb +12 -8
- data/lib/turbostreamer/version.rb +1 -1
- metadata +19 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 81c2119468be8e96eb8e02da3fe72df9996aaa16fc610d4b0bf2b5f902663004
|
4
|
+
data.tar.gz: 21fc7309b4f17ae08e76b73f70bdc6c9d6a456a37d354aa53c45313b4c5e017d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5353499e01978fa2b6036f2bd26bd4f76a3da28cd07a242aec9be06d67afb9125b49ba179e8d13748945f36c9cfecb276118d88952c600854f88ce4c65e0fb41
|
7
|
+
data.tar.gz: 907614df89e2f67d3a087570eda988f55b498b85d65d4e2756eccafb2acfdcd7911ff4de726edadb3bec02b4428812b68d58ca86fcb8d884dbf1f4beaf304e2b
|
data/README.md
CHANGED
@@ -93,6 +93,18 @@ end
|
|
93
93
|
# => { "author": { "name": "David" } }
|
94
94
|
```
|
95
95
|
|
96
|
+
To merge existing hash or array to current context:
|
97
|
+
|
98
|
+
``` ruby
|
99
|
+
hash = { author: { name: "David" } }
|
100
|
+
json.post do
|
101
|
+
json.title "Merge HOWTO"
|
102
|
+
json.merge! hash
|
103
|
+
end
|
104
|
+
|
105
|
+
# => "post": { "title": "Merge HOWTO", "author": { "name": "David" } }
|
106
|
+
```
|
107
|
+
|
96
108
|
Top level arrays can be handled directly. Useful for index and other collection
|
97
109
|
actions.
|
98
110
|
|
@@ -4,7 +4,7 @@ class TurboStreamer
|
|
4
4
|
class OjEncoder
|
5
5
|
|
6
6
|
attr_reader :output
|
7
|
-
|
7
|
+
|
8
8
|
def initialize(io, options={})
|
9
9
|
@stack = []
|
10
10
|
@indexes = []
|
@@ -42,8 +42,6 @@ class TurboStreamer
|
|
42
42
|
@stack << :map
|
43
43
|
@indexes << 0
|
44
44
|
if @write_comma_on_next_push
|
45
|
-
@stream_writer.flush
|
46
|
-
@output.write(",".freeze)
|
47
45
|
@write_comma_on_next_push = false
|
48
46
|
end
|
49
47
|
@stream_writer.push_object
|
@@ -59,8 +57,6 @@ class TurboStreamer
|
|
59
57
|
@stack << :array
|
60
58
|
@indexes << 0
|
61
59
|
if @write_comma_on_next_push
|
62
|
-
@stream_writer.flush
|
63
|
-
@output.write(",".freeze)
|
64
60
|
@write_comma_on_next_push = false
|
65
61
|
end
|
66
62
|
@stream_writer.push_array
|
@@ -75,21 +71,26 @@ class TurboStreamer
|
|
75
71
|
def inject(string)
|
76
72
|
@stream_writer.flush
|
77
73
|
|
74
|
+
# It's possible to have
|
75
|
+
# `@write_comma_on_next_push == true` and `@indexes.last > 0`
|
76
|
+
# So there might be double comma written without this flag
|
77
|
+
comma_written = false
|
78
78
|
if @write_comma_on_next_push
|
79
79
|
@output.write(",".freeze)
|
80
80
|
@write_comma_on_next_push = false
|
81
|
+
comma_written = true
|
81
82
|
end
|
82
83
|
|
83
84
|
if @stack.last == :array && !string.empty?
|
84
85
|
if @indexes.last > 0
|
85
|
-
self.output.write(",")
|
86
|
+
self.output.write(",") unless comma_written
|
86
87
|
else
|
87
88
|
@write_comma_on_next_push = true
|
88
89
|
end
|
89
90
|
@indexes[-1] += 1
|
90
91
|
elsif @stack.last == :map && !string.empty?
|
91
92
|
if @indexes.last > 0
|
92
|
-
self.output.write(",")
|
93
|
+
self.output.write(",") unless comma_written
|
93
94
|
else
|
94
95
|
@write_comma_on_next_push = true
|
95
96
|
end
|
@@ -130,7 +131,10 @@ class TurboStreamer
|
|
130
131
|
result = result.sub(/\A\[/, ''.freeze).chomp("]".freeze)
|
131
132
|
end
|
132
133
|
|
133
|
-
|
134
|
+
# Possible for `output.string` to have value like
|
135
|
+
# `[,{"key":"value"}]\n`
|
136
|
+
# Thus the comma must be removed here
|
137
|
+
result.sub(/\A,/, ''.freeze)
|
134
138
|
ensure
|
135
139
|
@indexes.pop
|
136
140
|
@stream_writer = old_writer
|
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.
|
4
|
+
version: 1.3.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:
|
11
|
+
date: 2019-02-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -72,20 +72,14 @@ dependencies:
|
|
72
72
|
requirements:
|
73
73
|
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: '
|
76
|
-
- - ">="
|
77
|
-
- !ruby/object:Gem::Version
|
78
|
-
version: 1.11.2
|
75
|
+
version: '2.0'
|
79
76
|
type: :development
|
80
77
|
prerelease: false
|
81
78
|
version_requirements: !ruby/object:Gem::Requirement
|
82
79
|
requirements:
|
83
80
|
- - "~>"
|
84
81
|
- !ruby/object:Gem::Version
|
85
|
-
version: '
|
86
|
-
- - ">="
|
87
|
-
- !ruby/object:Gem::Version
|
88
|
-
version: 1.11.2
|
82
|
+
version: '2.0'
|
89
83
|
- !ruby/object:Gem::Dependency
|
90
84
|
name: mocha
|
91
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -184,6 +178,20 @@ dependencies:
|
|
184
178
|
- - ">="
|
185
179
|
- !ruby/object:Gem::Version
|
186
180
|
version: '0'
|
181
|
+
- !ruby/object:Gem::Dependency
|
182
|
+
name: rabl
|
183
|
+
requirement: !ruby/object:Gem::Requirement
|
184
|
+
requirements:
|
185
|
+
- - ">="
|
186
|
+
- !ruby/object:Gem::Version
|
187
|
+
version: '0'
|
188
|
+
type: :development
|
189
|
+
prerelease: false
|
190
|
+
version_requirements: !ruby/object:Gem::Requirement
|
191
|
+
requirements:
|
192
|
+
- - ">="
|
193
|
+
- !ruby/object:Gem::Version
|
194
|
+
version: '0'
|
187
195
|
description:
|
188
196
|
email:
|
189
197
|
- jonbracy@gmail.com
|
@@ -226,8 +234,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
226
234
|
- !ruby/object:Gem::Version
|
227
235
|
version: '0'
|
228
236
|
requirements: []
|
229
|
-
|
230
|
-
rubygems_version: 2.7.4
|
237
|
+
rubygems_version: 3.0.1
|
231
238
|
signing_key:
|
232
239
|
specification_version: 4
|
233
240
|
summary: Stream JSON via a Builder-style DSL
|