From 1a626e1958a7578455e53fe2f7cc89030b3a4092 Mon Sep 17 00:00:00 2001 From: tyler-ball Date: Mon, 6 Oct 2014 09:33:07 -0700 Subject: If an object does not have .to_json, we no longer try to call it --- lib/ffi_yajl/ffi/encoder.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'lib/ffi_yajl') diff --git a/lib/ffi_yajl/ffi/encoder.rb b/lib/ffi_yajl/ffi/encoder.rb index 3df366c..a493158 100644 --- a/lib/ffi_yajl/ffi/encoder.rb +++ b/lib/ffi_yajl/ffi/encoder.rb @@ -201,7 +201,11 @@ end # I feel dirty class Object def ffi_yajl(yajl_gen, state) - json = self.to_json(state[:json_opts]) + if self.respond_to?(:to_json) + json = self.to_json(state[:json_opts]) + else + json = self.to_s + end if ( status = FFI_Yajl.yajl_gen_number(yajl_gen, json, json.bytesize) ) != 0 FFI_Yajl::Encoder.raise_error_for_status(status) end -- cgit v1.2.1 From 3af1ec06bd861bf0eb01863cbe02dffadbf45503 Mon Sep 17 00:00:00 2001 From: tyler-ball Date: Mon, 6 Oct 2014 09:34:57 -0700 Subject: Upping version --- lib/ffi_yajl/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/ffi_yajl') diff --git a/lib/ffi_yajl/version.rb b/lib/ffi_yajl/version.rb index 2f55c2b..b175d87 100644 --- a/lib/ffi_yajl/version.rb +++ b/lib/ffi_yajl/version.rb @@ -1,3 +1,3 @@ module FFI_Yajl - VERSION = "1.1.0" + VERSION = "1.1.1" end -- cgit v1.2.1 From 31df485a023364383353dabb97f9f0609ceddde6 Mon Sep 17 00:00:00 2001 From: tyler-ball Date: Tue, 7 Oct 2014 10:54:54 -0700 Subject: Making necessary C changes to only call to_json if it is present --- lib/ffi_yajl/ffi/encoder.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/ffi_yajl') diff --git a/lib/ffi_yajl/ffi/encoder.rb b/lib/ffi_yajl/ffi/encoder.rb index a493158..3724e49 100644 --- a/lib/ffi_yajl/ffi/encoder.rb +++ b/lib/ffi_yajl/ffi/encoder.rb @@ -204,7 +204,7 @@ class Object if self.respond_to?(:to_json) json = self.to_json(state[:json_opts]) else - json = self.to_s + json = "\"#{to_s}\"" end if ( status = FFI_Yajl.yajl_gen_number(yajl_gen, json, json.bytesize) ) != 0 FFI_Yajl::Encoder.raise_error_for_status(status) -- cgit v1.2.1 From d713d2681aba154fc83d41b32bbdbb99c2055b61 Mon Sep 17 00:00:00 2001 From: tyler-ball Date: Tue, 7 Oct 2014 14:01:39 -0700 Subject: Cleaning up code - letting yajl do more heavy lifting for us. Also removing version change since that will occur during release. --- lib/ffi_yajl/ffi/encoder.rb | 7 +++++-- lib/ffi_yajl/version.rb | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) (limited to 'lib/ffi_yajl') 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 -- cgit v1.2.1