From 18ac44d520d40ec8981b4266b8bb040607377f1e Mon Sep 17 00:00:00 2001 From: Lamont Granquist Date: Thu, 7 Aug 2014 14:24:20 -0500 Subject: fix for chef pretty printing issues --- lib/ffi_yajl/encoder.rb | 2 +- lib/ffi_yajl/ffi/encoder.rb | 2 +- lib/ffi_yajl/json_gem.rb | 18 ++++++++++-------- 3 files changed, 12 insertions(+), 10 deletions(-) (limited to 'lib') diff --git a/lib/ffi_yajl/encoder.rb b/lib/ffi_yajl/encoder.rb index 8b5bfcb..bd3ff31 100644 --- a/lib/ffi_yajl/encoder.rb +++ b/lib/ffi_yajl/encoder.rb @@ -18,7 +18,7 @@ module FFI_Yajl end # call either the ext or ffi hook - str = do_yajl_encode(obj, yajl_gen_opts) + str = do_yajl_encode(obj, yajl_gen_opts, opts) str.force_encoding('UTF-8') if defined? Encoding str end diff --git a/lib/ffi_yajl/ffi/encoder.rb b/lib/ffi_yajl/ffi/encoder.rb index bbeba27..8837e12 100644 --- a/lib/ffi_yajl/ffi/encoder.rb +++ b/lib/ffi_yajl/ffi/encoder.rb @@ -4,7 +4,7 @@ require 'ffi_yajl/ffi' module FFI_Yajl module FFI module Encoder - def do_yajl_encode(obj, yajl_gen_opts = {}) + def do_yajl_encode(obj, yajl_gen_opts = {}, opts) yajl_gen = FFI_Yajl.yajl_gen_alloc(nil); diff --git a/lib/ffi_yajl/json_gem.rb b/lib/ffi_yajl/json_gem.rb index 0e64d50..4773f7f 100644 --- a/lib/ffi_yajl/json_gem.rb +++ b/lib/ffi_yajl/json_gem.rb @@ -25,6 +25,8 @@ module JSON options_map = {} options_map[:pretty] = true options_map[:indent] = opts[:indent] if opts.has_key?(:indent) + require 'pp' + pp options_map FFI_Yajl::Encoder.encode(obj, options_map).chomp rescue FFI_Yajl::EncodeError => e raise JSON::GeneratorError, e.message @@ -55,49 +57,49 @@ end class Array def to_json(*opts, &block) - FFI_Yajl::Encoder.encode(self) + FFI_Yajl::Encoder.encode(self, *opts) end end class Hash def to_json(*opts, &block) - FFI_Yajl::Encoder.encode(self) + FFI_Yajl::Encoder.encode(self, *opts) end end class Fixnum def to_json(*opts, &block) - FFI_Yajl::Encoder.encode(self) + FFI_Yajl::Encoder.encode(self, *opts) end end class Float def to_json(*opts, &block) - FFI_Yajl::Encoder.encode(self) + FFI_Yajl::Encoder.encode(self, *opts) end end class String def to_json(*opts, &block) - FFI_Yajl::Encoder.encode(self) + FFI_Yajl::Encoder.encode(self, *opts) end end class TrueClass def to_json(*opts, &block) - FFI_Yajl::Encoder.encode(self) + FFI_Yajl::Encoder.encode(self, *opts) end end class FalseClass def to_json(*opts, &block) - FFI_Yajl::Encoder.encode(self) + FFI_Yajl::Encoder.encode(self, *opts) end end class NilClass def to_json(*opts, &block) - FFI_Yajl::Encoder.encode(self) + FFI_Yajl::Encoder.encode(self, *opts) end end -- cgit v1.2.1