summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2015-07-09 08:39:40 -0700
committerLamont Granquist <lamont@scriptkiddie.org>2015-07-09 08:39:40 -0700
commit8fabdd3fddbd222109976fddb0d38255a9490f1d (patch)
tree05c37181d228a244809572d16e3f2dfe2733fd90
parent6d427a893b28ee71ddcdbb3a6cd64cd01c7a690f (diff)
downloadffi-yajl-8fabdd3fddbd222109976fddb0d38255a9490f1d.tar.gz
fix lots of cops
and add a few more to be ignored
-rw-r--r--.rubocop.yml14
-rw-r--r--Gemfile2
-rw-r--r--Rakefile3
-rwxr-xr-xbin/ffi-yajl-bench9
-rw-r--r--ext/ffi_yajl/ext/encoder/extconf.rb1
-rw-r--r--ext/ffi_yajl/ext/parser/extconf.rb1
-rw-r--r--lib/ffi_yajl/benchmark.rb1
-rw-r--r--lib/ffi_yajl/benchmark/encode.rb3
-rw-r--r--lib/ffi_yajl/benchmark/encode_profile.rb2
-rw-r--r--lib/ffi_yajl/benchmark/http.rb4
-rw-r--r--lib/ffi_yajl/benchmark/parse.rb6
-rw-r--r--lib/ffi_yajl/benchmark/parse_json_and_marshal.rb4
-rw-r--r--lib/ffi_yajl/benchmark/parse_json_and_yaml.rb4
-rw-r--r--lib/ffi_yajl/benchmark/parse_profile.rb2
-rw-r--r--lib/ffi_yajl/benchmark/parse_profile_ruby_prof.rb2
-rw-r--r--lib/ffi_yajl/benchmark/parse_stream.rb4
-rw-r--r--lib/ffi_yajl/ffi.rb27
-rw-r--r--lib/ffi_yajl/ffi/encoder.rb37
-rw-r--r--lib/ffi_yajl/ffi/parser.rb11
-rw-r--r--lib/ffi_yajl/map_library_name.rb1
-rw-r--r--lib/ffi_yajl/parser.rb2
-rw-r--r--spec/ffi_yajl/encoder_spec.rb41
-rw-r--r--spec/ffi_yajl/map_library_name_spec.rb2
-rw-r--r--spec/ffi_yajl/parser_spec.rb66
-rw-r--r--spec/spec_helper.rb3
25 files changed, 121 insertions, 131 deletions
diff --git a/.rubocop.yml b/.rubocop.yml
index 3d62982..47de329 100644
--- a/.rubocop.yml
+++ b/.rubocop.yml
@@ -1,9 +1,15 @@
+AbcSize:
+ Enabled: false
AndOr:
Enabled: false
+ClassAndModuleCamelCase:
+ Enabled: false
ClassLength:
Enabled: false
CommentAnnotation:
Enabled: false
+CyclomaticComplexity:
+ Enabled: false
Documentation:
Enabled: false
DoubleNegation:
@@ -20,6 +26,10 @@ LineLength:
Enabled: false
MethodLength:
Enabled: false
+ModuleLength:
+ Enabled: false
+PerceivedComplexity:
+ Enabled: false
PercentLiteralDelimiters:
Enabled: false
RegexpLiteral:
@@ -36,3 +46,7 @@ StringLiterals:
Enabled: false
TrailingComma:
EnforcedStyleForMultiline: comma
+UnusedMethodArgument:
+ Enabled: false
+UnusedBlockArgument:
+ Enabled: false
diff --git a/Gemfile b/Gemfile
index 34b35ca..3298262 100644
--- a/Gemfile
+++ b/Gemfile
@@ -12,7 +12,7 @@ group :development do
end
group :development_extras do
- gem 'rubocop', '= 0.21.0'
+ gem 'rubocop', '= 0.32.1'
gem 'reek', '= 1.3.7'
gem 'test-kitchen', '~> 1.2'
gem 'kitchen-digitalocean'
diff --git a/Rakefile b/Rakefile
index ae19344..0cb0ed5 100644
--- a/Rakefile
+++ b/Rakefile
@@ -1,4 +1,4 @@
-$: << File.expand_path(File.join(File.dirname( __FILE__ ), "lib"))
+$LOAD_PATH << File.expand_path(File.join(File.dirname( __FILE__ ), "lib"))
require 'rspec/core/rake_task'
require 'rubygems/package_task'
@@ -161,7 +161,6 @@ else
end
end
-
desc 'Run all style checks'
task :style => ['style:rubocop', 'style:reek']
diff --git a/bin/ffi-yajl-bench b/bin/ffi-yajl-bench
index 5b3bf85..ceff62b 100755
--- a/bin/ffi-yajl-bench
+++ b/bin/ffi-yajl-bench
@@ -1,7 +1,6 @@
#!/usr/bin/env ruby
-
-$: << File.expand_path(File.join(File.dirname( File.symlink?(__FILE__) ? File.readlink(__FILE__) : __FILE__ ), "../lib"))
+$LOAD_PATH << File.expand_path(File.join(File.dirname( File.symlink?(__FILE__) ? File.readlink(__FILE__) : __FILE__ ), "../lib"))
require 'optparse'
require 'ffi_yajl/benchmark'
@@ -30,8 +29,8 @@ ENV['FORCE_FFI_YAJL'] = 'ffi' if opts[:ffi]
ENV['FORCE_FFI_YAJL'] = 'ext' if opts[:ext]
if opts[:profile]
- FFI_Yajl::Benchmark::ParseProfileRubyProf.new().run()
+ FFI_Yajl::Benchmark::ParseProfileRubyProf.new.run
else
- FFI_Yajl::Benchmark::Parse.new().run()
- FFI_Yajl::Benchmark::Encode.new().run()
+ FFI_Yajl::Benchmark::Parse.new.run
+ FFI_Yajl::Benchmark::Encode.new.run
end
diff --git a/ext/ffi_yajl/ext/encoder/extconf.rb b/ext/ffi_yajl/ext/encoder/extconf.rb
index f7f0116..0281ea4 100644
--- a/ext/ffi_yajl/ext/encoder/extconf.rb
+++ b/ext/ffi_yajl/ext/encoder/extconf.rb
@@ -1,3 +1,4 @@
+# rubocop:disable Style/GlobalVars
require 'mkmf'
require 'rubygems'
require 'libyajl2'
diff --git a/ext/ffi_yajl/ext/parser/extconf.rb b/ext/ffi_yajl/ext/parser/extconf.rb
index 0b13bca..26bdca0 100644
--- a/ext/ffi_yajl/ext/parser/extconf.rb
+++ b/ext/ffi_yajl/ext/parser/extconf.rb
@@ -1,3 +1,4 @@
+# rubocop:disable Style/GlobalVars
require 'mkmf'
require 'rubygems'
require 'libyajl2'
diff --git a/lib/ffi_yajl/benchmark.rb b/lib/ffi_yajl/benchmark.rb
index 6d50c0f..e8944ca 100644
--- a/lib/ffi_yajl/benchmark.rb
+++ b/lib/ffi_yajl/benchmark.rb
@@ -25,4 +25,3 @@ 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 d3f969c..5b7dbb1 100644
--- a/lib/ffi_yajl/benchmark/encode.rb
+++ b/lib/ffi_yajl/benchmark/encode.rb
@@ -42,7 +42,6 @@ end
module FFI_Yajl
class Benchmark
class Encode
-
def run
#filename = ARGV[0] || 'benchmark/subjects/ohai.json'
filename = File.expand_path(File.join(File.dirname(__FILE__), "subjects", "ohai.json"))
@@ -51,7 +50,6 @@ module FFI_Yajl
times = ARGV[1] ? ARGV[1].to_i : 1000
puts "Starting benchmark encoding #{filename} #{times} times\n\n"
::Benchmark.bmbm { |x|
-
x.report("FFI_Yajl::Encoder.encode (to a String)") {
times.times {
output = FFI_Yajl::Encoder.encode(hash)
@@ -136,5 +134,4 @@ module FFI_Yajl
end
end
end
-
end
diff --git a/lib/ffi_yajl/benchmark/encode_profile.rb b/lib/ffi_yajl/benchmark/encode_profile.rb
index ce98a3c..f7ac7c2 100644
--- a/lib/ffi_yajl/benchmark/encode_profile.rb
+++ b/lib/ffi_yajl/benchmark/encode_profile.rb
@@ -14,7 +14,6 @@ ENV['CPUPROFILE_FREQUENCY'] = "4000"
module FFI_Yajl
class Benchmark
class EncodeProfile
-
def run
if defined?(PerfTools)
filename = File.expand_path(File.join(File.dirname(__FILE__), "subjects", "ohai.json"))
@@ -32,7 +31,6 @@ module FFI_Yajl
system("pprof.rb --text /tmp/ffi_yajl_encode_profile.out")
end
end
-
end
end
end
diff --git a/lib/ffi_yajl/benchmark/http.rb b/lib/ffi_yajl/benchmark/http.rb
index 551c987..4c61df5 100644
--- a/lib/ffi_yajl/benchmark/http.rb
+++ b/lib/ffi_yajl/benchmark/http.rb
@@ -15,7 +15,7 @@ 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
-puts "Starting benchmark parsing #{uri.to_s} #{times} times\n\n"
+puts "Starting benchmark parsing #{uri} #{times} times\n\n"
Benchmark.bmbm { |x|
x.report {
puts "Yajl::HttpStream.get"
@@ -29,4 +29,4 @@ Benchmark.bmbm { |x|
JSON.parse(Net::HTTP.get_response(uri).body, :max_nesting => false)
}
}
-} \ No newline at end of file
+}
diff --git a/lib/ffi_yajl/benchmark/parse.rb b/lib/ffi_yajl/benchmark/parse.rb
index 02ad740..ce22147 100644
--- a/lib/ffi_yajl/benchmark/parse.rb
+++ b/lib/ffi_yajl/benchmark/parse.rb
@@ -34,7 +34,6 @@ rescue LoadError
end
class FFI_Yajl::Benchmark::Parse
-
def run
filename = File.expand_path(File.join(File.dirname(__FILE__), "subjects", "item.json"))
json = File.new(filename, 'r')
@@ -65,7 +64,7 @@ class FFI_Yajl::Benchmark::Parse
}
}
io_parser = Yajl::Parser.new
- io_parser.on_parse_complete = lambda {|obj|} if times > 1
+ io_parser.on_parse_complete = lambda { |obj| } if times > 1
x.report {
puts "Yajl::Parser#parse (from an IO)"
times.times {
@@ -74,7 +73,7 @@ class FFI_Yajl::Benchmark::Parse
}
}
string_parser = Yajl::Parser.new
- string_parser.on_parse_complete = lambda {|obj|} if times > 1
+ string_parser.on_parse_complete = lambda { |obj| } if times > 1
x.report {
puts "Yajl::Parser#parse (from a String)"
times.times {
@@ -143,4 +142,3 @@ class FFI_Yajl::Benchmark::Parse
end
end
-
diff --git a/lib/ffi_yajl/benchmark/parse_json_and_marshal.rb b/lib/ffi_yajl/benchmark/parse_json_and_marshal.rb
index 06fe70b..163f559 100644
--- a/lib/ffi_yajl/benchmark/parse_json_and_marshal.rb
+++ b/lib/ffi_yajl/benchmark/parse_json_and_marshal.rb
@@ -23,7 +23,7 @@ Benchmark.bmbm { |x|
x.report {
puts "Yajl::Parser#parse"
yajl = Yajl::Parser.new
- yajl.on_parse_complete = lambda {|obj|} if times > 1
+ yajl.on_parse_complete = lambda { |obj| } if times > 1
times.times {
json.rewind
hash = yajl.parse(json)
@@ -47,4 +47,4 @@ Benchmark.bmbm { |x|
}
}
json.close
-marshal_file.close \ No newline at end of file
+marshal_file.close
diff --git a/lib/ffi_yajl/benchmark/parse_json_and_yaml.rb b/lib/ffi_yajl/benchmark/parse_json_and_yaml.rb
index 0cc509a..4e96e02 100644
--- a/lib/ffi_yajl/benchmark/parse_json_and_yaml.rb
+++ b/lib/ffi_yajl/benchmark/parse_json_and_yaml.rb
@@ -18,7 +18,7 @@ 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 { |x|
parser = Yajl::Parser.new
- parser.on_parse_complete = lambda {|obj|} if times > 1
+ parser.on_parse_complete = lambda { |obj| } if times > 1
x.report {
puts "Yajl::Parser#parse"
times.times {
@@ -52,4 +52,4 @@ Benchmark.bmbm { |x|
}
}
}
-yaml.close \ No newline at end of file
+yaml.close
diff --git a/lib/ffi_yajl/benchmark/parse_profile.rb b/lib/ffi_yajl/benchmark/parse_profile.rb
index 5efb1e2..39343bc 100644
--- a/lib/ffi_yajl/benchmark/parse_profile.rb
+++ b/lib/ffi_yajl/benchmark/parse_profile.rb
@@ -14,7 +14,6 @@ ENV['CPUPROFILE_FREQUENCY'] = "4000"
module FFI_Yajl
class Benchmark
class ParseProfile
-
def run
if defined?(PerfTools)
filename = File.expand_path(File.join(File.dirname(__FILE__), "subjects", "ohai.json"))
@@ -31,7 +30,6 @@ module FFI_Yajl
system("pprof.rb --text /tmp/ffi_yajl_encode_profile.out")
end
end
-
end
end
end
diff --git a/lib/ffi_yajl/benchmark/parse_profile_ruby_prof.rb b/lib/ffi_yajl/benchmark/parse_profile_ruby_prof.rb
index 5b9f73e..8d9dd5d 100644
--- a/lib/ffi_yajl/benchmark/parse_profile_ruby_prof.rb
+++ b/lib/ffi_yajl/benchmark/parse_profile_ruby_prof.rb
@@ -7,7 +7,6 @@ require 'ffi_yajl'
module FFI_Yajl
class Benchmark
class ParseProfileRubyProf
-
def run
begin
require 'ruby-prof'
@@ -33,7 +32,6 @@ module FFI_Yajl
end
end
-
end
end
end
diff --git a/lib/ffi_yajl/benchmark/parse_stream.rb b/lib/ffi_yajl/benchmark/parse_stream.rb
index 94c5ac3..955f22f 100644
--- a/lib/ffi_yajl/benchmark/parse_stream.rb
+++ b/lib/ffi_yajl/benchmark/parse_stream.rb
@@ -20,7 +20,7 @@ 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 { |x|
parser = Yajl::Parser.new
- parser.on_parse_complete = lambda {|obj|}
+ parser.on_parse_complete = lambda { |obj| }
x.report {
puts "Yajl::Parser#parse"
times.times {
@@ -51,4 +51,4 @@ Benchmark.bmbm { |x|
}
end
}
-json.close \ No newline at end of file
+json.close
diff --git a/lib/ffi_yajl/ffi.rb b/lib/ffi_yajl/ffi.rb
index c56ea10..094c51d 100644
--- a/lib/ffi_yajl/ffi.rb
+++ b/lib/ffi_yajl/ffi.rb
@@ -42,16 +42,16 @@ 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, [
@@ -77,14 +77,14 @@ module FFI_Yajl
:yajl_dont_validate_strings, 0x02,
:yajl_allow_trailing_garbage, 0x04,
:yajl_allow_multiple_values, 0x08,
- :yajl_allow_partial_values, 0x10,
+ :yajl_allow_partial_values, 0x10
]
enum :yajl_gen_option, [
:yajl_gen_beautify, 0x01,
:yajl_gen_indent_string, 0x02,
:yajl_gen_print_callback, 0x04,
- :yajl_gen_validate_utf8, 0x08,
+ :yajl_gen_validate_utf8, 0x08
]
typedef :pointer, :yajl_handle
@@ -132,10 +132,9 @@ module FFI_Yajl
attach_function :yajl_gen_array_open, [:yajl_gen], :int
attach_function :yajl_gen_array_close, [:yajl_gen], :int
# yajl_gen_status yajl_gen_get_buf (yajl_gen hand, const unsigned char **buf, unsigned int *len)
- attach_function :yajl_gen_get_buf, [:yajl_gen, :pointer ,:pointer], :int
+ attach_function :yajl_gen_get_buf, [:yajl_gen, :pointer , :pointer], :int
# void yajl_gen_clear (yajl_gen hand)
attach_function :yajl_gen_clear, [:yajl_gen], :void
-
end
require 'ffi_yajl/encoder'
diff --git a/lib/ffi_yajl/ffi/encoder.rb b/lib/ffi_yajl/ffi/encoder.rb
index 71b631e..94588d0 100644
--- a/lib/ffi_yajl/ffi/encoder.rb
+++ b/lib/ffi_yajl/ffi/encoder.rb
@@ -60,7 +60,6 @@ module FFI_Yajl
return string
end
-
end
end
end
@@ -68,7 +67,7 @@ end
class Hash
def ffi_yajl(yajl_gen, state)
if state[:processing_key]
- str = self.to_s
+ str = to_s
if ( status = FFI_Yajl.yajl_gen_string(yajl_gen, str, str.bytesize) ) != 0
FFI_Yajl::Encoder.raise_error_for_status(status, str)
end
@@ -76,7 +75,7 @@ class Hash
if ( status = FFI_Yajl.yajl_gen_map_open(yajl_gen) ) != 0
FFI_Yajl::Encoder.raise_error_for_status(status, '{')
end
- self.each do |key, value|
+ each do |key, value|
# Perf Fix: mutate state hash rather than creating new copy
state[:processing_key] = true
key.ffi_yajl(yajl_gen, state)
@@ -93,7 +92,7 @@ end
class Array
def ffi_yajl(yajl_gen, state)
if state[:processing_key]
- str = self.to_s
+ str = to_s
if ( status = FFI_Yajl.yajl_gen_string(yajl_gen, str, str.bytesize) ) != 0
FFI_Yajl::Encoder.raise_error_for_status(status, str)
end
@@ -101,7 +100,7 @@ class Array
if ( status = FFI_Yajl.yajl_gen_array_open(yajl_gen) ) != 0
FFI_Yajl::Encoder.raise_error_for_status(status, '[')
end
- self.each do |value|
+ each do |value|
value.ffi_yajl(yajl_gen, state)
end
if ( status = FFI_Yajl.yajl_gen_array_close(yajl_gen) ) != 0
@@ -113,7 +112,7 @@ end
class NilClass
def ffi_yajl(yajl_gen, state)
- str = self.to_s
+ str = to_s
if state[:processing_key]
if ( status = FFI_Yajl.yajl_gen_string(yajl_gen, str, str.bytesize) ) != 0
FFI_Yajl::Encoder.raise_error_for_status(status, str)
@@ -128,7 +127,7 @@ end
class TrueClass
def ffi_yajl(yajl_gen, state)
- str = self.to_s
+ str = to_s
if state[:processing_key]
if ( status = FFI_Yajl.yajl_gen_string(yajl_gen, str, str.bytesize) ) != 0
FFI_Yajl::Encoder.raise_error_for_status(status, str)
@@ -143,7 +142,7 @@ end
class FalseClass
def ffi_yajl(yajl_gen, state)
- str = self.to_s
+ str = to_s
if state[:processing_key]
if ( status = FFI_Yajl.yajl_gen_string(yajl_gen, str, str.bytesize) ) != 0
FFI_Yajl::Encoder.raise_error_for_status(status, str)
@@ -158,7 +157,7 @@ end
class Fixnum
def ffi_yajl(yajl_gen, state)
- str = self.to_s
+ str = to_s
if str == "NaN" || str == "Infinity" || str == "-Infinity"
raise ::FFI_Yajl::EncodeError.new("'#{str}' is an invalid number")
end
@@ -176,7 +175,7 @@ end
class Bignum
def ffi_yajl(yajl_gen, state)
- str = self.to_s
+ str = to_s
if str == "NaN" || str == "Infinity" || str == "-Infinity"
raise ::FFI_Yajl::EncodeError.new("'#{str}' is an invalid number")
end
@@ -194,7 +193,7 @@ end
class Float
def ffi_yajl(yajl_gen, state)
- str = self.to_s
+ str = to_s
if str == "NaN" || str == "Infinity" || str == "-Infinity"
raise ::FFI_Yajl::EncodeError.new("'#{str}' is an invalid number")
end
@@ -212,7 +211,7 @@ end
class Symbol
def ffi_yajl(yajl_gen, state)
- str = self.to_s
+ str = to_s
if ( status = FFI_Yajl.yajl_gen_string(yajl_gen, str, str.bytesize) ) != 0
FFI_Yajl::Encoder.raise_error_for_status(status, str)
end
@@ -221,7 +220,7 @@ end
class String
def ffi_yajl(yajl_gen, state)
- if ( status = FFI_Yajl.yajl_gen_string(yajl_gen, self, self.bytesize) ) != 0
+ if ( status = FFI_Yajl.yajl_gen_string(yajl_gen, self, bytesize) ) != 0
FFI_Yajl::Encoder.raise_error_for_status(status, self)
end
end
@@ -229,7 +228,7 @@ end
class StringIO
def ffi_yajl(yajl_gen, state)
- str = self.read
+ str = read
if ( status = FFI_Yajl.yajl_gen_string(yajl_gen, str, str.bytesize) ) != 0
FFI_Yajl::Encoder.raise_error_for_status(status, str)
end
@@ -238,7 +237,7 @@ end
class Date
def ffi_yajl(yajl_gen, state)
- str = self.to_s
+ str = to_s
if ( status = FFI_Yajl.yajl_gen_string(yajl_gen, str, str.bytesize) ) != 0
FFI_Yajl::Encoder.raise_error_for_status(status, str)
end
@@ -247,7 +246,7 @@ end
class Time
def ffi_yajl(yajl_gen, state)
- str = self.strftime "%Y-%m-%d %H:%M:%S %z"
+ str = strftime "%Y-%m-%d %H:%M:%S %z"
if ( status = FFI_Yajl.yajl_gen_string(yajl_gen, str, str.bytesize) ) != 0
FFI_Yajl::Encoder.raise_error_for_status(status, str)
end
@@ -256,7 +255,7 @@ end
class DateTime
def ffi_yajl(yajl_gen, state)
- str = self.to_s
+ str = to_s
if ( status = FFI_Yajl.yajl_gen_string(yajl_gen, str, str.bytesize) ) != 0
FFI_Yajl::Encoder.raise_error_for_status(status, str)
end
@@ -267,11 +266,11 @@ end
class Object
def ffi_yajl(yajl_gen, state)
if !state[:processing_key] && self.respond_to?(:to_json)
- str = self.to_json(state[:json_opts])
+ str = to_json(state[:json_opts])
# #yajl_gen_number outputs a string without quotes around it
status = FFI_Yajl.yajl_gen_number(yajl_gen, str, str.bytesize)
else
- str = self.to_s
+ str = to_s
status = FFI_Yajl.yajl_gen_string(yajl_gen, str, str.bytesize)
end
if ( status ) != 0
diff --git a/lib/ffi_yajl/ffi/parser.rb b/lib/ffi_yajl/ffi/parser.rb
index 77d2389..d0d152a 100644
--- a/lib/ffi_yajl/ffi/parser.rb
+++ b/lib/ffi_yajl/ffi/parser.rb
@@ -23,7 +23,6 @@
module FFI_Yajl
module FFI
module Parser
-
def set_value(val)
case stack.last
when Hash
@@ -50,10 +49,9 @@ module FFI_Yajl
end
def key_pop
- @key = key_stack.pop()
+ @key = key_stack.pop
end
-
def setup_callbacks
@null_callback = ::FFI::Function.new(:int, [:pointer]) do |ctx|
set_value(nil)
@@ -68,7 +66,7 @@ module FFI_Yajl
1
end
@number_callback = ::FFI::Function.new(:int, [:pointer, :string, :size_t ]) do |ctx, stringval, stringlen|
- s = stringval.slice(0,stringlen)
+ s = stringval.slice(0, stringlen)
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
@@ -80,7 +78,7 @@ module FFI_Yajl
1
end
@string_callback = ::FFI::Function.new(:int, [:pointer, :string, :size_t]) do |ctx, stringval, stringlen|
- s = stringval.slice(0,stringlen)
+ s = stringval.slice(0, stringlen)
s.force_encoding('UTF-8') if defined? Encoding
set_value(s)
1
@@ -91,7 +89,7 @@ module FFI_Yajl
1
end
@map_key_callback = ::FFI::Function.new(:int, [:pointer, :string, :size_t]) do |ctx, key, keylen|
- s = key.slice(0,keylen)
+ s = key.slice(0, keylen)
s.force_encoding('UTF-8') if defined? Encoding
self.key = @opts[:symbolize_keys] ? s.to_sym : s
1
@@ -113,7 +111,6 @@ module FFI_Yajl
end
end
-
def do_yajl_parse(str, yajl_opts = {})
setup_callbacks
callback_ptr = ::FFI::MemoryPointer.new(::FFI_Yajl::YajlCallbacks)
diff --git a/lib/ffi_yajl/map_library_name.rb b/lib/ffi_yajl/map_library_name.rb
index 8723424..249116e 100644
--- a/lib/ffi_yajl/map_library_name.rb
+++ b/lib/ffi_yajl/map_library_name.rb
@@ -29,7 +29,6 @@ require 'libyajl2'
module FFI_Yajl
module MapLibraryName
-
private
# Stub for tests to override the host_os
diff --git a/lib/ffi_yajl/parser.rb b/lib/ffi_yajl/parser.rb
index 9008a3e..da9b704 100644
--- a/lib/ffi_yajl/parser.rb
+++ b/lib/ffi_yajl/parser.rb
@@ -82,7 +82,7 @@ module FFI_Yajl
return nil if str == ""
if str.respond_to?(:read)
- str = str.read()
+ str = str.read
end
# call either the ext or ffi hook
diff --git a/spec/ffi_yajl/encoder_spec.rb b/spec/ffi_yajl/encoder_spec.rb
index acd7fcf..d8ee707 100644
--- a/spec/ffi_yajl/encoder_spec.rb
+++ b/spec/ffi_yajl/encoder_spec.rb
@@ -25,18 +25,17 @@ require 'spec_helper'
require 'date'
describe "FFI_Yajl::Encoder" do
-
let(:options) { {} }
let(:encoder) { FFI_Yajl::Encoder.new(options) }
it "encodes hashes in keys as strings", :ruby_gte_193 => true do
- ruby = { {'a' => 'b'} => 2 }
+ ruby = { { 'a' => 'b' } => 2 }
expect(encoder.encode(ruby)).to eq('{"{\"a\"=>\"b\"}":2}')
end
it "encodes arrays in keys as strings", :ruby_gte_193 => true do
- ruby = { [0,1] => 2 }
+ ruby = { [0, 1] => 2 }
expect(encoder.encode(ruby)).to eq('{"[0, 1]":2}')
end
@@ -66,14 +65,14 @@ describe "FFI_Yajl::Encoder" do
end
it "encodes bignums in keys as strings" do
- ruby = { 12345678901234567890 => 2 }
+ ruby = { 12_345_678_901_234_567_890 => 2 }
expect(encoder.encode(ruby)).to eq('{"12345678901234567890":2}')
end
it "encodes objects in keys as strings" do
o = Object.new
ruby = { o => 2 }
- expect(encoder.encode(ruby)).to eq(%Q{{"#{o.to_s}":2}})
+ expect(encoder.encode(ruby)).to eq(%{{"#{o}":2}})
end
it "encodes an object in a key which has a #to_json method as strings" do
@@ -84,7 +83,7 @@ describe "FFI_Yajl::Encoder" do
end
o = Thing.new
ruby = { o => 2 }
- expect(encoder.encode(ruby)).to eq(%Q{{"#{o.to_s}":2}})
+ expect(encoder.encode(ruby)).to eq(%{{"#{o}":2}})
end
# XXX: 127 == YAJL_MAX_DEPTH hardcodedness, zero control for us, it isn't even a twiddleable #define
@@ -92,14 +91,14 @@ describe "FFI_Yajl::Encoder" do
root = []
a = root
127.times { |_| a << []; a = a[0] }
- expect{ encoder.encode(root) }.to raise_error(FFI_Yajl::EncodeError)
+ expect { encoder.encode(root) }.to raise_error(FFI_Yajl::EncodeError)
end
it "raises an exception for deeply nested hashes" do
root = {}
a = root
- 127.times {|_| a["a"] = {}; a = a["a"] }
- expect{ encoder.encode(root) }.to raise_error(FFI_Yajl::EncodeError)
+ 127.times { |_| a["a"] = {}; a = a["a"] }
+ expect { encoder.encode(root) }.to raise_error(FFI_Yajl::EncodeError)
end
it "encodes symbols in keys as strings" do
@@ -113,7 +112,7 @@ describe "FFI_Yajl::Encoder" do
end
it "can encode 32-bit unsigned ints" do
- ruby = { "gid"=>4294967294 }
+ ruby = { "gid" => 4_294_967_294 }
expect(encoder.encode(ruby)).to eq('{"gid":4294967294}')
end
@@ -128,7 +127,7 @@ describe "FFI_Yajl::Encoder" do
it "can encode Date objects" do
ruby = Date.parse('2001-02-03')
- expect(encoder.encode(ruby)).to eq( %q{"2001-02-03"} )
+ expect(encoder.encode(ruby)).to eq( '"2001-02-03"' )
end
it "can encode StringIOs" do
@@ -148,13 +147,13 @@ describe "FFI_Yajl::Encoder" do
it "encodes them correctly" do
ruby = Time.local(2001, 02, 02, 21, 05, 06)
- expect(encoder.encode(ruby)).to eq( %q{"2001-02-02 21:05:06 +0000"} )
+ expect(encoder.encode(ruby)).to eq( '"2001-02-02 21:05:06 +0000"' )
end
end
it "can encode DateTime objects" do
ruby = DateTime.parse('2001-02-03T04:05:06.1+07:00')
- expect(encoder.encode(ruby)).to eq( %q{"2001-02-03T04:05:06+07:00"} )
+ expect(encoder.encode(ruby)).to eq( '"2001-02-03T04:05:06+07:00"' )
end
describe "testing .to_json for Objects" do
@@ -176,25 +175,25 @@ describe "FFI_Yajl::Encoder" do
context "when encoding invalid utf-8" do
ruby = {
- "automatic"=>{
- "etc"=>{
- "passwd"=>{
- "root"=>{"dir"=>"/root", "gid"=>0, "uid"=>0, "shell"=>"/bin/sh", "gecos"=>"Elan Ruusam\xc3\xa4e"},
- "glen"=>{"dir"=>"/home/glen", "gid"=>500, "uid"=>500, "shell"=>"/bin/bash", "gecos"=>"Elan Ruusam\xE4e"},
- }
+ "automatic" => {
+ "etc" => {
+ "passwd" => {
+ "root" => { "dir" => "/root", "gid" => 0, "uid" => 0, "shell" => "/bin/sh", "gecos" => "Elan Ruusam\xc3\xa4e" },
+ "glen" => { "dir" => "/home/glen", "gid" => 500, "uid" => 500, "shell" => "/bin/bash", "gecos" => "Elan Ruusam\xE4e" },
+ },
},
},
}
it "raises an error on invalid json" do
- expect{ encoder.encode(ruby) }.to raise_error(FFI_Yajl::EncodeError, /Invalid UTF-8 string 'Elan Ruusam.e': cannot encode to UTF-8/)
+ expect { encoder.encode(ruby) }.to raise_error(FFI_Yajl::EncodeError, /Invalid UTF-8 string 'Elan Ruusam.e': cannot encode to UTF-8/)
end
context "when validate_utf8 is off" do
let(:options) { { :validate_utf8 => false } }
it "does not raise an error" do
- expect{ encoder.encode(ruby) }.not_to raise_error
+ expect { encoder.encode(ruby) }.not_to raise_error
end
it "returns utf8" do
diff --git a/spec/ffi_yajl/map_library_name_spec.rb b/spec/ffi_yajl/map_library_name_spec.rb
index 4907d50..0b5e9cb 100644
--- a/spec/ffi_yajl/map_library_name_spec.rb
+++ b/spec/ffi_yajl/map_library_name_spec.rb
@@ -47,7 +47,6 @@ describe "FFI_Yajl::MapLibraryName" do
end
host_os_library_name_mapping.each do |host_os, library_names|
-
context "#library_names" do
it "maps #{host_os} correctly" do
allow(Test).to receive(:host_os).and_return(host_os)
@@ -112,6 +111,5 @@ describe "FFI_Yajl::MapLibraryName" do
Test.send(:ffi_open_yajl_library)
end
end
-
end
end
diff --git a/spec/ffi_yajl/parser_spec.rb b/spec/ffi_yajl/parser_spec.rb
index ed6ef2a..968e0ee 100644
--- a/spec/ffi_yajl/parser_spec.rb
+++ b/spec/ffi_yajl/parser_spec.rb
@@ -24,21 +24,20 @@
require 'spec_helper'
describe "FFI_Yajl::Parser" do
-
shared_examples_for "correct json parsing" do
context "when json has 23456789012E666" do
let(:json) { '{"key": 23456789012E666}' }
it "should return infinity" do
- infinity = (1.0/0)
- expect(parser).to eq({"key" => infinity})
+ infinity = (1.0 / 0)
+ expect(parser).to eq("key" => infinity)
end
end
context "when parsing nil" do
let(:json) { nil }
it "should not coredump ruby" do
- expect{ parser }.to raise_error(FFI_Yajl::ParseError)
+ expect { parser }.to raise_error(FFI_Yajl::ParseError)
end
end
@@ -91,7 +90,7 @@ describe "FFI_Yajl::Parser" do
let(:options) { { :allow_comments => false } }
it "should not parse" do
- expect{parser}.to raise_error(FFI_Yajl::ParseError)
+ expect { parser }.to raise_error(FFI_Yajl::ParseError)
end
end
@@ -99,27 +98,27 @@ describe "FFI_Yajl::Parser" do
let(:options) { { :allow_comments => true } }
it "should parse" do
- expect(parser).to eq({"key"=>"value"})
+ expect(parser).to eq("key" => "value")
end
end
context "by default" do
- let(:options) { }
+ let(:options) {}
it "should parse" do
- expect(parser).to eq({"key"=>"value"})
+ expect(parser).to eq("key" => "value")
end
end
end
context "when json has multiline comments" do
- let(:json) { %Q{{"key": \n/*\n this is a multiline comment \n*/\n "value"}} }
+ let(:json) { %{{"key": \n/*\n this is a multiline comment \n*/\n "value"}} }
context "when allow_comments is false" do
let(:options) { { :allow_comments => false } }
it "should not parse" do
- expect{parser}.to raise_error(FFI_Yajl::ParseError)
+ expect { parser }.to raise_error(FFI_Yajl::ParseError)
end
end
@@ -127,19 +126,19 @@ describe "FFI_Yajl::Parser" do
let(:options) { { :allow_comments => true } }
it "should parse" do
- expect(parser).to eq({"key"=>"value"})
+ expect(parser).to eq("key" => "value")
end
end
end
context "when json has inline comments" do
- let(:json) { %Q{{"key": \n// this is an inline comment\n "value"}} }
+ let(:json) { %{{"key": \n// this is an inline comment\n "value"}} }
context "when allow_comments is false" do
let(:options) { { :allow_comments => false } }
it "should not parse" do
- expect{parser}.to raise_error(FFI_Yajl::ParseError)
+ expect { parser }.to raise_error(FFI_Yajl::ParseError)
end
end
@@ -147,7 +146,7 @@ describe "FFI_Yajl::Parser" do
let(:options) { { :allow_comments => true } }
it "should parse" do
- expect(parser).to eq({"key"=>"value"})
+ expect(parser).to eq("key" => "value")
end
end
end
@@ -156,7 +155,7 @@ describe "FFI_Yajl::Parser" do
let(:json) { "[\"#{"\201\203"}\"]" }
it "should not parse by default" do
- expect{parser}.to raise_error(FFI_Yajl::ParseError)
+ expect { parser }.to raise_error(FFI_Yajl::ParseError)
end
context "when :dont_validate_strings is set to true" do
@@ -171,7 +170,7 @@ describe "FFI_Yajl::Parser" do
let(:options) { { :dont_validate_strings => false } }
it "should not parse" do
- expect{parser}.to raise_error(FFI_Yajl::ParseError)
+ expect { parser }.to raise_error(FFI_Yajl::ParseError)
end
end
@@ -179,14 +178,14 @@ describe "FFI_Yajl::Parser" do
let(:options) { { :check_utf8 => true } }
it "should not parse" do
- expect{parser}.to raise_error(FFI_Yajl::ParseError)
+ expect { parser }.to raise_error(FFI_Yajl::ParseError)
end
context "when :dont_validate_strings is set to true" do
let(:options) { { :check_utf8 => true, :dont_validate_strings => true } }
it "should raise an ArgumentError" do
- expect{parser}.to raise_error(ArgumentError)
+ expect { parser }.to raise_error(ArgumentError)
end
end
@@ -194,7 +193,7 @@ describe "FFI_Yajl::Parser" do
let(:options) { { :check_utf8 => true, :dont_validate_strings => false } }
it "should not parse" do
- expect{parser}.to raise_error(FFI_Yajl::ParseError)
+ expect { parser }.to raise_error(FFI_Yajl::ParseError)
end
end
end
@@ -218,7 +217,7 @@ describe "FFI_Yajl::Parser" do
let(:options) { { :check_utf8 => false, :dont_validate_strings => false } }
it "should raise an ArgumentError" do
- expect{parser}.to raise_error(ArgumentError)
+ expect { parser }.to raise_error(ArgumentError)
end
end
end
@@ -228,7 +227,7 @@ describe "FFI_Yajl::Parser" do
let(:json) { StringIO.new('{"key": 1234}') }
it "should parse" do
- expect(parser).to eq({"key" => 1234})
+ expect(parser).to eq("key" => 1234)
end
end
@@ -236,14 +235,14 @@ describe "FFI_Yajl::Parser" do
let(:json) { '{"key": 1234}' }
it "should parse correctly" do
- expect(parser).to eq({"key" => 1234})
+ expect(parser).to eq("key" => 1234)
end
context "when symbolize_keys is true" do
let(:options) { { :symbolize_keys => true } }
it "should symbolize keys correctly" do
- expect(parser).to eq({:key => 1234})
+ expect(parser).to eq(:key => 1234)
end
end
@@ -254,7 +253,7 @@ describe "FFI_Yajl::Parser" do
parser do |obj|
output = obj
end
- expect(output).to eq({"key" => 1234})
+ expect(output).to eq("key" => 1234)
end
end
end
@@ -305,14 +304,14 @@ describe "FFI_Yajl::Parser" do
let(:json) { '{"日本語": 1234}' }
it "should parse correctly" do
- expect(parser).to eq({"日本語" => 1234})
+ expect(parser).to eq("日本語" => 1234)
end
context "when symbolize_keys is true" do
let(:options) { { :symbolize_keys => true } }
it "should symbolize keys correctly" do
- expect(parser).to eq({:"日本語" => 1234})
+ expect(parser).to eq(:"日本語" => 1234)
end
if RUBY_VERSION.to_f >= 1.9
@@ -327,7 +326,7 @@ describe "FFI_Yajl::Parser" do
let(:json) { "{\"id\": 2147483649}" }
it "should parse corectly" do
- expect(parser).to eql({"id" => 2147483649})
+ expect(parser).to eql("id" => 2_147_483_649)
end
end
@@ -335,7 +334,7 @@ describe "FFI_Yajl::Parser" do
let(:json) { "{\"id\": 5687389800}" }
it "should parse corectly" do
- expect(parser).to eql({"id" => 5687389800})
+ expect(parser).to eql("id" => 5_687_389_800)
end
end
@@ -343,7 +342,7 @@ describe "FFI_Yajl::Parser" do
let(:json) { "{\"id\": 1046289770033519442869495707521600000000}" }
it "should parse corectly" do
- expect(parser).to eql({"id" => 1046289770033519442869495707521600000000})
+ expect(parser).to eql("id" => 1_046_289_770_033_519_442_869_495_707_521_600_000_000)
end
end
@@ -385,10 +384,9 @@ describe "FFI_Yajl::Parser" do
context "with allow_trailing_garbage" do
let(:options) { { :allow_trailing_garbage => true } }
it "parses" do
- expect(parser).to eq({"foo"=>{"foo"=>1234}})
+ expect(parser).to eq("foo" => { "foo" => 1234 })
end
end
-
end
context "when an extra bracket is present" do
@@ -480,7 +478,7 @@ describe "FFI_Yajl::Parser" do
let(:json) { '[0.' + '1' * 2**23 + ']' }
it "parses" do
- expect{ parser }.not_to raise_error
+ expect { parser }.not_to raise_error
end
end
@@ -489,7 +487,7 @@ describe "FFI_Yajl::Parser" do
let(:options) { { :symbolize_keys => true } }
it "parses" do
- expect{ parser }.not_to raise_error
+ expect { parser }.not_to raise_error
end
end
@@ -504,7 +502,7 @@ describe "FFI_Yajl::Parser" do
let(:json) { '{"foo":"bar","foo":"baz"}' }
let(:options) { { :unique_key_checking => true } }
it "should raise" do
- expect{ parser }.to raise_error(FFI_Yajl::ParseError)
+ expect { parser }.to raise_error(FFI_Yajl::ParseError)
end
end
end
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index 03af269..147e124 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.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.
-$: << File.expand_path(File.join(File.dirname( __FILE__ ), "../lib"))
+$LOAD_PATH << File.expand_path(File.join(File.dirname( __FILE__ ), "../lib"))
# load yajl-ruby into the same process (tests that both c-libs can be
# linked in the same process). this should work, see:
@@ -42,5 +42,4 @@ RSpec.configure do |c|
c.expect_with :rspec do |c|
c.syntax = :expect
end
-
end