diff options
author | tyler-ball <tyleraball@gmail.com> | 2014-10-07 14:01:39 -0700 |
---|---|---|
committer | tyler-ball <tyleraball@gmail.com> | 2014-10-07 14:01:39 -0700 |
commit | d713d2681aba154fc83d41b32bbdbb99c2055b61 (patch) | |
tree | 41e85ca3d6b4dfa79b63c0d31f07116b8f141a18 | |
parent | 31df485a023364383353dabb97f9f0609ceddde6 (diff) | |
download | ffi-yajl-d713d2681aba154fc83d41b32bbdbb99c2055b61.tar.gz |
Cleaning up code - letting yajl do more heavy lifting for us. Also removing version change since that will occur during release.
-rw-r--r-- | CHANGELOG.md | 3 | ||||
-rw-r--r-- | lib/ffi_yajl/ffi/encoder.rb | 7 | ||||
-rw-r--r-- | lib/ffi_yajl/version.rb | 2 |
3 files changed, 9 insertions, 3 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 59eb314..651c40c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,9 @@ ### Changes +* Encoding Object will no longer blindly call .to_json(). It will first check if the Object supports a .to_json() method +and if it does not it will call .to_s(). This prevents NoSuchMethod errors when not using the JSON gem. + ### Bugs fixed * Change Config to RbConfig for FFI-based dlopen for non-DL/non-Fiddle fallback. diff --git a/lib/ffi_yajl/ffi/encoder.rb b/lib/ffi_yajl/ffi/encoder.rb index 3724e49..8177f5f 100644 --- a/lib/ffi_yajl/ffi/encoder.rb +++ b/lib/ffi_yajl/ffi/encoder.rb @@ -203,10 +203,13 @@ class Object def ffi_yajl(yajl_gen, state) if self.respond_to?(:to_json) json = self.to_json(state[:json_opts]) + # #yajl_gen_number outputs a string without quotes around it + status = FFI_Yajl.yajl_gen_number(yajl_gen, json, json.bytesize) else - json = "\"#{to_s}\"" + str = self.to_s + status = FFI_Yajl.yajl_gen_string(yajl_gen, str, str.bytesize) end - if ( status = FFI_Yajl.yajl_gen_number(yajl_gen, json, json.bytesize) ) != 0 + if ( status ) != 0 FFI_Yajl::Encoder.raise_error_for_status(status) end end diff --git a/lib/ffi_yajl/version.rb b/lib/ffi_yajl/version.rb index b175d87..2f55c2b 100644 --- a/lib/ffi_yajl/version.rb +++ b/lib/ffi_yajl/version.rb @@ -1,3 +1,3 @@ module FFI_Yajl - VERSION = "1.1.1" + VERSION = "1.1.0" end |