turbostreamer 1.2.0 → 1.3.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: e135edfd638899e0bb26aab00a6cc7f63d702c53757b0f3f7aeb1500762fd6b2
4
- data.tar.gz: 7a77931cabed9f76dec5925e5309fd8af550c2f5d829ed4472bf158e4e4555c4
3
+ metadata.gz: 81c2119468be8e96eb8e02da3fe72df9996aaa16fc610d4b0bf2b5f902663004
4
+ data.tar.gz: 21fc7309b4f17ae08e76b73f70bdc6c9d6a456a37d354aa53c45313b4c5e017d
5
5
  SHA512:
6
- metadata.gz: 48b0c24c3e052f91ad2f82455698f3640b6fb0048c5d5a58da8f2332e4f7af79f26ba72e65073fd48f64049e3cd36ecd1674cd357c9030c4e849d3865cf567d3
7
- data.tar.gz: 9c90fe729ce30b82f15919ded942519cef4436b2b5675711c549972e527210f1d7df173dfc92a45bea060273c2e92c7790a148314d2f78bfdb75c9cc2bb54ebc
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
- result
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
@@ -1,3 +1,3 @@
1
1
  class TurboStreamer
2
- VERSION = '1.2.0'
2
+ VERSION = '1.3.0'
3
3
  end
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.2.0
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: 2018-01-27 00:00:00.000000000 Z
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: '1.11'
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: '1.11'
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
- rubyforge_project:
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