summaryrefslogtreecommitdiff
path: root/lib/ffi_yajl/ffi/encoder.rb
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2014-08-11 09:07:25 -0700
committerLamont Granquist <lamont@scriptkiddie.org>2014-08-23 11:16:14 -0700
commit5d35f31762750169569eb5ae9ce51b9af8a91793 (patch)
tree1f23d0cd156fc05791bc16d9d105868477c189b2 /lib/ffi_yajl/ffi/encoder.rb
parent3759f4e96d3800260e3d942dd225867c13e78b33 (diff)
downloadffi-yajl-5d35f31762750169569eb5ae9ce51b9af8a91793.tar.gz
add datetime encoding
necessary for ohai json_gem spec complies with JSON gem format. this also arguably fixes issues with yajl-ruby where it does not encode date objects correctly.
Diffstat (limited to 'lib/ffi_yajl/ffi/encoder.rb')
-rw-r--r--lib/ffi_yajl/ffi/encoder.rb28
1 files changed, 27 insertions, 1 deletions
diff --git a/lib/ffi_yajl/ffi/encoder.rb b/lib/ffi_yajl/ffi/encoder.rb
index 3bad69f..b82c0fe 100644
--- a/lib/ffi_yajl/ffi/encoder.rb
+++ b/lib/ffi_yajl/ffi/encoder.rb
@@ -171,6 +171,33 @@ class String
end
end
+class Date
+ def ffi_yajl(yajl_gen, state)
+ str = self.to_s
+ if ( status = FFI_Yajl.yajl_gen_string(yajl_gen, str, str.bytesize) ) != 0
+ FFI_Yajl::Encoder.raise_error_for_status(status)
+ end
+ end
+end
+
+class Time
+ def ffi_yajl(yajl_gen, state)
+ str = self.to_s
+ if ( status = FFI_Yajl.yajl_gen_string(yajl_gen, str, str.bytesize) ) != 0
+ FFI_Yajl::Encoder.raise_error_for_status(status)
+ end
+ end
+end
+
+class DateTime
+ def ffi_yajl(yajl_gen, state)
+ str = self.to_s
+ if ( status = FFI_Yajl.yajl_gen_string(yajl_gen, str, str.bytesize) ) != 0
+ FFI_Yajl::Encoder.raise_error_for_status(status)
+ end
+ end
+end
+
# I feel dirty
class Object
def ffi_yajl(yajl_gen, state)
@@ -180,4 +207,3 @@ class Object
end
end
end
-