ffi-yajl 1.1.0-universal-java → 1.2.0-universal-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ext/ffi_yajl/ext/encoder/encoder.c +13 -7
- data/lib/ffi_yajl/ext.rb +3 -1
- data/lib/ffi_yajl/ffi.rb +2 -0
- data/lib/ffi_yajl/ffi/encoder.rb +9 -2
- data/lib/ffi_yajl/version.rb +1 -1
- data/spec/ffi_yajl/encoder_spec.rb +17 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 410e86817fefb47ba78622492bba6e0672f0b50d
|
4
|
+
data.tar.gz: 1008ba36c8873d22d35a50de9fc03a8efb26c803
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e510a619bb8febbdb2f8e3a727f7ae94d5c44b45407ed91b543ec12254d54767c951100169bf9527750b943bc91846ecd063930a87bd2fe5af35abe90e7a15eb
|
7
|
+
data.tar.gz: de12c5a201956bcb7b35d5ca71b99e515063c94b181cabe698f9969075dd5c4cb180ded3fba81c8e97dbfa12db88a6d1da15fd0952bc3f622ea0df9c73246ac6
|
@@ -272,14 +272,20 @@ static VALUE rb_cObject_ffi_yajl(VALUE self, VALUE rb_yajl_gen, VALUE state) {
|
|
272
272
|
yajl_gen_status status;
|
273
273
|
ID sym_to_json = rb_intern("to_json");
|
274
274
|
VALUE str;
|
275
|
-
VALUE json_opts = rb_hash_aref(state, rb_str_new2("json_opts"));
|
276
|
-
struct yajl_gen_t *yajl_gen;
|
277
|
-
Data_Get_Struct(rb_yajl_gen, struct yajl_gen_t, yajl_gen);
|
278
275
|
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
276
|
+
if ( rb_respond_to(self, sym_to_json) ) {
|
277
|
+
VALUE json_opts = rb_hash_aref(state, rb_str_new2("json_opts"));
|
278
|
+
struct yajl_gen_t *yajl_gen;
|
279
|
+
Data_Get_Struct(rb_yajl_gen, struct yajl_gen_t, yajl_gen);
|
280
|
+
|
281
|
+
str = rb_funcall(self, sym_to_json, 1, json_opts);
|
282
|
+
CHECK_STATUS(
|
283
|
+
yajl_gen_number(yajl_gen, (char *)RSTRING_PTR(str), RSTRING_LEN(str))
|
284
|
+
);
|
285
|
+
} else {
|
286
|
+
object_to_s_ffi_yajl(self, rb_yajl_gen, state);
|
287
|
+
}
|
288
|
+
|
283
289
|
return Qnil;
|
284
290
|
}
|
285
291
|
|
data/lib/ffi_yajl/ext.rb
CHANGED
@@ -10,6 +10,8 @@ module FFI_Yajl
|
|
10
10
|
# FIXME: extract map_library_name from FFI and stop requiring it at the top level
|
11
11
|
# so that the C-library can be installed without FFI
|
12
12
|
libname = ::FFI.map_library_name("yajl")
|
13
|
+
# awful windows patch, but there is an open issue to entirely replace FFI.map_library_name already
|
14
|
+
libname = "libyajl.so" if libname == "yajl.dll"
|
13
15
|
libpath = File.expand_path(File.join(Libyajl2.opt_path, libname))
|
14
16
|
libpath.gsub!(/dylib/, 'bundle')
|
15
17
|
libpath = ::FFI.map_library_name("yajl") unless File.exist?(libpath)
|
@@ -48,7 +50,7 @@ module FFI_Yajl
|
|
48
50
|
extend ::FFI::Library
|
49
51
|
ffi_lib 'dl'
|
50
52
|
attach_function 'dlopen', :dlopen, [:string, :int], :void
|
51
|
-
if
|
53
|
+
if RbConfig::CONFIG['host_os'] =~ /linux/i
|
52
54
|
dlopen libpath, 0x102 # linux: RTLD_GLOBAL | RTLD_NOW
|
53
55
|
else
|
54
56
|
dlopen libpath, 0
|
data/lib/ffi_yajl/ffi.rb
CHANGED
@@ -7,6 +7,8 @@ module FFI_Yajl
|
|
7
7
|
extend ::FFI::Library
|
8
8
|
|
9
9
|
libname = ::FFI.map_library_name("yajl")
|
10
|
+
# XXX: need to replace ::FFI.map_library_name here as well
|
11
|
+
libname = "libyajl.so" if libname == "yajl.dll"
|
10
12
|
libpath = File.expand_path(File.join(Libyajl2.opt_path, libname))
|
11
13
|
libpath.gsub!(/dylib/, 'bundle')
|
12
14
|
|
data/lib/ffi_yajl/ffi/encoder.rb
CHANGED
@@ -201,8 +201,15 @@ end
|
|
201
201
|
# I feel dirty
|
202
202
|
class Object
|
203
203
|
def ffi_yajl(yajl_gen, state)
|
204
|
-
|
205
|
-
|
204
|
+
if self.respond_to?(:to_json)
|
205
|
+
json = self.to_json(state[:json_opts])
|
206
|
+
# #yajl_gen_number outputs a string without quotes around it
|
207
|
+
status = FFI_Yajl.yajl_gen_number(yajl_gen, json, json.bytesize)
|
208
|
+
else
|
209
|
+
str = self.to_s
|
210
|
+
status = FFI_Yajl.yajl_gen_string(yajl_gen, str, str.bytesize)
|
211
|
+
end
|
212
|
+
if ( status ) != 0
|
206
213
|
FFI_Yajl::Encoder.raise_error_for_status(status)
|
207
214
|
end
|
208
215
|
end
|
data/lib/ffi_yajl/version.rb
CHANGED
@@ -87,4 +87,21 @@ describe "FFI_Yajl::Encoder" do
|
|
87
87
|
expect(encoder.encode(ruby)).to eq( %q{"2001-02-03T04:05:06+07:00"} )
|
88
88
|
end
|
89
89
|
|
90
|
+
describe "testing .to_json for Objects" do
|
91
|
+
class NoToJson; end
|
92
|
+
class HasToJson
|
93
|
+
def to_json(*args)
|
94
|
+
"{}"
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
it "calls .to_s for objects without .to_json" do
|
99
|
+
expect(encoder.encode(NoToJson.new)).to match(/^"#<NoToJson:\w+>"$/)
|
100
|
+
end
|
101
|
+
|
102
|
+
it "calls .to_json for objects wit .to_json" do
|
103
|
+
expect(encoder.encode(HasToJson.new)).to eq("{}")
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
90
107
|
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
|
+
version: 1.2.0
|
5
5
|
platform: universal-java
|
6
6
|
authors:
|
7
7
|
- Lamont Granquist
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-10-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|