ffi-yajl 1.4.0 → 2.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
  SHA1:
3
- metadata.gz: 7af5eee3b4627e919e66d1aea4326bdf251c4256
4
- data.tar.gz: 581d8c97420c1313de961eb974b74ded07c44f2b
3
+ metadata.gz: 22f963e220dde27e277e387e7dfba256859da2c8
4
+ data.tar.gz: d52391f8a6449ce89cbe3bb39a03cec421769967
5
5
  SHA512:
6
- metadata.gz: feb427a319145b354c0fc8f506a8b535e56b79d14abe803b9728ef3e6cd633547ed8857245bc58d15c7eeb14332f1bee32007d457afbe8ee46458ae81cfd7ad4
7
- data.tar.gz: d02c0c2c853b0d6d9fad1078d32a77e1984383592623121f748249e3cf7e605802b487b258442808341ad8fc559b07d650955d24e25c63f1727e758891df4b7d
6
+ metadata.gz: bf8965e64e5122273aea126fa4e6d284537e9680d298b4c6a24ff6a0c41f5540a2b22d6fb7181a6df80455909c05e943b55437aec7b54f041f5e99784b821970
7
+ data.tar.gz: 094122dadd975df2181a4fc51a6462086e37d6800ed05888f9b3c6591493ea3171c02d0b1bc1bd14122af4ec193bd569aafbd8b5dca4b136b17605f9c7a1a1e9
data/README.md CHANGED
@@ -1,5 +1,5 @@
1
1
 
2
- [![Build Status](https://travis-ci.org/opscode/ffi-yajl.png)](https://travis-ci.org/opscode/ffi-yajl) [![Code Climate](https://codeclimate.com/github/opscode/ffi-yajl.png)](https://codeclimate.com/github/opscode/ffi-yajl)
2
+ [![Build Status](https://travis-ci.org/chef/ffi-yajl.png)](https://travis-ci.org/chef/ffi-yajl) [![Code Climate](https://codeclimate.com/github/chef/ffi-yajl.png)](https://codeclimate.com/github/chef/ffi-yajl)
3
3
 
4
4
  # FFI YAJL
5
5
 
@@ -1,3 +1,3 @@
1
1
  module FFI_Yajl
2
- VERSION = "1.4.0"
2
+ VERSION = "2.0.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ffi-yajl
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lamont Granquist
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-17 00:00:00.000000000 Z
11
+ date: 2015-03-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -154,15 +154,13 @@ files:
154
154
  - lib/ffi_yajl/ffi.rb
155
155
  - lib/ffi_yajl/ffi/encoder.rb
156
156
  - lib/ffi_yajl/ffi/parser.rb
157
- - lib/ffi_yajl/json_gem.rb
158
157
  - lib/ffi_yajl/parser.rb
159
158
  - lib/ffi_yajl/platform.rb
160
159
  - lib/ffi_yajl/version.rb
161
160
  - spec/ffi_yajl/encoder_spec.rb
162
- - spec/ffi_yajl/json_gem_spec.rb
163
161
  - spec/ffi_yajl/parser_spec.rb
164
162
  - spec/spec_helper.rb
165
- homepage: http://github.com/opscode/ffi-yajl
163
+ homepage: http://github.com/chef/ffi-yajl
166
164
  licenses:
167
165
  - Apache-2.0
168
166
  metadata: {}
@@ -1,140 +0,0 @@
1
-
2
- # JSON compatibility layer, largely plagarized from yajl-ruby
3
-
4
- require 'ffi_yajl' unless defined?(FFI_Yajl::Parser)
5
-
6
- warn "ffi-yajl/json_gem is deprecated, these monkeypatches will be dropped shortly"
7
-
8
- module JSON
9
- class JSONError < StandardError; end unless defined?(JSON::JSONError)
10
- class GeneratorError < JSONError; end unless defined?(JSON::GeneratorError)
11
- class ParserError < JSONError; end unless defined?(JSON::ParserError)
12
-
13
- def self.generate(obj, opts=nil)
14
- opts ||= {}
15
- options_map = {}
16
- if opts.has_key?(:indent)
17
- options_map[:pretty] = true
18
- options_map[:indent] = opts[:indent]
19
- end
20
- FFI_Yajl::Encoder.encode(obj, options_map)
21
- rescue FFI_Yajl::EncodeError => e
22
- raise JSON::GeneratorError, e.message
23
- end
24
-
25
- def self.pretty_generate(obj, opts=nil)
26
- opts ||= {}
27
- options_map = {}
28
- options_map[:pretty] = true
29
- options_map[:indent] = opts[:indent] if opts.has_key?(:indent)
30
- FFI_Yajl::Encoder.encode(obj, options_map).chomp
31
- rescue FFI_Yajl::EncodeError => e
32
- raise JSON::GeneratorError, e.message
33
- end
34
-
35
- def self.dump(obj, io=nil, *args)
36
- FFI_Yajl::Encoder.encode(obj, io)
37
- rescue FFI_Yajl::EncodeError => e
38
- raise JSON::GeneratorError, e.message
39
- end
40
-
41
- def self.default_options
42
- @default_options ||= {:symbolize_keys => false}
43
- end
44
-
45
- def self.parse(str, opts=JSON.default_options)
46
- FFI_Yajl::Parser.parse(str, opts)
47
- rescue FFI_Yajl::ParseError => e
48
- raise JSON::ParserError, e.message
49
- end
50
-
51
- def self.load(input, *args)
52
- FFI_Yajl::Parser.parse(input, default_options)
53
- rescue FFI_Yajl::ParseError => e
54
- raise JSON::ParserError, e.message
55
- end
56
- end
57
-
58
- class Array
59
- def to_json(*opts, &block)
60
- FFI_Yajl::Encoder.encode(self, *opts)
61
- end
62
- end
63
-
64
- class Hash
65
- def to_json(*opts, &block)
66
- FFI_Yajl::Encoder.encode(self, *opts)
67
- end
68
- end
69
-
70
- class Fixnum
71
- def to_json(*opts, &block)
72
- FFI_Yajl::Encoder.encode(self, *opts)
73
- end
74
- end
75
-
76
- class Float
77
- def to_json(*opts, &block)
78
- FFI_Yajl::Encoder.encode(self, *opts)
79
- end
80
- end
81
-
82
- class String
83
- def to_json(*opts, &block)
84
- FFI_Yajl::Encoder.encode(self, *opts)
85
- end
86
- end
87
-
88
- class TrueClass
89
- def to_json(*opts, &block)
90
- FFI_Yajl::Encoder.encode(self, *opts)
91
- end
92
- end
93
-
94
- class FalseClass
95
- def to_json(*opts, &block)
96
- FFI_Yajl::Encoder.encode(self, *opts)
97
- end
98
- end
99
-
100
- class NilClass
101
- def to_json(*opts, &block)
102
- FFI_Yajl::Encoder.encode(self, *opts)
103
- end
104
- end
105
-
106
- class Date
107
- def to_json(*opts, &block)
108
- FFI_Yajl::Encoder.encode(self, *opts)
109
- end
110
- end
111
-
112
- class Time
113
- def to_json(*opts, &block)
114
- FFI_Yajl::Encoder.encode(self, *opts)
115
- end
116
- end
117
-
118
- class DateTime
119
- def to_json(*opts, &block)
120
- FFI_Yajl::Encoder.encode(self, *opts)
121
- end
122
- end
123
-
124
- module ::Kernel
125
- def JSON(object, opts = {})
126
- if object.respond_to? :to_s
127
- JSON.parse(object.to_s, JSON.default_options.merge(opts))
128
- else
129
- JSON.generate(object,opts)
130
- end
131
- end
132
- end
133
-
134
- class Object
135
- unless defined?(ActiveSupport)
136
- def to_json(*args, &block)
137
- "\"#{to_s}\""
138
- end
139
- end
140
- end
@@ -1,382 +0,0 @@
1
- # encoding: UTF-8
2
-
3
- # This started life as yajl-ruby's json_gem_compatibility/compatibility_spec.rb file.
4
- # Kinda looks like they stole it from the JSON gem. I updated the syntax a lot.
5
-
6
- require 'spec_helper'
7
- require 'date'
8
-
9
- class Dummy; end
10
-
11
- describe "JSON Gem Compat API" do
12
-
13
- # Magic to make the before loading tests actually run before loading
14
- RSpec.configure do |config|
15
- config.register_ordering(:global) do |list|
16
- list.sort_by { |item| item.description }
17
- end
18
- end
19
-
20
- context "A: before loading the compat library" do
21
- it "should not mixin #to_json on random objects" do
22
- d = Dummy.new
23
- expect(d.respond_to?(:to_json)).to be false
24
- end
25
-
26
- it "should not mixin #to_json to a string" do
27
- expect("".respond_to?(:to_json)).to be false
28
- end
29
-
30
- it "should not mixin #to_json to a fixnum" do
31
- expect(1.respond_to?(:to_json)).to be false
32
- end
33
-
34
- it "should not mixin #to_json on a float" do
35
- expect("1.5".to_f.respond_to?(:to_json)).to be false
36
- end
37
-
38
- it "should not mixin #to_json on an array" do
39
- expect([].respond_to?(:to_json)).to be false
40
- end
41
-
42
- it "should not mixin #to_json on a hash" do
43
- expect({ :foo => "bar" }.respond_to?(:to_json)).to be false
44
- end
45
-
46
- it "should not mixin #to_json on a trueclass" do
47
- expect(true.respond_to?(:to_json)).to be false
48
- end
49
-
50
- it "should not mixin #to_json on a falseclass" do
51
- expect(false.respond_to?(:to_json)).to be false
52
- end
53
-
54
- it "should not mixin #to_json on a nilclass" do
55
- expect(nil.respond_to?(:to_json)).to be false
56
- end
57
- end
58
-
59
- context "B: when in compat mode" do
60
-
61
- before(:all) do
62
- require 'ffi_yajl/json_gem'
63
- end
64
-
65
- it "should define JSON class" do
66
- expect(defined?(JSON)).to be_truthy
67
- end
68
-
69
- it "should implement JSON#parse" do
70
- expect(JSON.respond_to?(:parse)).to be true
71
- end
72
-
73
- it "should implement JSON#generate" do
74
- expect(JSON.respond_to?(:generate)).to be true
75
- end
76
-
77
- it "should implement JSON#pretty_generate" do
78
- expect(JSON.respond_to?(:pretty_generate)).to be true
79
- end
80
-
81
- it "should implement JSON#load" do
82
- expect(JSON.respond_to?(:load)).to be true
83
- end
84
-
85
- it "should implement JSON#dump" do
86
- expect(JSON.respond_to?(:dump)).to be true
87
- end
88
-
89
- it "JSON#pretty_generate should work with an explicit nil for options" do
90
- expect(JSON.pretty_generate({'foo' => 1234}, nil)).to eql("{\n \"foo\": 1234\n}")
91
- end
92
-
93
- it "JSON#pretty_generate should work without options" do
94
- expect(JSON.pretty_generate({'foo' => 1234})).to eql("{\n \"foo\": 1234\n}")
95
- end
96
-
97
- it "JSON#pretty_generate should work with an empty options hash" do
98
- expect(JSON.pretty_generate({'foo' => 1234}, {})).to eql("{\n \"foo\": 1234\n}")
99
- end
100
-
101
- class Foo
102
- def to_json(*a)
103
- {'foo' => 1234}.to_json(*a)
104
- end
105
- end
106
-
107
- it "JSON#pretty_generate should work with an Object that implements #to_json" do
108
- f = Foo.new
109
- expect(JSON.pretty_generate(f)).to eql("{\n \"foo\": 1234\n}\n")
110
- end
111
-
112
- context "when setting symbolize_keys via JSON.default_options" do
113
- after(:each) { JSON.default_options[:symbolize_keys] = false }
114
-
115
- it "the default behavior should be to not symbolize keys" do
116
- expect(JSON.parse('{"foo": 1234}')).to eq( "foo" => 1234 )
117
- end
118
-
119
- it "changing the default_options should change the behavior to true" do
120
- JSON.default_options[:symbolize_keys] = true
121
- expect(JSON.parse('{"foo": 1234}')).to eq( :foo => 1234 )
122
- end
123
- end
124
-
125
- context "when setting symbolize_names via JSON.default_options" do
126
- after { JSON.default_options.delete(:symbolize_names)}
127
-
128
- it "the default behavior should be to not symbolize keys" do
129
- expect(JSON.parse('{"foo": 1234}')).to eq( "foo" => 1234 )
130
- end
131
-
132
- it "changing the default_options should change the behavior to true" do
133
- JSON.default_options[:symbolize_names] = true
134
- expect(JSON.parse('{"foo": 1234}')).to eq( :foo => 1234 )
135
- end
136
- end
137
-
138
- it "should support passing symbolize_names to JSON.parse" do
139
- expect(JSON.parse('{"foo": 1234}', :symbolize_names => true)).to eq( :foo => 1234 )
140
- end
141
-
142
- it "should support passing symbolize_keys to JSON.parse" do
143
- expect(JSON.parse('{"foo": 1234}', :symbolize_keys => true)).to eq( :foo => 1234 )
144
- end
145
-
146
- context "when encode arbitrary classes via their default to_json method" do
147
- it "encodes random classes correctly" do
148
- d = Dummy.new
149
- expect(d.to_json).to eq( %Q{"#{d.to_s}"} )
150
- end
151
-
152
- context "when encoding Time objects in UTC timezone" do
153
- before do
154
- @saved_tz = ENV['TZ']
155
- ENV['TZ'] = 'UTC'
156
- end
157
-
158
- after do
159
- ENV['TZ'] = @saved_tz
160
- end
161
-
162
- it "encodes Time values correctly" do
163
- t = Time.local(2001, 02, 02, 21, 05, 06)
164
- expect(t.to_json).to eq( %Q{"2001-02-02 21:05:06 +0000"} )
165
- end
166
- end
167
-
168
- it "encodes Date values correctly" do
169
- da = Date.parse('2001-02-03')
170
- expect(da.to_json).to eq( %Q{"2001-02-03"} )
171
- end
172
-
173
- it "encodes DateTime values correctly" do
174
- dt = DateTime.parse('2001-02-03T04:05:06.1+07:00')
175
- expect(dt.to_json).to eq( %Q{"2001-02-03T04:05:06+07:00"} )
176
- end
177
- end
178
-
179
- context "JSON exception classes" do
180
- it "should define JSON::JSONError as a StandardError" do
181
- expect(JSON::JSONError.new.is_a?(StandardError)).to be true
182
- end
183
- it "should define JSON::ParserError as a JSON::JSONError" do
184
- expect(JSON::ParserError.new.is_a?(JSON::JSONError)).to be true
185
- end
186
- it "should define JSON::GeneratorError as a JSON::JSONError" do
187
- expect(JSON::GeneratorError.new.is_a?(JSON::JSONError)).to be true
188
- end
189
- it "should raise JSON::ParserError on a bad parse" do
190
- expect{ JSON.parse("blah") }.to raise_error(JSON::ParserError)
191
- end
192
- it "should raise JSON::GeneratorError on encoding NaN" do
193
- expect{ JSON.generate(0.0/0.0) }.to raise_error(JSON::GeneratorError)
194
- end
195
- it "should raise JSON::GeneratorError on encoding -Infinity" do
196
- expect{ JSON.generate(-1.0/0.0) }.to raise_error(JSON::GeneratorError)
197
- end
198
- it "should raise JSON::GeneratorError on encoding Infinity" do
199
- expect{ JSON.generate(1.0/0.0) }.to raise_error(JSON::GeneratorError)
200
- end
201
- it "should raise JSON::GeneratorError on encoding a partial UTF-8 character" do
202
- expect{ JSON.generate(["\xea"]) }.to raise_error(JSON::GeneratorError)
203
- end
204
- end
205
-
206
- shared_examples_for "handles encoding and parsing correctly" do
207
- it "should encode the content correctly" do
208
- expect(ruby.to_json).to eq(json)
209
- end
210
- it "should parse the content correctly" do
211
- expect(JSON.parse(json)).to eq(ruby)
212
- end
213
- end
214
-
215
- context "when encoding strings" do
216
- it "should render empty string correctly" do
217
- expect(''.to_json).to eq( %q{""} )
218
- end
219
- it "should encode backspace character" do
220
- expect("\b".to_json).to eq( %q{"\\b"} )
221
- end
222
- it "should encode \u0001 correctly" do
223
- expect(0x1.chr.to_json).to eq( %q{"\u0001"} )
224
- end
225
-
226
- it "should encode \u001f correctly" do
227
- expect(0x1f.chr.to_json).to eq( %q{"\u001F"} )
228
- end
229
-
230
- it "should encode a string with a space correctly" do
231
- expect(' '.to_json).to eq( %q{" "} )
232
- end
233
-
234
- it "should encode 0x75 correctly" do
235
- expect(0x7f.chr.to_json).to eq( %Q{"#{0x7f.chr}"} )
236
- end
237
-
238
- context "when dealing with bignums" do
239
- let(:ruby) { [ 12345678901234567890 ] }
240
- let(:json) { "[12345678901234567890]" }
241
-
242
- it_behaves_like "handles encoding and parsing correctly"
243
- end
244
-
245
- context "when dealing with common UTF-8 symbols" do
246
- let(:ruby) { [ "© ≠ €! \01" ] }
247
- let(:json) { "[\"© ≠ €! \\u0001\"]" }
248
-
249
- it_behaves_like "handles encoding and parsing correctly"
250
- end
251
-
252
- context "when dealing with Hiragana UTF-8 characters" do
253
- let(:ruby) { ["\343\201\202\343\201\204\343\201\206\343\201\210\343\201\212"] }
254
- let(:json) { "[\"あいうえお\"]" }
255
-
256
- it_behaves_like "handles encoding and parsing correctly"
257
- end
258
-
259
- context "whatever this is" do
260
- let(:ruby) { ['საქართველო'] }
261
- let(:json) { "[\"საქართველო\"]" }
262
-
263
- it_behaves_like "handles encoding and parsing correctly"
264
- end
265
-
266
- context "accents" do
267
- let(:ruby) { ["Ã"] }
268
- let(:json) { '["Ã"]' }
269
-
270
- it_behaves_like "handles encoding and parsing correctly"
271
- end
272
-
273
- context "euro symbol" do
274
- let(:ruby) { ["€"] }
275
- let(:json) { '["\u20ac"]' }
276
- it "should parse the content correctly" do
277
- expect(JSON.parse(json)).to eq(ruby)
278
- end
279
- end
280
-
281
- context "and whatever this is" do
282
-
283
- utf8_str = "\xf0\xa0\x80\x81"
284
- let(:ruby) { [utf8_str] }
285
- let(:json) { "[\"#{utf8_str}\"]" }
286
-
287
- it_behaves_like "handles encoding and parsing correctly"
288
- end
289
- end
290
-
291
- context "when encoding basic types with #to_json" do
292
- it "Array#to_json should work" do
293
- expect([ "a", "b", "c" ].to_json).to eq(%Q{["a","b","c"]})
294
- end
295
-
296
- it "Hash#to_json should work" do
297
- expect({ "a"=>"b" }.to_json).to eq(%Q{{"a":"b"}})
298
- end
299
-
300
- it "Fixnum#to_json should work" do
301
- expect(1.to_json).to eq("1")
302
- end
303
-
304
- it "Float#to_json should work" do
305
- expect(1.1.to_json).to eq("1.1")
306
- end
307
-
308
- it "String#to_json should work" do
309
- expect("foo".to_json).to eq(%Q{"foo"})
310
- end
311
-
312
- it "TrueClass#to_json should work" do
313
- expect(true.to_json).to eq("true")
314
- end
315
-
316
- it "FalseClass#to_json should work" do
317
- expect(false.to_json).to eq("false")
318
- end
319
-
320
- it "NilClass#to_json should work" do
321
- expect(nil.to_json).to eq("null")
322
- end
323
- end
324
-
325
- context "ported tests for generation" do
326
- before(:all) do
327
- @hash = {
328
- 'a' => 2,
329
- 'b' => 3.141,
330
- 'c' => 'c',
331
- 'd' => [ 1, "b", 3.14 ],
332
- 'e' => { 'foo' => 'bar' },
333
- 'g' => "blah",
334
- 'h' => 1000.0,
335
- 'i' => 0.001,
336
- }
337
-
338
- @json2 = '{"a":2,"b":3.141,"c":"c","d":[1,"b",3.14],"e":{"foo":"bar"},"g":"blah","h":1000.0,"i":0.001}'
339
-
340
- @json3 = %{
341
- {
342
- "a": 2,
343
- "b": 3.141,
344
- "c": "c",
345
- "d": [1, "b", 3.14],
346
- "e": {"foo": "bar"},
347
- "g": "blah",
348
- "h": 1000.0,
349
- "i": 0.001
350
- }
351
- }.chomp
352
- end
353
-
354
- it "should be able to unparse" do
355
- json = JSON.generate(@hash)
356
- expect(JSON.parse(@json2)).to eq(JSON.parse(json))
357
- parsed_json = JSON.parse(json)
358
- expect(@hash).to eq(parsed_json)
359
- json = JSON.generate( 1=>2 )
360
- expect('{"1":2}').to eql(json)
361
- parsed_json = JSON.parse(json)
362
- expect( "1"=>2 ).to eq(parsed_json)
363
- end
364
-
365
- it "should be able to unparse pretty" do
366
- json = JSON.pretty_generate(@hash)
367
- expect(JSON.parse(@json3)).to eq(JSON.parse(json))
368
- parsed_json = JSON.parse(json)
369
- expect(@hash).to eq(parsed_json)
370
- json = JSON.pretty_generate( 1=>2 )
371
- test = "{\n \"1\": 2\n}".chomp
372
- expect(test).to eq(json)
373
- parsed_json = JSON.parse(json)
374
- expect( "1"=>2 ).to eq(parsed_json)
375
- end
376
-
377
- it "JSON.generate should handle nil second argument" do
378
- expect(JSON.generate(["foo"], nil)).to eql(%q{["foo"]})
379
- end
380
- end
381
- end
382
- end