wankel 0.3.1 → 0.4.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
  SHA1:
3
- metadata.gz: 794731e10604a40d87557559c974422920b468a0
4
- data.tar.gz: b328c5d3230268990c5d34004c6e8ae885e2d437
3
+ metadata.gz: d39a95397c69844f5192789cd5df648a8e9a8b47
4
+ data.tar.gz: 62d409b5d77f50cb3747ea8bf2cc18e38fa271a0
5
5
  SHA512:
6
- metadata.gz: 468bfdbee4e692305cceb4647c298d218cc43f4ec3278890254da41fc497657b1ac5300d92bab4f215a0d723bf65f9141778ffba1365a27da2957ed781739650
7
- data.tar.gz: 857c6ad778dc3d6a5917c03ccbac6c35531bdfeba8fefde80af1f0f30c0bfaf28f1954774932c46afc187c9f28ca2bca08e2110ae272def85772502560c48a64
6
+ metadata.gz: efd5c840d75fef714ed9f3483107f3ab18938630f21f025567586496afb3f92067842e2694c79b59ff3b42d2425177a3ab1cf9c6482ddc19c635819886622976
7
+ data.tar.gz: be6ee04733bc4f3a02e1402fba54ec017559a258564b4da7768c77b5925b40cb800d17f5f33739dd74a62081ba84ae3446c171089df3bd1973c3f6f019e41a80
@@ -0,0 +1 @@
1
+ exclude = '{$exclude,tmp,.tm_properties}'
@@ -0,0 +1,14 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
4
+ - 2.1.2
5
+ - 2.2.0-rc1
6
+ cache: bundler
7
+ install:
8
+ - wget 'https://github.com/lloyd/yajl/archive/2.1.0.tar.gz'
9
+ - tar -xvf '2.1.0.tar.gz'
10
+ - cd 'yajl-2.1.0' && ./configure && make && sudo make install
11
+ - sudo ldconfig
12
+ - bundle install
13
+ - bundle exec rake compile
14
+ script: bundle exec rake test
@@ -2,8 +2,14 @@
2
2
 
3
3
  New Features:
4
4
 
5
+ - Added `Wankel::SaxEncoder#value(VALUE)`
6
+ - Abilitly to change the output stream of a `Wankel::SaxEncoder` during generation
7
+ via `Wankel::SaxEncoder#output=`
8
+
5
9
  Major Changes:
6
10
 
11
+ - `Wankel::SaxEncoder#complete` changed to `Wankel::SaxEncoder#flush`
12
+
7
13
  Minor Changes:
8
14
 
9
15
  Bugfixes:
data/README.md CHANGED
@@ -83,7 +83,7 @@ encoder.number(123)
83
83
  encoder.string("type")
84
84
  encoder.value("value-determined-by-method")
85
85
  encoder.map_close
86
- encoder.complete
86
+ encoder.flush
87
87
  output.string # => '{"key":123,"type":"value-determined-by-method"}'
88
88
  ```
89
89
 
@@ -15,8 +15,8 @@ static VALUE wankelSaxEncoder_map_open(VALUE self);
15
15
  static VALUE wankelSaxEncoder_map_close(VALUE self);
16
16
  static VALUE wankelSaxEncoder_array_open(VALUE self);
17
17
  static VALUE wankelSaxEncoder_array_close(VALUE self);
18
- static VALUE wankelSaxEncoder_complete(VALUE self);
19
- static void wankelSaxEncoder_flush(wankel_encoder * p);
18
+ static VALUE wankelSaxEncoder_flush(VALUE self);
19
+ static void wankelSaxEncoder_write_buffer(wankel_encoder * p);
20
20
  static VALUE wankel_sax_encoder_alloc(VALUE klass);
21
21
  static void wankel_sax_encoder_free(void * handle);
22
22
  static void wankel_sax_encoder_mark(void * handle);
@@ -80,6 +80,21 @@ static VALUE wankelSaxEncoder_initialize(int argc, VALUE * argv, VALUE self) {
80
80
  return self;
81
81
  }
82
82
 
83
+ static VALUE wankelSaxEncoder_change_io(VALUE self, VALUE io) {
84
+ wankel_encoder * p;
85
+
86
+ if (!rb_respond_to(io, intern_io_write)) {
87
+ rb_raise(e_encodeError, "output must be a an IO");
88
+ }
89
+
90
+ Data_Get_Struct(self, wankel_encoder, p);
91
+
92
+ wankelSaxEncoder_flush(self);
93
+ p->output = io;
94
+
95
+ return Qnil;
96
+ }
97
+
83
98
  static VALUE wankelSaxEncoder_number(VALUE self, VALUE number) {
84
99
  size_t len;
85
100
  const char * cptr;
@@ -98,7 +113,7 @@ static VALUE wankelSaxEncoder_number(VALUE self, VALUE number) {
98
113
  status = yajl_gen_number(p->g, cptr, len);
99
114
  yajl_helper_check_gen_status(status);
100
115
 
101
- wankelSaxEncoder_flush(p);
116
+ wankelSaxEncoder_write_buffer(p);
102
117
 
103
118
  return Qnil;
104
119
  }
@@ -118,7 +133,7 @@ static VALUE wankelSaxEncoder_string(VALUE self, VALUE string) {
118
133
  status = yajl_gen_string(p->g, (const unsigned char *)cptr, len);
119
134
  yajl_helper_check_gen_status(status);
120
135
 
121
- wankelSaxEncoder_flush(p);
136
+ wankelSaxEncoder_write_buffer(p);
122
137
 
123
138
  return Qnil;
124
139
  }
@@ -131,7 +146,7 @@ static VALUE wankelSaxEncoder_null(VALUE self) {
131
146
  status = yajl_gen_null(p->g);
132
147
  yajl_helper_check_gen_status(status);
133
148
 
134
- wankelSaxEncoder_flush(p);
149
+ wankelSaxEncoder_write_buffer(p);
135
150
 
136
151
  return Qnil;
137
152
  }
@@ -144,7 +159,7 @@ static VALUE wankelSaxEncoder_boolean(VALUE self, VALUE b) {
144
159
  status = yajl_gen_bool(p->g, RTEST(b));
145
160
  yajl_helper_check_gen_status(status);
146
161
 
147
- wankelSaxEncoder_flush(p);
162
+ wankelSaxEncoder_write_buffer(p);
148
163
 
149
164
  return Qnil;
150
165
  }
@@ -157,7 +172,7 @@ static VALUE wankelSaxEncoder_map_open(VALUE self) {
157
172
  status = yajl_gen_map_open(p->g);
158
173
  yajl_helper_check_gen_status(status);
159
174
 
160
- wankelSaxEncoder_flush(p);
175
+ wankelSaxEncoder_write_buffer(p);
161
176
 
162
177
  return Qnil;
163
178
  }
@@ -170,7 +185,7 @@ static VALUE wankelSaxEncoder_map_close(VALUE self) {
170
185
  status = yajl_gen_map_close(p->g);
171
186
  yajl_helper_check_gen_status(status);
172
187
 
173
- wankelSaxEncoder_flush(p);
188
+ wankelSaxEncoder_write_buffer(p);
174
189
 
175
190
  return Qnil;
176
191
  }
@@ -183,7 +198,7 @@ static VALUE wankelSaxEncoder_array_open(VALUE self) {
183
198
  status = yajl_gen_array_open(p->g);
184
199
  yajl_helper_check_gen_status(status);
185
200
 
186
- wankelSaxEncoder_flush(p);
201
+ wankelSaxEncoder_write_buffer(p);
187
202
 
188
203
  return Qnil;
189
204
  }
@@ -196,12 +211,12 @@ static VALUE wankelSaxEncoder_array_close(VALUE self) {
196
211
  status = yajl_gen_array_close(p->g);
197
212
  yajl_helper_check_gen_status(status);
198
213
 
199
- wankelSaxEncoder_flush(p);
214
+ wankelSaxEncoder_write_buffer(p);
200
215
 
201
216
  return Qnil;
202
217
  }
203
218
 
204
- static VALUE wankelSaxEncoder_complete(VALUE self) {
219
+ static VALUE wankelSaxEncoder_flush(VALUE self) {
205
220
  size_t len;
206
221
  VALUE rbBuffer;
207
222
  wankel_encoder * p;
@@ -220,7 +235,7 @@ static VALUE wankelSaxEncoder_complete(VALUE self) {
220
235
  return Qnil;
221
236
  }
222
237
 
223
- void wankelSaxEncoder_flush(wankel_encoder * p) {
238
+ void wankelSaxEncoder_write_buffer(wankel_encoder * p) {
224
239
  VALUE rbBuffer;
225
240
  yajl_gen_status status;
226
241
  const unsigned char * buffer;
@@ -252,7 +267,8 @@ void Init_wankel_sax_encoder() {
252
267
  rb_define_method(c_wankelSaxEncoder, "map_close", wankelSaxEncoder_map_close, 0);
253
268
  rb_define_method(c_wankelSaxEncoder, "array_open", wankelSaxEncoder_array_open, 0);
254
269
  rb_define_method(c_wankelSaxEncoder, "array_close", wankelSaxEncoder_array_close, 0);
255
- rb_define_method(c_wankelSaxEncoder, "complete", wankelSaxEncoder_complete, 0);
270
+ rb_define_method(c_wankelSaxEncoder, "flush", wankelSaxEncoder_flush, 0);
271
+ rb_define_method(c_wankelSaxEncoder, "output=", wankelSaxEncoder_change_io, 1);
256
272
 
257
273
 
258
274
  intern_to_s = rb_intern("to_s");
@@ -24,42 +24,42 @@ class Wankel::SaxEncoderTest < Minitest::Test
24
24
 
25
25
  test "number" do
26
26
  @encoder.number(1234)
27
- @encoder.complete
27
+ @encoder.flush
28
28
 
29
29
  assert_output("1234")
30
30
  end
31
31
 
32
32
  test "string" do
33
33
  @encoder.string("hello world")
34
- @encoder.complete
34
+ @encoder.flush
35
35
 
36
36
  assert_output('"hello world"')
37
37
  end
38
38
 
39
39
  test "null" do
40
40
  @encoder.null
41
- @encoder.complete
41
+ @encoder.flush
42
42
 
43
43
  assert_output("null")
44
44
  end
45
45
 
46
46
  test "boolean(false)" do
47
47
  @encoder.boolean(false)
48
- @encoder.complete
48
+ @encoder.flush
49
49
 
50
50
  assert_output("false")
51
51
  end
52
52
 
53
53
  test "boolean(true)" do
54
54
  @encoder.boolean(true)
55
- @encoder.complete
55
+ @encoder.flush
56
56
 
57
57
  assert_output("true")
58
58
  end
59
59
 
60
60
  test "map_open" do
61
61
  @encoder.map_open
62
- @encoder.complete
62
+ @encoder.flush
63
63
 
64
64
  assert_output("{")
65
65
  end
@@ -67,14 +67,14 @@ class Wankel::SaxEncoderTest < Minitest::Test
67
67
  test "map_close" do
68
68
  @encoder.map_open
69
69
  @encoder.map_close
70
- @encoder.complete
70
+ @encoder.flush
71
71
 
72
72
  assert_output("{}")
73
73
  end
74
74
 
75
75
  test "array_open" do
76
76
  @encoder.array_open
77
- @encoder.complete
77
+ @encoder.flush
78
78
 
79
79
  assert_output("[")
80
80
  end
@@ -82,66 +82,100 @@ class Wankel::SaxEncoderTest < Minitest::Test
82
82
  test "array_close" do
83
83
  @encoder.array_open
84
84
  @encoder.array_close
85
- @encoder.complete
85
+ @encoder.flush
86
86
 
87
87
  assert_output("[]")
88
88
  end
89
89
 
90
90
  test "value(NUMBER)" do
91
91
  @encoder.value(123)
92
- @encoder.complete
92
+ @encoder.flush
93
93
 
94
94
  assert_output("123")
95
95
  end
96
96
 
97
97
  test "value(STRING)" do
98
98
  @encoder.value("hello")
99
- @encoder.complete
99
+ @encoder.flush
100
100
 
101
101
  assert_output("\"hello\"")
102
102
  end
103
103
 
104
104
  test "value(NIL)" do
105
105
  @encoder.value(nil)
106
- @encoder.complete
106
+ @encoder.flush
107
107
 
108
108
  assert_output("null")
109
109
  end
110
110
 
111
111
  test "value(BOOLEAN)" do
112
112
  @encoder.value(true)
113
- @encoder.complete
113
+ @encoder.flush
114
114
 
115
115
  assert_output("true")
116
116
 
117
117
  @output.rewind
118
118
  @encoder.value(false)
119
- @encoder.complete
119
+ @encoder.flush
120
120
 
121
121
  assert_output("true")
122
122
  end
123
123
 
124
124
  test "value(ARRAY)" do
125
125
  @encoder.value([])
126
- @encoder.complete
126
+ @encoder.flush
127
127
 
128
128
  assert_output("[]")
129
129
  end
130
130
 
131
131
  test "value(ARRAY_WITH_VALUES)" do
132
132
  @encoder.value([1, "hello", nil, false, true, 45.21, {:key => 'val'}])
133
- @encoder.complete
133
+ @encoder.flush
134
134
 
135
135
  assert_output("[1,\"hello\",null,false,true,45.21,{\"key\":\"val\"}]")
136
136
  end
137
137
 
138
138
  test "value(HASH)" do
139
139
  @encoder.value(:one => 'one', :two => 2, :three => true, :four => nil, 5 => [45.21])
140
- @encoder.complete
140
+ @encoder.flush
141
141
 
142
142
  assert_output('{"one":"one","two":2,"three":true,"four":null,"5":[45.21]}')
143
143
  end
144
144
 
145
+ test 'flush' do
146
+ output = StringIO.new
147
+
148
+ # Set large write_buffer_size to test flush
149
+ encoder = Wankel::SaxEncoder.new(output, :write_buffer_size => 1_000_000)
150
+ encoder.value({key: "value"})
151
+
152
+ assert_equal("", output.string)
153
+ encoder.flush
154
+ assert_equal('{"key":"value"}', output.string)
155
+ end
156
+
157
+ test "output=, changing the output io during generation" do
158
+ output1 = StringIO.new
159
+ output2 = StringIO.new
160
+
161
+ # Set large write_buffer_size to test flush
162
+ encoder = Wankel::SaxEncoder.new(output1, :write_buffer_size => 1_000_000)
163
+ encoder.map_open
164
+ encoder.string("key")
165
+ encoder.string("value")
166
+
167
+ assert_equal("", output1.string)
168
+ encoder.output = output2
169
+ assert_equal('{"key":"value"', output1.string)
170
+
171
+ encoder.string("other-key")
172
+ encoder.string("other-value")
173
+ encoder.map_close
174
+ assert_equal("", output2.string)
175
+ encoder.flush
176
+ assert_equal(',"other-key":"other-value"}', output2.string)
177
+ end
178
+
145
179
  end
146
180
  __END__
147
181
  test "map_open" do
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'wankel'
3
- s.version = '0.3.1'
3
+ s.version = '0.4.0'
4
4
  s.licenses = ['MIT']
5
5
  s.authors = ['Jon Bracy']
6
6
  s.email = ['jonbracy@gmail.com']
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wankel
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.4.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: 2014-12-19 00:00:00.000000000 Z
11
+ date: 2014-12-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake-compiler
@@ -75,6 +75,8 @@ extensions:
75
75
  extra_rdoc_files: []
76
76
  files:
77
77
  - ".gitignore"
78
+ - ".tm_properties"
79
+ - ".travis.yml"
78
80
  - CHANGELOG.md
79
81
  - Gemfile
80
82
  - LICENSE