summaryrefslogtreecommitdiff
path: root/lib/ffi_yajl
diff options
context:
space:
mode:
Diffstat (limited to 'lib/ffi_yajl')
-rw-r--r--lib/ffi_yajl/benchmark.rb10
-rw-r--r--lib/ffi_yajl/benchmark/encode.rb16
-rw-r--r--lib/ffi_yajl/benchmark/encode_json_and_marshal.rb18
-rw-r--r--lib/ffi_yajl/benchmark/encode_json_and_yaml.rb22
-rw-r--r--lib/ffi_yajl/benchmark/encode_profile.rb10
-rw-r--r--lib/ffi_yajl/benchmark/http.rb24
-rw-r--r--lib/ffi_yajl/benchmark/parse.rb20
-rw-r--r--lib/ffi_yajl/benchmark/parse_json_and_marshal.rb22
-rw-r--r--lib/ffi_yajl/benchmark/parse_json_and_yaml.rb24
-rw-r--r--lib/ffi_yajl/benchmark/parse_profile.rb10
-rw-r--r--lib/ffi_yajl/benchmark/parse_profile_ruby_prof.rb8
-rw-r--r--lib/ffi_yajl/benchmark/parse_stream.rb20
-rw-r--r--lib/ffi_yajl/ext.rb18
-rw-r--r--lib/ffi_yajl/ffi.rb40
-rw-r--r--lib/ffi_yajl/ffi/encoder.rb78
-rw-r--r--lib/ffi_yajl/ffi/parser.rb36
-rw-r--r--lib/ffi_yajl/map_library_name.rb16
17 files changed, 196 insertions, 196 deletions
diff --git a/lib/ffi_yajl/benchmark.rb b/lib/ffi_yajl/benchmark.rb
index e8944ca..1372133 100644
--- a/lib/ffi_yajl/benchmark.rb
+++ b/lib/ffi_yajl/benchmark.rb
@@ -20,8 +20,8 @@
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-require 'ffi_yajl/benchmark/encode.rb'
-require 'ffi_yajl/benchmark/encode_profile.rb'
-require 'ffi_yajl/benchmark/parse.rb'
-require 'ffi_yajl/benchmark/parse_profile.rb'
-require 'ffi_yajl/benchmark/parse_profile_ruby_prof.rb'
+require "ffi_yajl/benchmark/encode.rb"
+require "ffi_yajl/benchmark/encode_profile.rb"
+require "ffi_yajl/benchmark/parse.rb"
+require "ffi_yajl/benchmark/parse_profile.rb"
+require "ffi_yajl/benchmark/parse_profile_ruby_prof.rb"
diff --git a/lib/ffi_yajl/benchmark/encode.rb b/lib/ffi_yajl/benchmark/encode.rb
index fc03c06..17e12cc 100644
--- a/lib/ffi_yajl/benchmark/encode.rb
+++ b/lib/ffi_yajl/benchmark/encode.rb
@@ -1,26 +1,26 @@
# Portions Originally Copyright (c) 2008-2011 Brian Lopez - http://github.com/brianmario
# See MIT-LICENSE
-require 'rubygems'
-require 'benchmark'
-require 'stringio'
+require "rubygems"
+require "benchmark"
+require "stringio"
if !defined?(RUBY_ENGINE) || RUBY_ENGINE !~ /jruby/
begin
- require 'yajl'
+ require "yajl"
rescue LoadError
puts "INFO: yajl-ruby not installed"
end
else
puts "INFO: skipping yajl-ruby on jruby"
end
-require 'ffi_yajl'
+require "ffi_yajl"
begin
- require 'json'
+ require "json"
rescue LoadError
puts "INFO: json gem not installed"
end
begin
- require 'oj'
+ require "oj"
rescue LoadError
puts "INFO: oj gem not installed"
end
@@ -31,7 +31,7 @@ module FFI_Yajl
def run
# filename = ARGV[0] || 'benchmark/subjects/ohai.json'
filename = File.expand_path(File.join(File.dirname(__FILE__), "subjects", "ohai.json"))
- hash = File.open(filename, 'rb') { |f| FFI_Yajl::Parser.parse(f.read) }
+ hash = File.open(filename, "rb") { |f| FFI_Yajl::Parser.parse(f.read) }
times = ARGV[1] ? ARGV[1].to_i : 1000
puts "Starting benchmark encoding #{filename} #{times} times\n\n"
diff --git a/lib/ffi_yajl/benchmark/encode_json_and_marshal.rb b/lib/ffi_yajl/benchmark/encode_json_and_marshal.rb
index e9d19bc..4269056 100644
--- a/lib/ffi_yajl/benchmark/encode_json_and_marshal.rb
+++ b/lib/ffi_yajl/benchmark/encode_json_and_marshal.rb
@@ -1,18 +1,18 @@
-$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/..')
-$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')
+$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + "/..")
+$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + "/../lib")
-require 'rubygems'
-require 'benchmark'
-require 'yajl'
-require 'stringio'
+require "rubygems"
+require "benchmark"
+require "yajl"
+require "stringio"
begin
- require 'json'
+ require "json"
rescue LoadError
end
times = ARGV[0] ? ARGV[0].to_i : 1000
-filename = 'benchmark/subjects/ohai.json'
-json = File.new(filename, 'r')
+filename = "benchmark/subjects/ohai.json"
+json = File.new(filename, "r")
hash = Yajl::Parser.new.parse(json)
json.close
diff --git a/lib/ffi_yajl/benchmark/encode_json_and_yaml.rb b/lib/ffi_yajl/benchmark/encode_json_and_yaml.rb
index 33dbbb2..72310c1 100644
--- a/lib/ffi_yajl/benchmark/encode_json_and_yaml.rb
+++ b/lib/ffi_yajl/benchmark/encode_json_and_yaml.rb
@@ -1,18 +1,18 @@
-$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/..')
-$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')
+$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + "/..")
+$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + "/../lib")
-require 'rubygems'
-require 'benchmark'
-require 'yajl'
+require "rubygems"
+require "benchmark"
+require "yajl"
begin
- require 'json'
+ require "json"
rescue LoadError
end
-require 'yaml'
+require "yaml"
# JSON Section
-filename = 'benchmark/subjects/ohai.json'
-json = File.new(filename, 'r')
+filename = "benchmark/subjects/ohai.json"
+json = File.new(filename, "r")
hash = Yajl::Parser.new.parse(json)
json.close
@@ -33,8 +33,8 @@ Benchmark.bmbm do |x|
end
# YAML Section
-filename = 'benchmark/subjects/ohai.yml'
-yml = File.new(filename, 'r')
+filename = "benchmark/subjects/ohai.yml"
+yml = File.new(filename, "r")
data = YAML.load_stream(yml)
yml.close
diff --git a/lib/ffi_yajl/benchmark/encode_profile.rb b/lib/ffi_yajl/benchmark/encode_profile.rb
index 36b92c7..468f88b 100644
--- a/lib/ffi_yajl/benchmark/encode_profile.rb
+++ b/lib/ffi_yajl/benchmark/encode_profile.rb
@@ -1,15 +1,15 @@
# Portions Originally Copyright (c) 2008-2011 Brian Lopez - http://github.com/brianmario
# See MIT-LICENSE
-require 'rubygems'
-require 'ffi_yajl'
+require "rubygems"
+require "ffi_yajl"
begin
- require 'perftools'
+ require "perftools"
rescue LoadError
puts "INFO: perftools.rb gem not installed"
end
-ENV['CPUPROFILE_FREQUENCY'] = "4000"
+ENV["CPUPROFILE_FREQUENCY"] = "4000"
module FFI_Yajl
class Benchmark
@@ -18,7 +18,7 @@ module FFI_Yajl
return unless defined?(PerfTools)
filename = File.expand_path(File.join(File.dirname(__FILE__), "subjects", "ohai.json"))
- hash = File.open(filename, 'rb') { |f| FFI_Yajl::Parser.parse(f.read) }
+ hash = File.open(filename, "rb") { |f| FFI_Yajl::Parser.parse(f.read) }
times = 1000
puts "Starting profiling encoding #{filename} #{times} times\n\n"
diff --git a/lib/ffi_yajl/benchmark/http.rb b/lib/ffi_yajl/benchmark/http.rb
index b94a46c..0b19387 100644
--- a/lib/ffi_yajl/benchmark/http.rb
+++ b/lib/ffi_yajl/benchmark/http.rb
@@ -1,17 +1,17 @@
-$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/..')
-$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')
+$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + "/..")
+$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + "/../lib")
-require 'rubygems'
-require 'benchmark'
-require 'yajl/http_stream'
-require 'yajl/gzip'
-require 'yajl/deflate'
-require 'yajl/bzip2' unless defined?(Bzip2)
-require 'json'
-require 'uri'
-require 'net/http'
+require "rubygems"
+require "benchmark"
+require "yajl/http_stream"
+require "yajl/gzip"
+require "yajl/deflate"
+require "yajl/bzip2" unless defined?(Bzip2)
+require "json"
+require "uri"
+require "net/http"
-uri = URI.parse('http://search.twitter.com/search.json?q=github')
+uri = URI.parse("http://search.twitter.com/search.json?q=github")
# uri = URI.parse('http://localhost/yajl-ruby.git/benchmark/subjects/contacts.json')
times = ARGV[0] ? ARGV[0].to_i : 1
diff --git a/lib/ffi_yajl/benchmark/parse.rb b/lib/ffi_yajl/benchmark/parse.rb
index 6aacc94..f7ab8b1 100644
--- a/lib/ffi_yajl/benchmark/parse.rb
+++ b/lib/ffi_yajl/benchmark/parse.rb
@@ -1,10 +1,10 @@
-require 'rubygems'
-require 'benchmark'
-require 'yajl'
-require 'ffi_yajl'
+require "rubygems"
+require "benchmark"
+require "yajl"
+require "ffi_yajl"
if !defined?(RUBY_ENGINE) || RUBY_ENGINE !~ /jruby/
begin
- require 'yajl'
+ require "yajl"
rescue LoadError
puts "INFO: yajl-ruby not installed"
end
@@ -12,11 +12,11 @@ else
puts "INFO: skipping yajl-ruby on jruby"
end
begin
- require 'json'
+ require "json"
rescue LoadError
end
begin
- require 'oj'
+ require "oj"
rescue LoadError
end
@@ -25,7 +25,7 @@ module FFI_Yajl
class Parse
def run
filename = File.expand_path(File.join(File.dirname(__FILE__), "subjects", "item.json"))
- json = File.new(filename, 'r')
+ json = File.new(filename, "r")
json_str = json.read
times = ARGV[1] ? ARGV[1].to_i : 10_000
@@ -49,7 +49,7 @@ module FFI_Yajl
times.times { Yajl::Parser.parse(json_str) }
end
io_parser = Yajl::Parser.new
- io_parser.on_parse_complete = ->(obj) {} if times > 1
+ io_parser.on_parse_complete = ->(_obj) {} if times > 1
x.report do
puts "Yajl::Parser#parse (from an IO)"
times.times do
@@ -58,7 +58,7 @@ module FFI_Yajl
end
end
string_parser = Yajl::Parser.new
- string_parser.on_parse_complete = ->(obj) {} if times > 1
+ string_parser.on_parse_complete = ->(_obj) {} if times > 1
x.report do
puts "Yajl::Parser#parse (from a String)"
times.times do
diff --git a/lib/ffi_yajl/benchmark/parse_json_and_marshal.rb b/lib/ffi_yajl/benchmark/parse_json_and_marshal.rb
index cd07d46..194c18b 100644
--- a/lib/ffi_yajl/benchmark/parse_json_and_marshal.rb
+++ b/lib/ffi_yajl/benchmark/parse_json_and_marshal.rb
@@ -1,19 +1,19 @@
-$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/..')
-$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')
+$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + "/..")
+$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + "/../lib")
-require 'rubygems'
-require 'benchmark'
-require 'yajl'
+require "rubygems"
+require "benchmark"
+require "yajl"
begin
- require 'json'
+ require "json"
rescue LoadError
end
# JSON section
-filename = 'benchmark/subjects/ohai.json'
-marshal_filename = 'benchmark/subjects/ohai.marshal_dump'
-json = File.new(filename, 'r')
-marshal_file = File.new(marshal_filename, 'r')
+filename = "benchmark/subjects/ohai.json"
+marshal_filename = "benchmark/subjects/ohai.marshal_dump"
+json = File.new(filename, "r")
+marshal_file = File.new(marshal_filename, "r")
hash = {}
@@ -23,7 +23,7 @@ Benchmark.bmbm do |x|
x.report do
puts "Yajl::Parser#parse"
yajl = Yajl::Parser.new
- yajl.on_parse_complete = ->(obj) {} if times > 1
+ yajl.on_parse_complete = ->(_obj) {} if times > 1
times.times do
json.rewind
hash = yajl.parse(json)
diff --git a/lib/ffi_yajl/benchmark/parse_json_and_yaml.rb b/lib/ffi_yajl/benchmark/parse_json_and_yaml.rb
index 6e479ce..d73d0bd 100644
--- a/lib/ffi_yajl/benchmark/parse_json_and_yaml.rb
+++ b/lib/ffi_yajl/benchmark/parse_json_and_yaml.rb
@@ -1,24 +1,24 @@
-$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/..')
-$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')
+$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + "/..")
+$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + "/../lib")
-require 'rubygems'
-require 'benchmark'
-require 'yajl'
+require "rubygems"
+require "benchmark"
+require "yajl"
begin
- require 'json'
+ require "json"
rescue LoadError
end
-require 'yaml'
+require "yaml"
# JSON section
-filename = 'benchmark/subjects/ohai.json'
-json = File.new(filename, 'r')
+filename = "benchmark/subjects/ohai.json"
+json = File.new(filename, "r")
times = ARGV[0] ? ARGV[0].to_i : 1000
puts "Starting benchmark parsing #{File.size(filename)} bytes of JSON data #{times} times\n\n"
Benchmark.bmbm do |x|
parser = Yajl::Parser.new
- parser.on_parse_complete = ->(obj) {} if times > 1
+ parser.on_parse_complete = ->(_obj) {} if times > 1
x.report do
puts "Yajl::Parser#parse"
times.times do
@@ -39,8 +39,8 @@ end
json.close
# YAML section
-filename = 'benchmark/subjects/ohai.yml'
-yaml = File.new(filename, 'r')
+filename = "benchmark/subjects/ohai.yml"
+yaml = File.new(filename, "r")
puts "Starting benchmark parsing #{File.size(filename)} bytes of YAML data #{times} times\n\n"
Benchmark.bmbm do |x|
diff --git a/lib/ffi_yajl/benchmark/parse_profile.rb b/lib/ffi_yajl/benchmark/parse_profile.rb
index 6ef00ac..4b396b4 100644
--- a/lib/ffi_yajl/benchmark/parse_profile.rb
+++ b/lib/ffi_yajl/benchmark/parse_profile.rb
@@ -1,15 +1,15 @@
# Portions Originally Copyright (c) 2008-2011 Brian Lopez - http://github.com/brianmario
# See MIT-LICENSE
-require 'rubygems'
-require 'ffi_yajl'
+require "rubygems"
+require "ffi_yajl"
begin
- require 'perftools'
+ require "perftools"
rescue LoadError
puts "INFO: perftools.rb gem not installed"
end
-ENV['CPUPROFILE_FREQUENCY'] = "4000"
+ENV["CPUPROFILE_FREQUENCY"] = "4000"
module FFI_Yajl
class Benchmark
@@ -18,7 +18,7 @@ module FFI_Yajl
return if defined?(PerfTools)
filename = File.expand_path(File.join(File.dirname(__FILE__), "subjects", "ohai.json"))
- json = File.new(filename, 'r').read
+ json = File.new(filename, "r").read
times = 1000
puts "Starting profiling encoding #{filename} #{times} times\n\n"
diff --git a/lib/ffi_yajl/benchmark/parse_profile_ruby_prof.rb b/lib/ffi_yajl/benchmark/parse_profile_ruby_prof.rb
index 51696c5..2c4021a 100644
--- a/lib/ffi_yajl/benchmark/parse_profile_ruby_prof.rb
+++ b/lib/ffi_yajl/benchmark/parse_profile_ruby_prof.rb
@@ -1,15 +1,15 @@
# Portions Originally Copyright (c) 2008-2011 Brian Lopez - http://github.com/brianmario
# See MIT-LICENSE
-require 'rubygems'
-require 'ffi_yajl'
+require "rubygems"
+require "ffi_yajl"
module FFI_Yajl
class Benchmark
class ParseProfileRubyProf
def run
begin
- require 'ruby-prof'
+ require "ruby-prof"
rescue LoadError
puts "INFO: perftools.rb gem not installed"
end
@@ -17,7 +17,7 @@ module FFI_Yajl
return if defined?(RubyProf)
filename = File.expand_path(File.join(File.dirname(__FILE__), "subjects", "ohai.json"))
- json = File.new(filename, 'r').read
+ json = File.new(filename, "r").read
times = 1000
puts "Starting profiling encoding #{filename} #{times} times\n\n"
diff --git a/lib/ffi_yajl/benchmark/parse_stream.rb b/lib/ffi_yajl/benchmark/parse_stream.rb
index 679eb92..d689a3d 100644
--- a/lib/ffi_yajl/benchmark/parse_stream.rb
+++ b/lib/ffi_yajl/benchmark/parse_stream.rb
@@ -1,26 +1,26 @@
-$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/..')
-$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')
+$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + "/..")
+$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + "/../lib")
-require 'rubygems'
-require 'benchmark'
-require 'yajl'
+require "rubygems"
+require "benchmark"
+require "yajl"
begin
- require 'json'
+ require "json"
rescue LoadError
end
begin
- require 'active_support'
+ require "active_support"
rescue LoadError
end
-filename = 'benchmark/subjects/twitter_stream.json'
-json = File.new(filename, 'r')
+filename = "benchmark/subjects/twitter_stream.json"
+json = File.new(filename, "r")
times = ARGV[0] ? ARGV[0].to_i : 100
puts "Starting benchmark parsing JSON stream (#{File.size(filename)} bytes of JSON data with 430 JSON separate strings) #{times} times\n\n"
Benchmark.bmbm do |x|
parser = Yajl::Parser.new
- parser.on_parse_complete = ->(obj) {}
+ parser.on_parse_complete = ->(_obj) {}
x.report do
puts "Yajl::Parser#parse"
times.times do
diff --git a/lib/ffi_yajl/ext.rb b/lib/ffi_yajl/ext.rb
index ed17e59..f7bbcfd 100644
--- a/lib/ffi_yajl/ext.rb
+++ b/lib/ffi_yajl/ext.rb
@@ -20,16 +20,16 @@
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-require 'rubygems'
+require "rubygems"
-require 'ffi_yajl/encoder'
-require 'ffi_yajl/parser'
-require 'ffi_yajl/ext/dlopen'
-require 'ffi_yajl/map_library_name'
+require "ffi_yajl/encoder"
+require "ffi_yajl/parser"
+require "ffi_yajl/ext/dlopen"
+require "ffi_yajl/map_library_name"
# needed so the encoder c-code can find these symbols
-require 'stringio'
-require 'date'
+require "stringio"
+require "date"
module FFI_Yajl
extend FFI_Yajl::MapLibraryName
@@ -38,12 +38,12 @@ module FFI_Yajl
dlopen_yajl_library
class Parser
- require 'ffi_yajl/ext/parser'
+ require "ffi_yajl/ext/parser"
include FFI_Yajl::Ext::Parser
end
class Encoder
- require 'ffi_yajl/ext/encoder'
+ require "ffi_yajl/ext/encoder"
include FFI_Yajl::Ext::Encoder
end
end
diff --git a/lib/ffi_yajl/ffi.rb b/lib/ffi_yajl/ffi.rb
index 3b83bae..fc6f99f 100644
--- a/lib/ffi_yajl/ffi.rb
+++ b/lib/ffi_yajl/ffi.rb
@@ -20,18 +20,18 @@
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-require 'rubygems'
+require "rubygems"
-require 'libyajl2'
+require "libyajl2"
begin
- require 'ffi'
+ require "ffi"
rescue LoadError
$stderr.puts "FATAL: to use the ffi extension instead of the compiled C extension, the ffi gem must be installed"
$stderr.puts " (it is optional, so you must include it in your bundle manually)"
exit 1
end
-require 'ffi_yajl/map_library_name'
+require "ffi_yajl/map_library_name"
module FFI_Yajl
extend ::FFI::Library
@@ -42,23 +42,23 @@ module FFI_Yajl
class YajlCallbacks < ::FFI::Struct
layout :yajl_null, :pointer,
- :yajl_boolean, :pointer,
- :yajl_integer, :pointer,
- :yajl_double, :pointer,
- :yajl_number, :pointer,
- :yajl_string, :pointer,
- :yajl_start_map, :pointer,
- :yajl_map_key, :pointer,
- :yajl_end_map, :pointer,
- :yajl_start_array, :pointer,
- :yajl_end_array, :pointer
+ :yajl_boolean, :pointer,
+ :yajl_integer, :pointer,
+ :yajl_double, :pointer,
+ :yajl_number, :pointer,
+ :yajl_string, :pointer,
+ :yajl_start_map, :pointer,
+ :yajl_map_key, :pointer,
+ :yajl_end_map, :pointer,
+ :yajl_start_array, :pointer,
+ :yajl_end_array, :pointer
end
enum :yajl_status, [
:yajl_status_ok,
:yajl_status_client_canceled,
:yajl_status_insufficient_data,
- :yajl_status_error,
+ :yajl_status_error
]
# FFI::Enums are slow, should remove the rest
@@ -95,7 +95,7 @@ module FFI_Yajl
typedef :string, :ustring
# const char *yajl_status_to_string (yajl_status code)
- attach_function :yajl_status_to_string, [ :yajl_status ], :string
+ attach_function :yajl_status_to_string, [:yajl_status], :string
# yajl_handle yajl_alloc(const yajl_callbacks * callbacks, yajl_alloc_funcs * afs, void * ctx)
attach_function :yajl_alloc, [:pointer, :pointer, :pointer], :yajl_handle
# void yajl_free (yajl_handle handle)
@@ -137,17 +137,17 @@ module FFI_Yajl
attach_function :yajl_gen_clear, [:yajl_gen], :void
end
-require 'ffi_yajl/encoder'
-require 'ffi_yajl/parser'
+require "ffi_yajl/encoder"
+require "ffi_yajl/parser"
module FFI_Yajl
class Parser
- require 'ffi_yajl/ffi/parser'
+ require "ffi_yajl/ffi/parser"
include FFI_Yajl::FFI::Parser
end
class Encoder
- require 'ffi_yajl/ffi/encoder'
+ require "ffi_yajl/ffi/encoder"
include FFI_Yajl::FFI::Encoder
end
end
diff --git a/lib/ffi_yajl/ffi/encoder.rb b/lib/ffi_yajl/ffi/encoder.rb
index 304c85f..a46cb96 100644
--- a/lib/ffi_yajl/ffi/encoder.rb
+++ b/lib/ffi_yajl/ffi/encoder.rb
@@ -20,8 +20,8 @@
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-require 'date'
-require 'stringio'
+require "date"
+require "stringio"
module FFI_Yajl
module FFI
@@ -42,7 +42,7 @@ module FFI_Yajl
# setup our own state
state = {
json_opts: opts,
- processing_key: false,
+ processing_key: false
}
# do the encoding
@@ -51,7 +51,7 @@ module FFI_Yajl
# get back our encoded JSON
string_ptr = ::FFI::MemoryPointer.new(:string)
length_ptr = ::FFI::MemoryPointer.new(:int)
- if ( status = FFI_Yajl.yajl_gen_get_buf(yajl_gen, string_ptr, length_ptr) ) != 0
+ if (status = FFI_Yajl.yajl_gen_get_buf(yajl_gen, string_ptr, length_ptr)) != 0
FFI_Yajl::Encoder.raise_error_for_status(status)
end
string = string_ptr.get_pointer(0).read_string
@@ -68,12 +68,12 @@ class Hash
def ffi_yajl(yajl_gen, state)
if state[:processing_key]
str = to_s
- if ( status = FFI_Yajl.yajl_gen_string(yajl_gen, str, str.bytesize) ) != 0
+ if (status = FFI_Yajl.yajl_gen_string(yajl_gen, str, str.bytesize)) != 0
FFI_Yajl::Encoder.raise_error_for_status(status, str)
end
else
- if ( status = FFI_Yajl.yajl_gen_map_open(yajl_gen) ) != 0
- FFI_Yajl::Encoder.raise_error_for_status(status, '{')
+ if (status = FFI_Yajl.yajl_gen_map_open(yajl_gen)) != 0
+ FFI_Yajl::Encoder.raise_error_for_status(status, "{")
end
each do |key, value|
# Perf Fix: mutate state hash rather than creating new copy
@@ -82,8 +82,8 @@ class Hash
state[:processing_key] = false
value.ffi_yajl(yajl_gen, state)
end
- if ( status = FFI_Yajl.yajl_gen_map_close(yajl_gen) ) != 0
- FFI_Yajl::Encoder.raise_error_for_status(status, '}')
+ if (status = FFI_Yajl.yajl_gen_map_close(yajl_gen)) != 0
+ FFI_Yajl::Encoder.raise_error_for_status(status, "}")
end
end
end
@@ -93,18 +93,18 @@ class Array
def ffi_yajl(yajl_gen, state)
if state[:processing_key]
str = to_s
- if ( status = FFI_Yajl.yajl_gen_string(yajl_gen, str, str.bytesize) ) != 0
+ if (status = FFI_Yajl.yajl_gen_string(yajl_gen, str, str.bytesize)) != 0
FFI_Yajl::Encoder.raise_error_for_status(status, str)
end
else
- if ( status = FFI_Yajl.yajl_gen_array_open(yajl_gen) ) != 0
- FFI_Yajl::Encoder.raise_error_for_status(status, '[')
+ if (status = FFI_Yajl.yajl_gen_array_open(yajl_gen)) != 0
+ FFI_Yajl::Encoder.raise_error_for_status(status, "[")
end
each do |value|
value.ffi_yajl(yajl_gen, state)
end
- if ( status = FFI_Yajl.yajl_gen_array_close(yajl_gen) ) != 0
- FFI_Yajl::Encoder.raise_error_for_status(status, ']')
+ if (status = FFI_Yajl.yajl_gen_array_close(yajl_gen)) != 0
+ FFI_Yajl::Encoder.raise_error_for_status(status, "]")
end
end
end
@@ -114,11 +114,11 @@ class NilClass
def ffi_yajl(yajl_gen, state)
str = to_s
if state[:processing_key]
- if ( status = FFI_Yajl.yajl_gen_string(yajl_gen, str, str.bytesize) ) != 0
+ if (status = FFI_Yajl.yajl_gen_string(yajl_gen, str, str.bytesize)) != 0
FFI_Yajl::Encoder.raise_error_for_status(status, str)
end
else
- if ( status = FFI_Yajl.yajl_gen_null(yajl_gen) ) != 0
+ if (status = FFI_Yajl.yajl_gen_null(yajl_gen)) != 0
FFI_Yajl::Encoder.raise_error_for_status(status, str)
end
end
@@ -129,11 +129,11 @@ class TrueClass
def ffi_yajl(yajl_gen, state)
str = to_s
if state[:processing_key]
- if ( status = FFI_Yajl.yajl_gen_string(yajl_gen, str, str.bytesize) ) != 0
+ if (status = FFI_Yajl.yajl_gen_string(yajl_gen, str, str.bytesize)) != 0
FFI_Yajl::Encoder.raise_error_for_status(status, str)
end
else
- if ( status = FFI_Yajl.yajl_gen_bool(yajl_gen, 1) ) != 0
+ if (status = FFI_Yajl.yajl_gen_bool(yajl_gen, 1)) != 0
FFI_Yajl::Encoder.raise_error_for_status(status, str)
end
end
@@ -144,11 +144,11 @@ class FalseClass
def ffi_yajl(yajl_gen, state)
str = to_s
if state[:processing_key]
- if ( status = FFI_Yajl.yajl_gen_string(yajl_gen, str, str.bytesize) ) != 0
+ if (status = FFI_Yajl.yajl_gen_string(yajl_gen, str, str.bytesize)) != 0
FFI_Yajl::Encoder.raise_error_for_status(status, str)
end
else
- if ( status = FFI_Yajl.yajl_gen_bool(yajl_gen, 0) ) != 0
+ if (status = FFI_Yajl.yajl_gen_bool(yajl_gen, 0)) != 0
FFI_Yajl::Encoder.raise_error_for_status(status, str)
end
end
@@ -162,11 +162,11 @@ class Fixnum
raise ::FFI_Yajl::EncodeError, "'#{str}' is an invalid number"
end
if state[:processing_key]
- if ( status = FFI_Yajl.yajl_gen_string(yajl_gen, str, str.bytesize) ) != 0
+ if (status = FFI_Yajl.yajl_gen_string(yajl_gen, str, str.bytesize)) != 0
FFI_Yajl::Encoder.raise_error_for_status(status, str)
end
else
- if ( status = FFI_Yajl.yajl_gen_integer(yajl_gen, self) ) != 0
+ if (status = FFI_Yajl.yajl_gen_integer(yajl_gen, self)) != 0
FFI_Yajl::Encoder.raise_error_for_status(status, str)
end
end
@@ -180,11 +180,11 @@ class Bignum
raise ::FFI_Yajl::EncodeError, "'#{str}' is an invalid number"
end
if state[:processing_key]
- if ( status = FFI_Yajl.yajl_gen_string(yajl_gen, str, str.bytesize) ) != 0
+ if (status = FFI_Yajl.yajl_gen_string(yajl_gen, str, str.bytesize)) != 0
FFI_Yajl::Encoder.raise_error_for_status(status, str)
end
else
- if ( status = FFI_Yajl.yajl_gen_number(yajl_gen, str, str.bytesize) ) != 0
+ if (status = FFI_Yajl.yajl_gen_number(yajl_gen, str, str.bytesize)) != 0
FFI_Yajl::Encoder.raise_error_for_status(status, str)
end
end
@@ -198,11 +198,11 @@ class Float
raise ::FFI_Yajl::EncodeError, "'#{str}' is an invalid number"
end
if state[:processing_key]
- if ( status = FFI_Yajl.yajl_gen_string(yajl_gen, str, str.bytesize) ) != 0
+ if (status = FFI_Yajl.yajl_gen_string(yajl_gen, str, str.bytesize)) != 0
FFI_Yajl::Encoder.raise_error_for_status(status, str)
end
else
- if ( status = FFI_Yajl.yajl_gen_number(yajl_gen, str, str.bytesize) ) != 0
+ if (status = FFI_Yajl.yajl_gen_number(yajl_gen, str, str.bytesize)) != 0
FFI_Yajl::Encoder.raise_error_for_status(status, str)
end
end
@@ -210,53 +210,53 @@ class Float
end
class Symbol
- def ffi_yajl(yajl_gen, state)
+ def ffi_yajl(yajl_gen, _state)
str = to_s
- if ( status = FFI_Yajl.yajl_gen_string(yajl_gen, str, str.bytesize) ) != 0
+ if (status = FFI_Yajl.yajl_gen_string(yajl_gen, str, str.bytesize)) != 0
FFI_Yajl::Encoder.raise_error_for_status(status, str)
end
end
end
class String
- def ffi_yajl(yajl_gen, state)
- if ( status = FFI_Yajl.yajl_gen_string(yajl_gen, self, bytesize) ) != 0
+ def ffi_yajl(yajl_gen, _state)
+ if (status = FFI_Yajl.yajl_gen_string(yajl_gen, self, bytesize)) != 0
FFI_Yajl::Encoder.raise_error_for_status(status, self)
end
end
end
class StringIO
- def ffi_yajl(yajl_gen, state)
+ def ffi_yajl(yajl_gen, _state)
str = read
- if ( status = FFI_Yajl.yajl_gen_string(yajl_gen, str, str.bytesize) ) != 0
+ if (status = FFI_Yajl.yajl_gen_string(yajl_gen, str, str.bytesize)) != 0
FFI_Yajl::Encoder.raise_error_for_status(status, str)
end
end
end
class Date
- def ffi_yajl(yajl_gen, state)
+ def ffi_yajl(yajl_gen, _state)
str = to_s
- if ( status = FFI_Yajl.yajl_gen_string(yajl_gen, str, str.bytesize) ) != 0
+ if (status = FFI_Yajl.yajl_gen_string(yajl_gen, str, str.bytesize)) != 0
FFI_Yajl::Encoder.raise_error_for_status(status, str)
end
end
end
class Time
- def ffi_yajl(yajl_gen, state)
+ def ffi_yajl(yajl_gen, _state)
str = strftime "%Y-%m-%d %H:%M:%S %z"
- if ( status = FFI_Yajl.yajl_gen_string(yajl_gen, str, str.bytesize) ) != 0
+ if (status = FFI_Yajl.yajl_gen_string(yajl_gen, str, str.bytesize)) != 0
FFI_Yajl::Encoder.raise_error_for_status(status, str)
end
end
end
class DateTime
- def ffi_yajl(yajl_gen, state)
+ def ffi_yajl(yajl_gen, _state)
str = to_s
- if ( status = FFI_Yajl.yajl_gen_string(yajl_gen, str, str.bytesize) ) != 0
+ if (status = FFI_Yajl.yajl_gen_string(yajl_gen, str, str.bytesize)) != 0
FFI_Yajl::Encoder.raise_error_for_status(status, str)
end
end
@@ -273,6 +273,6 @@ class Object
str = to_s
status = FFI_Yajl.yajl_gen_string(yajl_gen, str, str.bytesize)
end
- FFI_Yajl::Encoder.raise_error_for_status(status, str) if ( status ) != 0
+ FFI_Yajl::Encoder.raise_error_for_status(status, str) if (status) != 0
end
end
diff --git a/lib/ffi_yajl/ffi/parser.rb b/lib/ffi_yajl/ffi/parser.rb
index 67df934..4f39179 100644
--- a/lib/ffi_yajl/ffi/parser.rb
+++ b/lib/ffi_yajl/ffi/parser.rb
@@ -39,7 +39,7 @@ module FFI_Yajl
end
def stack_pop
- set_value( stack.pop ) if stack.length > 1
+ set_value(stack.pop) if stack.length > 1
end
def key_push
@@ -51,58 +51,58 @@ module FFI_Yajl
end
def setup_callbacks
- @null_callback = ::FFI::Function.new(:int, [:pointer]) do |ctx|
+ @null_callback = ::FFI::Function.new(:int, [:pointer]) do |_ctx|
set_value(nil)
1
end
- @boolean_callback = ::FFI::Function.new(:int, [:pointer, :int]) do |ctx, boolval|
+ @boolean_callback = ::FFI::Function.new(:int, [:pointer, :int]) do |_ctx, boolval|
set_value(boolval == 1 ? true : false)
1
end
- @integer_callback = ::FFI::Function.new(:int, [:pointer, :long_long]) do |ctx, intval|
+ @integer_callback = ::FFI::Function.new(:int, [:pointer, :long_long]) do |_ctx, intval|
set_value(intval)
1
end
- @number_callback = ::FFI::Function.new(:int, [:pointer, :string, :size_t ]) do |ctx, stringval, stringlen|
+ @number_callback = ::FFI::Function.new(:int, [:pointer, :string, :size_t]) do |_ctx, stringval, stringlen|
s = stringval.slice(0, stringlen)
- s.force_encoding('UTF-8') if defined? Encoding
+ s.force_encoding("UTF-8") if defined? Encoding
# XXX: I can't think of a better way to do this right now. need to call to_f if and only if its a float.
- v = ( s =~ /[\.eE]/ ) ? s.to_f : s.to_i
+ v = (s =~ /[\.eE]/) ? s.to_f : s.to_i
set_value(v)
1
end
- @double_callback = ::FFI::Function.new(:int, [:pointer, :double]) do |ctx, doubleval|
+ @double_callback = ::FFI::Function.new(:int, [:pointer, :double]) do |_ctx, doubleval|
set_value(doubleval)
1
end
- @string_callback = ::FFI::Function.new(:int, [:pointer, :string, :size_t]) do |ctx, stringval, stringlen|
+ @string_callback = ::FFI::Function.new(:int, [:pointer, :string, :size_t]) do |_ctx, stringval, stringlen|
s = stringval.slice(0, stringlen)
- s.force_encoding('UTF-8') if defined? Encoding
+ s.force_encoding("UTF-8") if defined? Encoding
set_value(s)
1
end
- @start_map_callback = ::FFI::Function.new(:int, [:pointer]) do |ctx|
+ @start_map_callback = ::FFI::Function.new(:int, [:pointer]) do |_ctx|
key_push # for key => { } case, save the key
stack.push({})
1
end
- @map_key_callback = ::FFI::Function.new(:int, [:pointer, :string, :size_t]) do |ctx, key, keylen|
+ @map_key_callback = ::FFI::Function.new(:int, [:pointer, :string, :size_t]) do |_ctx, key, keylen|
s = key.slice(0, keylen)
- s.force_encoding('UTF-8') if defined? Encoding
+ s.force_encoding("UTF-8") if defined? Encoding
self.key = @opts[:symbolize_keys] ? s.to_sym : s
1
end
- @end_map_callback = ::FFI::Function.new(:int, [:pointer]) do |ctx|
+ @end_map_callback = ::FFI::Function.new(:int, [:pointer]) do |_ctx|
key_pop
stack_pop
1
end
- @start_array_callback = ::FFI::Function.new(:int, [:pointer]) do |ctx|
+ @start_array_callback = ::FFI::Function.new(:int, [:pointer]) do |_ctx|
key_push # for key => [ ] case, save the key
stack.push([])
1
end
- @end_array_callback = ::FFI::Function.new(:int, [:pointer]) do |ctx|
+ @end_array_callback = ::FFI::Function.new(:int, [:pointer]) do |_ctx|
key_pop
stack_pop
1
@@ -143,12 +143,12 @@ module FFI_Yajl
::FFI_Yajl.yajl_config(yajl_handle, :yajl_allow_partial_values, :int, 1)
end
- if ( ::FFI_Yajl.yajl_parse(yajl_handle, str, str.bytesize) != :yajl_status_ok )
+ if (::FFI_Yajl.yajl_parse(yajl_handle, str, str.bytesize) != :yajl_status_ok)
# FIXME: dup the error and call yajl_free_error?
error = ::FFI_Yajl.yajl_get_error(yajl_handle, 1, str, str.bytesize)
raise ::FFI_Yajl::ParseError, error
end
- if ( ::FFI_Yajl.yajl_complete_parse(yajl_handle) != :yajl_status_ok )
+ if (::FFI_Yajl.yajl_complete_parse(yajl_handle) != :yajl_status_ok)
# FIXME: dup the error and call yajl_free_error?
error = ::FFI_Yajl.yajl_get_error(yajl_handle, 1, str, str.bytesize)
raise ::FFI_Yajl::ParseError, error
diff --git a/lib/ffi_yajl/map_library_name.rb b/lib/ffi_yajl/map_library_name.rb
index 249116e..83d9e0e 100644
--- a/lib/ffi_yajl/map_library_name.rb
+++ b/lib/ffi_yajl/map_library_name.rb
@@ -20,7 +20,7 @@
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-require 'libyajl2'
+require "libyajl2"
# Mixin for use in finding the right yajl library on the system. The 'caller'
# needs to also mixin either the FFI module or the DLopen module. Those are
@@ -36,7 +36,7 @@ module FFI_Yajl
# @api private
# @return Array<String> lower case ruby host_os string
def host_os
- RbConfig::CONFIG['host_os'].downcase
+ RbConfig::CONFIG["host_os"].downcase
end
# Array of yajl library names on the platform. Some platforms like Windows
@@ -47,13 +47,13 @@ module FFI_Yajl
def library_names
case host_os
when /mingw|mswin/
- [ "libyajl.so", "yajl.dll" ]
+ ["libyajl.so", "yajl.dll"]
when /cygwin/
- [ "libyajl.so", "cygyajl.dll" ]
+ ["libyajl.so", "cygyajl.dll"]
when /darwin/
- [ "libyajl.bundle", "libyajl.dylib" ]
+ ["libyajl.bundle", "libyajl.dylib"]
else
- [ "libyajl.so" ]
+ ["libyajl.so"]
end
end
@@ -78,7 +78,7 @@ module FFI_Yajl
# @api private
def dlopen_yajl_library
found = false
- ( expanded_library_names + library_names ).each do |libname|
+ (expanded_library_names + library_names).each do |libname|
begin
dlopen(libname)
found = true
@@ -103,7 +103,7 @@ module FFI_Yajl
rescue LoadError
end
end
- ffi_lib 'yajl' unless found
+ ffi_lib "yajl" unless found
end
end
end