ffi-yajl 1.0.1 → 1.0.2
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 +1 -1
 - data/ext/ffi_yajl/ext/encoder/encoder.c +4 -2
 - data/lib/ffi_yajl/encoder.rb +2 -1
 - data/lib/ffi_yajl/ffi/encoder.rb +1 -2
 - data/lib/ffi_yajl/json_gem.rb +8 -8
 - data/lib/ffi_yajl/parser.rb +6 -1
 - data/lib/ffi_yajl/version.rb +1 -1
 - data/spec/ffi_yajl/encoder_spec.rb +9 -1
 - data/spec/ffi_yajl/json_gem_spec.rb +11 -0
 - data/spec/ffi_yajl/parser_spec.rb +8 -0
 - metadata +4 -4
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA1:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 1b3576aa3b630817425565c2e7f18e03a6bf3144
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 0ba4867aafcbd1b5ed11e5aac09fb949d7fc28e2
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 0437fb83e17971e61d8b07cc539de3184a7a5718471deeb91ffa57eac960519ab4429de20b944b9cb087ffee6138346c7e1cb2652ed62d8c794d7ca01f5e688f
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: ddf01b4b3eeac328bdd8226acbc40648615f09ad6ab8662192e3774ee02c97203b65a61e78f69e8356e9c619fc5f6cac7191ed8b2ac5bd946618e3a10696cabb
         
     | 
    
        data/README.md
    CHANGED
    
    | 
         @@ -1,5 +1,5 @@ 
     | 
|
| 
       1 
1 
     | 
    
         | 
| 
       2 
     | 
    
         
            -
            [](https://travis-ci.org/opscode/ffi-yajl)  [](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,  
     | 
| 
      
 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);
         
     | 
    
        data/lib/ffi_yajl/encoder.rb
    CHANGED
    
    | 
         @@ -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)
         
     | 
    
        data/lib/ffi_yajl/ffi/encoder.rb
    CHANGED
    
    
    
        data/lib/ffi_yajl/json_gem.rb
    CHANGED
    
    | 
         @@ -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 
     | 
    
         | 
    
        data/lib/ffi_yajl/parser.rb
    CHANGED
    
    | 
         @@ -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]         =  
     | 
| 
      
 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]
         
     | 
    
        data/lib/ffi_yajl/version.rb
    CHANGED
    
    
| 
         @@ -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 
     | 
    
         
            -
             
     | 
| 
      
 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. 
     | 
| 
      
 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- 
     | 
| 
      
 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@ 
     | 
| 
      
 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/ 
     | 
| 
      
 164 
     | 
    
         
            +
            homepage: http://github.com/opscode/ffi-yajl
         
     | 
| 
       165 
165 
     | 
    
         
             
            licenses:
         
     | 
| 
       166 
166 
     | 
    
         
             
            - Apache-2.0
         
     | 
| 
       167 
167 
     | 
    
         
             
            metadata: {}
         
     |