summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2013-11-18 20:19:51 -0800
committerLamont Granquist <lamont@scriptkiddie.org>2013-11-18 20:19:51 -0800
commit47905bd4cef721bf5de4e3fc4e9411665414d4ff (patch)
tree8dceb28df551de1d7fe9c8ff1d9c62cf948d0f5e /lib
parentc9673929b4ea808d690d649fe3145c4dd0bb90ee (diff)
downloadffi-yajl-47905bd4cef721bf5de4e3fc4e9411665414d4ff.tar.gz
somewhat working ext code
Diffstat (limited to 'lib')
-rw-r--r--lib/ffi_yajl.rb34
-rw-r--r--lib/ffi_yajl/ffi/encoder.rb18
2 files changed, 24 insertions, 28 deletions
diff --git a/lib/ffi_yajl.rb b/lib/ffi_yajl.rb
index ecd3592..9452bfb 100644
--- a/lib/ffi_yajl.rb
+++ b/lib/ffi_yajl.rb
@@ -1,19 +1,31 @@
require 'rubygems'
require 'ffi'
-begin
- require 'ffi_yajl/ext'
- puts "W00T! native extensions!"
- module FFI_Yajl
- class Encoder
- include FFI_Yajl::Ext::Encoder
+module FFI_Yajl
+ class Encoder
+ attr_accessor :opts
+
+ def self.encode(obj, *args)
+ new(*args).encode(obj)
end
- end
-rescue LoadError
- require 'ffi_yajl/ffi'
- module FFI_Yajl
- class Encoder
+
+ def initialize(opts = {})
+ @opts = opts
+ end
+
+ if defined?(Yajl)
+ puts "oh shit, yajl is loaded, don't cross the streams, going ffi.."
+ require 'ffi_yajl/ffi'
include FFI_Yajl::FFI::Encoder
+ else
+ begin
+ require 'ffi_yajl/ext'
+ puts "W00T! native extensions!"
+ include FFI_Yajl::Ext::Encoder
+ rescue LoadError
+ require 'ffi_yajl/ffi'
+ include FFI_Yajl::FFI::Encoder
+ end
end
end
end
diff --git a/lib/ffi_yajl/ffi/encoder.rb b/lib/ffi_yajl/ffi/encoder.rb
index 178d4db..17e8787 100644
--- a/lib/ffi_yajl/ffi/encoder.rb
+++ b/lib/ffi_yajl/ffi/encoder.rb
@@ -5,24 +5,8 @@ require 'ffi'
module FFI_Yajl
module FFI
module Encoder
- module ClassMethods
- def encode(obj, *args)
- new(*args).encode(obj)
- end
- end
-
- def self.included(base)
- base.extend ClassMethods
- end
-
- attr_accessor :opts
-
- def initialize(opts = {})
- @opts = opts
- end
-
def encode(obj)
- yajl_gen = FFI_Yajl.yajl_gen_alloc(nil, nil)
+ yajl_gen = FFI_Yajl.yajl_gen_alloc(nil);
# configure the yajl encoder
FFI_Yajl.yajl_gen_config(yajl_gen, :yajl_gen_beautify, :int, 1) if opts[:pretty]