summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith@chef.io>2017-06-20 15:37:38 -0700
committerTim Smith <tsmith@chef.io>2017-06-20 15:37:38 -0700
commit672fce3aed2d68e7362dc5cfeb72df78f30eb3a2 (patch)
tree76598d0c31493ca6fa8a8353402136cf8003b997
parentf3f92275f804f4c6cf93ee054af7d4ba3e50030a (diff)
downloadffi-yajl-672fce3aed2d68e7362dc5cfeb72df78f30eb3a2.tar.gz
Switch from reek/rubocop to chefstyle
Reek doesn't work with modern Rake Signed-off-by: Tim Smith <tsmith@chef.io>
-rw-r--r--.rubocop.yml68
-rw-r--r--Gemfile7
-rw-r--r--Rakefile141
-rwxr-xr-xbin/ffi-yajl-bench14
-rw-r--r--ext/ffi_yajl/ext/dlopen/extconf.rb10
-rw-r--r--ext/ffi_yajl/ext/encoder/extconf.rb24
-rw-r--r--ext/ffi_yajl/ext/parser/extconf.rb24
-rw-r--r--lib/ffi_yajl.rb14
-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.rb16
-rw-r--r--lib/ffi_yajl/benchmark/parse_json_and_marshal.rb20
-rw-r--r--lib/ffi_yajl/benchmark/parse_json_and_yaml.rb22
-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.rb18
-rw-r--r--lib/ffi_yajl/encoder.rb4
-rw-r--r--lib/ffi_yajl/ext.rb18
-rw-r--r--lib/ffi_yajl/ffi.rb16
-rw-r--r--lib/ffi_yajl/ffi/encoder.rb18
-rw-r--r--lib/ffi_yajl/ffi/parser.rb10
-rw-r--r--lib/ffi_yajl/map_library_name.rb6
-rw-r--r--lib/ffi_yajl/parser.rb4
-rw-r--r--spec/ffi_yajl/encoder_spec.rb20
-rw-r--r--spec/ffi_yajl/map_library_name_spec.rb4
-rw-r--r--spec/ffi_yajl/parser_spec.rb14
-rw-r--r--spec/spec_helper.rb8
31 files changed, 254 insertions, 364 deletions
diff --git a/.rubocop.yml b/.rubocop.yml
index e843ff7..1ed8c28 100644
--- a/.rubocop.yml
+++ b/.rubocop.yml
@@ -1,67 +1,3 @@
-AbcSize:
- Enabled: false
-AndOr:
- Enabled: false
-Lint/AssignmentInCondition:
- Enabled: false
-ClassAndModuleCamelCase:
- Enabled: false
-ClassLength:
- Enabled: false
-CommentAnnotation:
- Enabled: false
-CyclomaticComplexity:
- Enabled: false
-Documentation:
- Enabled: false
-DoubleNegation:
- Enabled: false
-Encoding:
- Enabled: false
-Eval:
- Enabled: false
-Style/FileName:
+Lint/DuplicateMethods:
Exclude:
- - bin/ffi-yajl-bench
-FormatString:
- Enabled: false
-Style/GuardClause:
- Enabled: false
-Lint/HandleExceptions:
- Enabled: false
-LineLength:
- Enabled: false
-MethodLength:
- Enabled: false
-ModuleLength:
- Enabled: false
-PerceivedComplexity:
- Enabled: false
-PercentLiteralDelimiters:
- PreferredDelimiters:
- '%': '{}'
- '%q': '{}'
- '%Q': '{}'
- '%w': '{}'
- '%W': '{}'
- '%x': '{}'
-RegexpLiteral:
- Enabled: false
-Style/Semicolon:
- Enabled: false
-SignalException:
- Enabled: false
-SingleSpaceBeforeFirstArg:
- Enabled: false
-SpaceInsideBrackets:
- Enabled: false
-SpaceInsideParens:
- Enabled: false
-StringLiterals:
- Enabled: false
-TrailingComma:
- EnforcedStyleForMultiline: comma
-UnusedMethodArgument:
- Enabled: false
-UnusedBlockArgument:
- Enabled: false
+ - 'lib/ffi_yajl/ffi/encoder.rb'
diff --git a/Gemfile b/Gemfile
index d5fe6d0..3250298 100644
--- a/Gemfile
+++ b/Gemfile
@@ -3,16 +3,15 @@ source "https://rubygems.org"
gemspec name: "ffi-yajl"
platforms :rbx do
- gem 'rubysl', '~> 2.0'
+ gem "rubysl", "~> 2.0"
end
group :development do
# for testing loading concurrently with yajl-ruby, not on jruby
# gem 'yajl-ruby', platforms: [ :ruby, :mswin, :mingw ]
- gem 'github_changelog_generator'
+ gem "github_changelog_generator"
end
group :development_extras do
- gem 'rubocop', '= 0.32.1'
- gem 'reek', '= 1.3.7'
+ gem "chefstyle"
end
diff --git a/Rakefile b/Rakefile
index 05a69d1..331b3fd 100644
--- a/Rakefile
+++ b/Rakefile
@@ -1,10 +1,10 @@
$LOAD_PATH << File.expand_path(File.join(File.dirname( __FILE__ ), "lib"))
-require 'rspec/core/rake_task'
-require 'rubygems/package_task'
-require 'rake/extensiontask'
-require 'ffi_yajl/version'
-require 'github_changelog_generator/task'
+require "rspec/core/rake_task"
+require "rubygems/package_task"
+require "rake/extensiontask"
+require "ffi_yajl/version"
+require "github_changelog_generator/task"
Dir[File.expand_path("../*gemspec", __FILE__)].reverse_each do |gemspec_path|
gemspec = eval(IO.read(gemspec_path))
@@ -13,7 +13,7 @@ end
GitHubChangelogGenerator::RakeTask.new :changelog do |config|
config.issues = false
- config.since_tag = '1.0.1'
+ config.since_tag = "1.0.1"
config.exclude_labels = %w{duplicate question invalid wontfix changelog_skip}
end
@@ -42,26 +42,26 @@ task install: [:package] do
end
end
-spec = Gem::Specification.load('ffi-yajl.gemspec')
+spec = Gem::Specification.load("ffi-yajl.gemspec")
Rake::ExtensionTask.new do |ext|
- ext.name = 'encoder'
- ext.lib_dir = 'lib/ffi_yajl/ext'
- ext.ext_dir = 'ext/ffi_yajl/ext/encoder'
+ ext.name = "encoder"
+ ext.lib_dir = "lib/ffi_yajl/ext"
+ ext.ext_dir = "ext/ffi_yajl/ext/encoder"
ext.gem_spec = spec
end
Rake::ExtensionTask.new do |ext|
- ext.name = 'parser'
- ext.lib_dir = 'lib/ffi_yajl/ext'
- ext.ext_dir = 'ext/ffi_yajl/ext/parser'
+ ext.name = "parser"
+ ext.lib_dir = "lib/ffi_yajl/ext"
+ ext.ext_dir = "ext/ffi_yajl/ext/parser"
ext.gem_spec = spec
end
Rake::ExtensionTask.new do |ext|
- ext.name = 'dlopen'
- ext.lib_dir = 'lib/ffi_yajl/ext'
- ext.ext_dir = 'ext/ffi_yajl/ext/dlopen'
+ ext.name = "dlopen"
+ ext.lib_dir = "lib/ffi_yajl/ext"
+ ext.ext_dir = "ext/ffi_yajl/ext/dlopen"
ext.gem_spec = spec
end
@@ -80,101 +80,56 @@ end
namespace :spec do
desc "Run all specs against ffi extension"
RSpec::Core::RakeTask.new(:ffi) do |t|
- ENV['FORCE_FFI_YAJL'] = "ffi"
- t.pattern = FileList['spec/**/*_spec.rb']
+ ENV["FORCE_FFI_YAJL"] = "ffi"
+ t.pattern = FileList["spec/**/*_spec.rb"]
end
if !defined?(RUBY_ENGINE) || RUBY_ENGINE !~ /jruby/
desc "Run all specs again c extension"
RSpec::Core::RakeTask.new(:ext) do |t|
- ENV['FORCE_FFI_YAJL'] = "ext"
- t.pattern = FileList['spec/**/*_spec.rb']
+ ENV["FORCE_FFI_YAJL"] = "ext"
+ t.pattern = FileList["spec/**/*_spec.rb"]
end
end
end
-if RUBY_VERSION.to_f >= 1.9
- namespace :integration do
- begin
- require 'kitchen'
- rescue LoadError
- task :vagrant do
- puts "test-kitchen gem is not installed"
- end
- task :cloud do
- puts "test-kitchen gem is not installed"
- end
- else
- desc 'Run Test Kitchen with Vagrant'
- task :vagrant do
- Kitchen.logger = Kitchen.default_file_logger
- Kitchen::Config.new.instances.each do |instance|
- instance.test(:always)
- end
- end
-
- desc 'Run Test Kitchen with cloud plugins'
- task :cloud do
- if ENV['TRAVIS_PULL_REQUEST'] != 'true'
- ENV['KITCHEN_YAML'] = '.kitchen.cloud.yml'
- sh "kitchen test --concurrency 4"
- end
- end
- end
- end
- namespace :style do
- desc 'Run Ruby style checks'
- begin
- require 'rubocop/rake_task'
- rescue LoadError
- task :rubocop do
- puts "rubocop gem is not installed"
- end
- else
- RuboCop::RakeTask.new(:rubocop) do |t|
- t.fail_on_error = false
- end
- end
-
- desc 'Run Ruby smell checks'
- begin
- require 'reek/rake/task'
- rescue LoadError
- task :reek do
- puts "reek gem is not installed"
- end
- else
- Reek::Rake::Task.new(:reek) do |t|
- t.fail_on_error = false
- # t.config_files = '.reek.yml'
- end
- end
- end
-else
- namespace :integration do
+namespace :integration do
+ begin
+ require "kitchen"
+ rescue LoadError
task :vagrant do
- puts "test-kitchen unsupported on ruby 1.8"
+ puts "test-kitchen gem is not installed"
end
- task :cloud do
- puts "test-kitchen unsupported on ruby 1.8"
+ else
+ desc "Run Test Kitchen with Vagrant"
+ task :vagrant do
+ Kitchen.logger = Kitchen.default_file_logger
+ Kitchen::Config.new.instances.each do |instance|
+ instance.test(:always)
+ end
end
end
- namespace :style do
+end
+namespace :style do
+ desc "Run Ruby style checks"
+ begin
+ require "chefstyle"
+ require "rubocop/rake_task"
+ rescue LoadError
task :rubocop do
- puts "rubocop unsupported on ruby 1.8"
+ puts "chefstyle gem is not installed"
end
- task :reek do
- puts "reek unsupported on ruby 1.8"
+ else
+ RuboCop::RakeTask.new(:rubocop) do |t|
+ t.fail_on_error = false
end
end
end
-desc 'Run all style checks'
-task style: ['style:rubocop', 'style:reek']
+desc "Run all style checks"
+task style: ["style:rubocop"]
-desc 'Run style + spec tests by default on travis'
+desc "Run style + spec tests by default on travis"
task travis: %w{style spec}
-desc 'Run style, spec and test kichen on travis'
-task travis_all: ['style', 'spec', 'integration:cloud']
-
-task default: ['style', 'spec', 'integration:vagrant']
+desc "Run style + spec tests by default"
+task default: %w{style spec}
diff --git a/bin/ffi-yajl-bench b/bin/ffi-yajl-bench
index ceff62b..a861d1f 100755
--- a/bin/ffi-yajl-bench
+++ b/bin/ffi-yajl-bench
@@ -2,31 +2,31 @@
$LOAD_PATH << File.expand_path(File.join(File.dirname( File.symlink?(__FILE__) ? File.readlink(__FILE__) : __FILE__ ), "../lib"))
-require 'optparse'
-require 'ffi_yajl/benchmark'
+require "optparse"
+require "ffi_yajl/benchmark"
opts = {}
optparse = OptionParser.new do |o|
o.banner = "Usage: ffi-yajl-bench"
opts[:profile] = false
- o.on( '-p', '--profile', 'Run perftools.rb profiling' ) do
+ o.on( "-p", "--profile", "Run perftools.rb profiling" ) do
opts[:profile] = true
end
- o.on( '-F', '--ffi', 'Force using FFI' ) do
+ o.on( "-F", "--ffi", "Force using FFI" ) do
opts[:ffi] = true
end
- o.on( '-E', '--ext', 'Force using C ext' ) do
+ o.on( "-E", "--ext", "Force using C ext" ) do
opts[:ext] = true
end
end
optparse.parse!
-ENV['FORCE_FFI_YAJL'] = 'ffi' if opts[:ffi]
-ENV['FORCE_FFI_YAJL'] = 'ext' if opts[:ext]
+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
diff --git a/ext/ffi_yajl/ext/dlopen/extconf.rb b/ext/ffi_yajl/ext/dlopen/extconf.rb
index f35d0cb..803d326 100644
--- a/ext/ffi_yajl/ext/dlopen/extconf.rb
+++ b/ext/ffi_yajl/ext/dlopen/extconf.rb
@@ -1,8 +1,8 @@
# rubocop:disable Style/GlobalVars
-require 'mkmf'
-require 'rubygems'
+require "mkmf"
+require "rubygems"
-RbConfig::MAKEFILE_CONFIG['CC'] = ENV['CC'] if ENV['CC']
+RbConfig::MAKEFILE_CONFIG["CC"] = ENV["CC"] if ENV["CC"]
puts $CFLAGS
puts $LDFLAGS
@@ -11,6 +11,6 @@ have_header("dlfcn.h")
have_library("dl", "dlopen")
-dir_config 'dlopen'
+dir_config "dlopen"
-create_makefile 'ffi_yajl/ext/dlopen'
+create_makefile "ffi_yajl/ext/dlopen"
diff --git a/ext/ffi_yajl/ext/encoder/extconf.rb b/ext/ffi_yajl/ext/encoder/extconf.rb
index e46080a..e13c0a1 100644
--- a/ext/ffi_yajl/ext/encoder/extconf.rb
+++ b/ext/ffi_yajl/ext/encoder/extconf.rb
@@ -1,9 +1,9 @@
# rubocop:disable Style/GlobalVars
-require 'mkmf'
-require 'rubygems'
-require 'libyajl2'
+require "mkmf"
+require "rubygems"
+require "libyajl2"
-RbConfig::MAKEFILE_CONFIG['CC'] = ENV['CC'] if ENV['CC']
+RbConfig::MAKEFILE_CONFIG["CC"] = ENV["CC"] if ENV["CC"]
# pick up the vendored libyajl2 out of the libyajl2 gem
$CFLAGS = " -I#{Libyajl2.include_path} #{$CFLAGS}"
@@ -16,7 +16,7 @@ puts $CFLAGS
puts $LDFLAGS
# except if you're doing an unoptimized gcc install we're going to help you out a bit
-if RbConfig::MAKEFILE_CONFIG['CC'] =~ /gcc|clang/
+if RbConfig::MAKEFILE_CONFIG["CC"] =~ /gcc|clang/
$CFLAGS << " -O3" unless $CFLAGS[/-O\d/]
# how many people realize that -Wall is a compiler-specific flag???
# apparently not many based on reading lots of shitty extconf.rb's out there
@@ -34,32 +34,32 @@ end
# NOTE: find_library has the side effect of adding -lyajl to the flags which we are deliberately
# avoiding doing with the libyajl2-gem (allowing it to be lazily loaded with dlopen)
-if !windows? && !find_header('yajl/yajl_tree.h')
+if !windows? && !find_header("yajl/yajl_tree.h")
puts "libyajl2 headers not found in libyajl2-gem, searching for system libraries..."
HEADER_DIRS = [
"/opt/local/include", # MacPorts
"/usr/local/include", # /usr/local
- RbConfig::CONFIG['includedir'], # Ruby
+ RbConfig::CONFIG["includedir"], # Ruby
"/usr/include", # (default)
]
LIB_DIRS = [
"/opt/local/lib", # MacPorts
"/usr/local/lib", # /usr/local + Homebrew
- RbConfig::CONFIG['libdir'], # Ruby
+ RbConfig::CONFIG["libdir"], # Ruby
"/usr/lib", # (default)
]
# add --with-yajl-dir, --with-yajl-include, --with-yajl-lib
- dir_config('yajl', HEADER_DIRS, LIB_DIRS)
+ dir_config("yajl", HEADER_DIRS, LIB_DIRS)
# here we use find_library in order to deliberately link with -lyajl as a useful side-effect
- unless find_header('yajl/yajl_tree.h') && find_library('yajl', 'yajl_complete_parse')
+ unless find_header("yajl/yajl_tree.h") && find_library("yajl", "yajl_complete_parse")
abort "libyajl2 is missing. please install libyajl2"
end
end
-dir_config 'encoder'
+dir_config "encoder"
-create_makefile 'ffi_yajl/ext/encoder'
+create_makefile "ffi_yajl/ext/encoder"
diff --git a/ext/ffi_yajl/ext/parser/extconf.rb b/ext/ffi_yajl/ext/parser/extconf.rb
index 6f8526e..86ee50f 100644
--- a/ext/ffi_yajl/ext/parser/extconf.rb
+++ b/ext/ffi_yajl/ext/parser/extconf.rb
@@ -1,9 +1,9 @@
# rubocop:disable Style/GlobalVars
-require 'mkmf'
-require 'rubygems'
-require 'libyajl2'
+require "mkmf"
+require "rubygems"
+require "libyajl2"
-RbConfig::MAKEFILE_CONFIG['CC'] = ENV['CC'] if ENV['CC']
+RbConfig::MAKEFILE_CONFIG["CC"] = ENV["CC"] if ENV["CC"]
# pick up the vendored libyajl2 out of the libyajl2 gem
$CFLAGS = "-I#{Libyajl2.include_path} #{$CFLAGS}"
@@ -16,7 +16,7 @@ puts $CFLAGS
puts $LDFLAGS
# except if you're doing an unoptimized gcc install we're going to help you out a bit
-if RbConfig::MAKEFILE_CONFIG['CC'] =~ /gcc|clang/
+if RbConfig::MAKEFILE_CONFIG["CC"] =~ /gcc|clang/
$CFLAGS << " -O3" unless $CFLAGS[/-O\d/]
# how many people realize that -Wall is a compiler-specific flag???
# apparently not many based on reading lots of shitty extconf.rb's out there
@@ -34,32 +34,32 @@ end
# NOTE: find_library has the side effect of adding -lyajl to the flags which we are deliberately
# avoiding doing with the libyajl2-gem (allowing it to be lazily loaded with dlopen)
-if !windows? && !find_header('yajl/yajl_tree.h')
+if !windows? && !find_header("yajl/yajl_tree.h")
puts "libyajl2 headers not found in libyajl2-gem, searching for system libraries..."
HEADER_DIRS = [
"/opt/local/include", # MacPorts
"/usr/local/include", # /usr/local
- RbConfig::CONFIG['includedir'], # Ruby
+ RbConfig::CONFIG["includedir"], # Ruby
"/usr/include", # (default)
]
LIB_DIRS = [
"/opt/local/lib", # MacPorts
"/usr/local/lib", # /usr/local + Homebrew
- RbConfig::CONFIG['libdir'], # Ruby
+ RbConfig::CONFIG["libdir"], # Ruby
"/usr/lib", # (default)
]
# add --with-yajl-dir, --with-yajl-include, --with-yajl-lib
- dir_config('yajl', HEADER_DIRS, LIB_DIRS)
+ dir_config("yajl", HEADER_DIRS, LIB_DIRS)
# here we use find_library in order to deliberately link with -lyajl as a useful side-effect
- unless find_header('yajl/yajl_tree.h') && find_library('yajl', 'yajl_complete_parse')
+ unless find_header("yajl/yajl_tree.h") && find_library("yajl", "yajl_complete_parse")
abort "libyajl2 is missing. please install libyajl2"
end
end
-dir_config 'parser'
+dir_config "parser"
-create_makefile 'ffi_yajl/ext/parser'
+create_makefile "ffi_yajl/ext/parser"
diff --git a/lib/ffi_yajl.rb b/lib/ffi_yajl.rb
index 49cf97f..1111775 100644
--- a/lib/ffi_yajl.rb
+++ b/lib/ffi_yajl.rb
@@ -34,17 +34,17 @@
# dropped, so don't bother asking for that.
# - Then we try the c-ext and rescue into ffi that fails
#
-if ENV['FORCE_FFI_YAJL'] == "ext"
- require 'ffi_yajl/ext'
-elsif ENV['FORCE_FFI_YAJL'] == "ffi"
- require 'ffi_yajl/ffi'
+if ENV["FORCE_FFI_YAJL"] == "ext"
+ require "ffi_yajl/ext"
+elsif ENV["FORCE_FFI_YAJL"] == "ffi"
+ require "ffi_yajl/ffi"
elsif RUBY_PLATFORM == "java"
- require 'ffi_yajl/ffi'
+ require "ffi_yajl/ffi"
else
begin
- require 'ffi_yajl/ext'
+ require "ffi_yajl/ext"
rescue LoadError
warn "failed to load the ffi-yajl c-extension, falling back to ffi interface"
- require 'ffi_yajl/ffi'
+ require "ffi_yajl/ffi"
end
end
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..ad0091c 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
diff --git a/lib/ffi_yajl/benchmark/parse_json_and_marshal.rb b/lib/ffi_yajl/benchmark/parse_json_and_marshal.rb
index cd07d46..1148ebc 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 = {}
diff --git a/lib/ffi_yajl/benchmark/parse_json_and_yaml.rb b/lib/ffi_yajl/benchmark/parse_json_and_yaml.rb
index 6e479ce..b55d916 100644
--- a/lib/ffi_yajl/benchmark/parse_json_and_yaml.rb
+++ b/lib/ffi_yajl/benchmark/parse_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")
times = ARGV[0] ? ARGV[0].to_i : 1000
puts "Starting benchmark parsing #{File.size(filename)} bytes of JSON data #{times} times\n\n"
@@ -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..9ca0050 100644
--- a/lib/ffi_yajl/benchmark/parse_stream.rb
+++ b/lib/ffi_yajl/benchmark/parse_stream.rb
@@ -1,20 +1,20 @@
-$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"
diff --git a/lib/ffi_yajl/encoder.rb b/lib/ffi_yajl/encoder.rb
index 3b07e95..97f3e66 100644
--- a/lib/ffi_yajl/encoder.rb
+++ b/lib/ffi_yajl/encoder.rb
@@ -47,7 +47,7 @@ module FFI_Yajl
if str.respond_to?(:scrub)
str.scrub!
else
- str.encode!("UTF-16le", undef: :replace, invalid: :replace).encode!('UTF-8')
+ str.encode!("UTF-16le", undef: :replace, invalid: :replace).encode!("UTF-8")
end
end
str
@@ -68,7 +68,7 @@ module FFI_Yajl
if token.respond_to?(:scrub)
token.scrub!
else
- token.encode!("UTF-16le", undef: :replace, invalid: :replace).encode!('UTF-8')
+ token.encode!("UTF-16le", undef: :replace, invalid: :replace).encode!("UTF-8")
end
case status
when 1 # yajl_gen_keys_must_be_strings
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..7211c79 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
@@ -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..f35f3c4 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
@@ -73,7 +73,7 @@ class Hash
end
else
if ( status = FFI_Yajl.yajl_gen_map_open(yajl_gen) ) != 0
- FFI_Yajl::Encoder.raise_error_for_status(status, '{')
+ FFI_Yajl::Encoder.raise_error_for_status(status, "{")
end
each do |key, value|
# Perf Fix: mutate state hash rather than creating new copy
@@ -83,7 +83,7 @@ class Hash
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, '}')
+ FFI_Yajl::Encoder.raise_error_for_status(status, "}")
end
end
end
@@ -98,13 +98,13 @@ class Array
end
else
if ( status = FFI_Yajl.yajl_gen_array_open(yajl_gen) ) != 0
- FFI_Yajl::Encoder.raise_error_for_status(status, '[')
+ 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, ']')
+ FFI_Yajl::Encoder.raise_error_for_status(status, "]")
end
end
end
@@ -155,7 +155,7 @@ class FalseClass
end
end
-class Fixnum
+class Integer
def ffi_yajl(yajl_gen, state)
str = to_s
if str == "NaN" || str == "Infinity" || str == "-Infinity"
@@ -173,7 +173,7 @@ class Fixnum
end
end
-class Bignum
+class Integer
def ffi_yajl(yajl_gen, state)
str = to_s
if str == "NaN" || str == "Infinity" || str == "-Infinity"
@@ -265,7 +265,7 @@ end
# I feel dirty
class Object
def ffi_yajl(yajl_gen, state)
- if !state[:processing_key] && self.respond_to?(:to_json)
+ if !state[:processing_key] && respond_to?(:to_json)
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)
diff --git a/lib/ffi_yajl/ffi/parser.rb b/lib/ffi_yajl/ffi/parser.rb
index 67df934..7c98d59 100644
--- a/lib/ffi_yajl/ffi/parser.rb
+++ b/lib/ffi_yajl/ffi/parser.rb
@@ -65,7 +65,7 @@ module FFI_Yajl
end
@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
set_value(v)
@@ -77,7 +77,7 @@ module FFI_Yajl
end
@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
@@ -88,7 +88,7 @@ module FFI_Yajl
end
@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
@@ -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..6ec3c0c 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
@@ -103,7 +103,7 @@ module FFI_Yajl
rescue LoadError
end
end
- ffi_lib 'yajl' unless found
+ ffi_lib "yajl" unless found
end
end
end
diff --git a/lib/ffi_yajl/parser.rb b/lib/ffi_yajl/parser.rb
index 6029691..2f1dbf7 100644
--- a/lib/ffi_yajl/parser.rb
+++ b/lib/ffi_yajl/parser.rb
@@ -65,10 +65,10 @@ module FFI_Yajl
raise ArgumentError, "options check_utf8 and dont_validate_strings are both true which conflict"
end
- yajl_opts[:yajl_allow_comments] = true
+ yajl_opts[:yajl_allow_comments] = true
if @opts.key?(:allow_comments)
- yajl_opts[:yajl_allow_comments] = @opts[:allow_comments]
+ yajl_opts[:yajl_allow_comments] = @opts[:allow_comments]
end
yajl_opts[:yajl_dont_validate_strings] = (@opts[:check_utf8] == false || @opts[:dont_validate_strings])
diff --git a/spec/ffi_yajl/encoder_spec.rb b/spec/ffi_yajl/encoder_spec.rb
index 724277b..7a76c0a 100644
--- a/spec/ffi_yajl/encoder_spec.rb
+++ b/spec/ffi_yajl/encoder_spec.rb
@@ -21,8 +21,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 'spec_helper'
-require 'date'
+require "spec_helper"
+require "date"
describe "FFI_Yajl::Encoder" do
let(:options) { {} }
@@ -30,7 +30,7 @@ describe "FFI_Yajl::Encoder" do
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
@@ -126,23 +126,23 @@ describe "FFI_Yajl::Encoder" do
end
it "can encode Date objects" do
- ruby = Date.parse('2001-02-03')
+ ruby = Date.parse("2001-02-03")
expect(encoder.encode(ruby)).to eq( '"2001-02-03"' )
end
it "can encode StringIOs" do
- ruby = { "foo" => StringIO.new('THING') }
+ ruby = { "foo" => StringIO.new("THING") }
expect(encoder.encode(ruby)).to eq("{\"foo\":\"THING\"}")
end
context "when encoding Time objects in UTC timezone" do
before do
- @saved_tz = ENV['TZ']
- ENV['TZ'] = 'UTC'
+ @saved_tz = ENV["TZ"]
+ ENV["TZ"] = "UTC"
end
after do
- ENV['TZ'] = @saved_tz
+ ENV["TZ"] = @saved_tz
end
it "encodes them correctly" do
@@ -152,7 +152,7 @@ describe "FFI_Yajl::Encoder" do
end
it "can encode DateTime objects" do
- ruby = DateTime.parse('2001-02-03T04:05:06.1+07:00')
+ ruby = DateTime.parse("2001-02-03T04:05:06.1+07:00")
expect(encoder.encode(ruby)).to eq( '"2001-02-03T04:05:06+07:00"' )
end
@@ -191,7 +191,7 @@ describe "FFI_Yajl::Encoder" do
end
context "when validate_utf8 is off" do
- let(:options) { { validate_utf8: false } }
+ let(:options) { { validate_utf8: false } }
it "does not raise an error" do
expect { encoder.encode(ruby) }.not_to raise_error
diff --git a/spec/ffi_yajl/map_library_name_spec.rb b/spec/ffi_yajl/map_library_name_spec.rb
index 0b5e9cb..b16483f 100644
--- a/spec/ffi_yajl/map_library_name_spec.rb
+++ b/spec/ffi_yajl/map_library_name_spec.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 'spec_helper'
+require "spec_helper"
class Test
extend FFI_Yajl::MapLibraryName
@@ -107,7 +107,7 @@ describe "FFI_Yajl::MapLibraryName" do
allow(File).to receive(:file?).with(path).and_return(true)
allow(Test).to receive(:ffi_lib).with(path).and_raise(LoadError)
end
- allow(Test).to receive(:ffi_lib).with('yajl').and_return(nil)
+ allow(Test).to receive(:ffi_lib).with("yajl").and_return(nil)
Test.send(:ffi_open_yajl_library)
end
end
diff --git a/spec/ffi_yajl/parser_spec.rb b/spec/ffi_yajl/parser_spec.rb
index 750567f..be392c8 100644
--- a/spec/ffi_yajl/parser_spec.rb
+++ b/spec/ffi_yajl/parser_spec.rb
@@ -21,12 +21,12 @@
# 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 'spec_helper'
+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}' }
+ let(:json) { '{"key": 23456789012E666}' }
it "should return infinity" do
infinity = (1.0 / 0)
@@ -271,10 +271,10 @@ describe "FFI_Yajl::Parser" do
Encoding.default_internal = @saved_encoding
end
it "encodes keys to UTF-8" do
- expect(parser.keys.first.encoding).to eql(Encoding.find('utf-8'))
+ expect(parser.keys.first.encoding).to eql(Encoding.find("utf-8"))
end
it "encodes values to UTF-8" do
- expect(parser.values.first.encoding).to eql(Encoding.find('utf-8'))
+ expect(parser.values.first.encoding).to eql(Encoding.find("utf-8"))
end
end
@@ -349,7 +349,7 @@ describe "FFI_Yajl::Parser" do
# NOTE: we are choosing to be compatible with yajl-ruby here vs. JSON
# gem and libyajl C behavior (which is to throw an exception in this case)
context "when the JSON is empty string" do
- let(:json) { '' }
+ let(:json) { "" }
it "returns nil" do
expect(parser).to be_nil
@@ -475,7 +475,7 @@ describe "FFI_Yajl::Parser" do
# NOTE: parsing floats with 8 million digits on windows has some kind of huge
# perf issues likely in ruby and/or the underlying windows libs
context "when parsing big floats", ruby_gte_193: true, unix_only: true do
- let(:json) { '[0.' + '1' * 2**23 + ']' }
+ let(:json) { "[0." + "1" * 2**23 + "]" }
it "parses" do
expect { parser }.not_to raise_error
@@ -483,7 +483,7 @@ describe "FFI_Yajl::Parser" do
end
context "when parsing long hash keys with symbolize_keys option", ruby_gte_193: true do
- let(:json) { '{"' + 'a' * 2**23 + '": 0}' }
+ let(:json) { '{"' + "a" * 2**23 + '": 0}' }
let(:options) { { symbolize_keys: true } }
it "parses" do
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index 9ec853d..48e2de5 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -26,18 +26,18 @@ $LOAD_PATH << File.expand_path(File.join(File.dirname( __FILE__ ), "../lib"))
# linked in the same process). this should work, see:
# http://stackoverflow.com/questions/3232822/linking-with-multiple-versions-of-a-library
begin
- require 'yajl'
+ require "yajl"
rescue LoadError
- puts 'WARN: yajl cannot be loaded, expected if this is jruby'
+ puts "WARN: yajl cannot be loaded, expected if this is jruby"
end
-require 'ffi_yajl'
+require "ffi_yajl"
RSpec.configure do |conf|
conf.filter_run_excluding unix_only: true unless RUBY_PLATFORM !~ /mswin|mingw|windows/
conf.filter_run_excluding ruby_gte_193: true unless RUBY_VERSION.to_f >= 2.0 || RUBY_VERSION =~ /^1\.9\.3/
- conf.order = 'random'
+ conf.order = "random"
conf.expect_with :rspec do |rspec|
rspec.syntax = :expect