ffi-yajl 1.0.1 → 1.0.2

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: e660d3d15b0a0f9af4ad908c4fbc45242782c101
4
- data.tar.gz: 9cfc7d0d71890a8a8d99074164dc5a012b45b009
3
+ metadata.gz: 1b3576aa3b630817425565c2e7f18e03a6bf3144
4
+ data.tar.gz: 0ba4867aafcbd1b5ed11e5aac09fb949d7fc28e2
5
5
  SHA512:
6
- metadata.gz: 9c4115b6df991bfd96123074691c591c1821a1234940b34ee0f554eb8e3087a9c1fe5bb69da32fd550e32298f8061f4d9da6125911bb217f52e7e5a9b756ab8c
7
- data.tar.gz: a2881d97c1aac2ba7546fd47aa2497f7a0efc16d46b854561a112cfc1cc36f02e51cf0447bd7e6d92ce0eb15f9a2c51de44cda0b9bfb949b86c4cf61a0901251
6
+ metadata.gz: 0437fb83e17971e61d8b07cc539de3184a7a5718471deeb91ffa57eac960519ab4429de20b944b9cb087ffee6138346c7e1cb2652ed62d8c794d7ca01f5e688f
7
+ data.tar.gz: ddf01b4b3eeac328bdd8226acbc40648615f09ad6ab8662192e3774ee02c97203b65a61e78f69e8356e9c619fc5f6cac7191ed8b2ac5bd946618e3a10696cabb
data/README.md CHANGED
@@ -1,5 +1,5 @@
1
1
 
2
- [![Build Status](https://travis-ci.org/lamont-granquist/ffi-yajl.png)](https://travis-ci.org/lamont-granquist/ffi-yajl) [![Code Climate](https://codeclimate.com/github/lamont-granquist/ffi-yajl.png)](https://codeclimate.com/github/lamont-granquist/ffi-yajl)
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)
3
3
 
4
4
  ## TODO
5
5
 
@@ -9,7 +9,7 @@ static VALUE cYajl_Gen;
9
9
  #define CHECK_STATUS(call) \
10
10
  if ((status = (call)) != yajl_gen_status_ok) { rb_funcall(mEncoder2, rb_intern("raise_error_for_status"), 1, INT2FIX(status)); }
11
11
 
12
- static VALUE mEncoder_do_yajl_encode(VALUE self, VALUE obj, VALUE yajl_gen_opts) {
12
+ static VALUE mEncoder_do_yajl_encode(VALUE self, VALUE obj, VALUE yajl_gen_opts, VALUE json_opts) {
13
13
  ID sym_ffi_yajl = rb_intern("ffi_yajl");
14
14
  VALUE sym_yajl_gen_beautify = ID2SYM(rb_intern("yajl_gen_beautify"));
15
15
  VALUE sym_yajl_gen_validate_utf8 = ID2SYM(rb_intern("yajl_gen_validate_utf8"));
@@ -42,6 +42,8 @@ static VALUE mEncoder_do_yajl_encode(VALUE self, VALUE obj, VALUE yajl_gen_opts)
42
42
 
43
43
  rb_hash_aset(state, rb_str_new2("processing_key"), Qfalse);
44
44
 
45
+ rb_hash_aset(state, rb_str_new2("json_opts"), json_opts);
46
+
45
47
  rb_yajl_gen = Data_Wrap_Struct(cYajl_Gen, NULL, NULL, yajl_gen);
46
48
 
47
49
  rb_funcall(obj, sym_ffi_yajl, 2, rb_yajl_gen, state);
@@ -261,7 +263,7 @@ void Init_encoder() {
261
263
  mExt = rb_define_module_under(mFFI_Yajl, "Ext");
262
264
  mEncoder = rb_define_module_under(mExt, "Encoder");
263
265
  cYajl_Gen = rb_define_class_under(mEncoder, "YajlGen", rb_cObject);
264
- rb_define_method(mEncoder, "do_yajl_encode", mEncoder_do_yajl_encode, 2);
266
+ rb_define_method(mEncoder, "do_yajl_encode", mEncoder_do_yajl_encode, 3);
265
267
 
266
268
  rb_define_method(rb_cHash, "ffi_yajl", rb_cHash_ffi_yajl, 2);
267
269
  rb_define_method(rb_cArray, "ffi_yajl", rb_cArray_ffi_yajl, 2);
@@ -18,7 +18,7 @@ module FFI_Yajl
18
18
  end
19
19
 
20
20
  # call either the ext or ffi hook
21
- str = do_yajl_encode(obj, yajl_gen_opts)
21
+ str = do_yajl_encode(obj, yajl_gen_opts, opts)
22
22
  str.force_encoding('UTF-8') if defined? Encoding
23
23
  str
24
24
  end
@@ -29,6 +29,7 @@ module FFI_Yajl
29
29
 
30
30
  def initialize(opts = {})
31
31
  @opts = opts
32
+ @opts ||= {}
32
33
  end
33
34
 
34
35
  def self.raise_error_for_status(status)
@@ -4,8 +4,7 @@ require 'ffi_yajl/ffi'
4
4
  module FFI_Yajl
5
5
  module FFI
6
6
  module Encoder
7
- def do_yajl_encode(obj, yajl_gen_opts = {})
8
-
7
+ def do_yajl_encode(obj, yajl_gen_opts, opts)
9
8
  yajl_gen = FFI_Yajl.yajl_gen_alloc(nil);
10
9
 
11
10
  # configure the yajl encoder
@@ -55,49 +55,49 @@ end
55
55
 
56
56
  class Array
57
57
  def to_json(*opts, &block)
58
- FFI_Yajl::Encoder.encode(self)
58
+ FFI_Yajl::Encoder.encode(self, *opts)
59
59
  end
60
60
  end
61
61
 
62
62
  class Hash
63
63
  def to_json(*opts, &block)
64
- FFI_Yajl::Encoder.encode(self)
64
+ FFI_Yajl::Encoder.encode(self, *opts)
65
65
  end
66
66
  end
67
67
 
68
68
  class Fixnum
69
69
  def to_json(*opts, &block)
70
- FFI_Yajl::Encoder.encode(self)
70
+ FFI_Yajl::Encoder.encode(self, *opts)
71
71
  end
72
72
  end
73
73
 
74
74
  class Float
75
75
  def to_json(*opts, &block)
76
- FFI_Yajl::Encoder.encode(self)
76
+ FFI_Yajl::Encoder.encode(self, *opts)
77
77
  end
78
78
  end
79
79
 
80
80
  class String
81
81
  def to_json(*opts, &block)
82
- FFI_Yajl::Encoder.encode(self)
82
+ FFI_Yajl::Encoder.encode(self, *opts)
83
83
  end
84
84
  end
85
85
 
86
86
  class TrueClass
87
87
  def to_json(*opts, &block)
88
- FFI_Yajl::Encoder.encode(self)
88
+ FFI_Yajl::Encoder.encode(self, *opts)
89
89
  end
90
90
  end
91
91
 
92
92
  class FalseClass
93
93
  def to_json(*opts, &block)
94
- FFI_Yajl::Encoder.encode(self)
94
+ FFI_Yajl::Encoder.encode(self, *opts)
95
95
  end
96
96
  end
97
97
 
98
98
  class NilClass
99
99
  def to_json(*opts, &block)
100
- FFI_Yajl::Encoder.encode(self)
100
+ FFI_Yajl::Encoder.encode(self, *opts)
101
101
  end
102
102
  end
103
103
 
@@ -41,7 +41,12 @@ module FFI_Yajl
41
41
  raise ArgumentError, "options check_utf8 and dont_validate_strings are both true which conflict"
42
42
  end
43
43
 
44
- yajl_opts[:yajl_allow_comments] = @opts[:allow_comments]
44
+ yajl_opts[:yajl_allow_comments] = true
45
+
46
+ if @opts.key?(:allow_comments)
47
+ yajl_opts[:yajl_allow_comments] = @opts[:allow_comments]
48
+ end
49
+
45
50
  yajl_opts[:yajl_dont_validate_strings] = (@opts[:check_utf8] == false || @opts[:dont_validate_strings])
46
51
  yajl_opts[:yajl_allow_trailing_garbage] = @opts[:allow_trailing_garbage]
47
52
  yajl_opts[:yajl_allow_multiple_values] = @opts[:allow_multiple_values]
@@ -1,3 +1,3 @@
1
1
  module FFI_Yajl
2
- VERSION = "1.0.1"
2
+ VERSION = "1.0.2"
3
3
  end
@@ -51,5 +51,13 @@ describe "FFI_Yajl::Encoder" do
51
51
  expect(encoder.encode(ruby)).to eq('{"gid":4294967294}')
52
52
  end
53
53
 
54
- end
54
+ context "when the encoder has nil passed in for options" do
55
+ let(:encoder) { FFI_Yajl::Encoder.new(nil) }
56
+
57
+ it "does not throw an exception" do
58
+ ruby = { "foo" => "bar" }
59
+ expect(encoder.encode(ruby)).to eq("{\"foo\":\"bar\"}")
60
+ end
61
+ end
55
62
 
63
+ end
@@ -97,6 +97,17 @@ describe "JSON Gem Compat API" do
97
97
  expect(JSON.pretty_generate({'foo' => 1234}, {})).to eql("{\n \"foo\": 1234\n}")
98
98
  end
99
99
 
100
+ class Foo
101
+ def to_json(*a)
102
+ {'foo' => 1234}.to_json(*a)
103
+ end
104
+ end
105
+
106
+ it "JSON#pretty_generate should work with an Object that implements #to_json" do
107
+ f = Foo.new
108
+ expect(JSON.pretty_generate(f)).to eql("{\n \"foo\": 1234\n}\n")
109
+ end
110
+
100
111
  context "when setting symbolize_keys via JSON.default_options" do
101
112
  after(:each) { JSON.default_options[:symbolize_keys] = false }
102
113
 
@@ -32,6 +32,14 @@ describe "FFI_Yajl::Parser" do
32
32
  expect(parser).to eq({"key"=>"value"})
33
33
  end
34
34
  end
35
+
36
+ context "by default" do
37
+ let(:options) { }
38
+
39
+ it "should parse" do
40
+ expect(parser).to eq({"key"=>"value"})
41
+ end
42
+ end
35
43
  end
36
44
 
37
45
  context "when json has multiline comments" do
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.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lamont Granquist
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-17 00:00:00.000000000 Z
11
+ date: 2014-08-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -109,7 +109,7 @@ dependencies:
109
109
  - !ruby/object:Gem::Version
110
110
  version: '1.0'
111
111
  description: Ruby FFI wrapper around YAJL 2.x
112
- email: lamont@scriptkiddie.org
112
+ email: lamont@getchef.com
113
113
  executables:
114
114
  - ffi-yajl-bench
115
115
  extensions:
@@ -161,7 +161,7 @@ files:
161
161
  - spec/ffi_yajl/json_gem_spec.rb
162
162
  - spec/ffi_yajl/parser_spec.rb
163
163
  - spec/spec_helper.rb
164
- homepage: http://github.com/lamont-granquist/ffi-yajl
164
+ homepage: http://github.com/opscode/ffi-yajl
165
165
  licenses:
166
166
  - Apache-2.0
167
167
  metadata: {}