diff options
author | Lamont Granquist <lamont@scriptkiddie.org> | 2015-07-09 08:45:46 -0700 |
---|---|---|
committer | Lamont Granquist <lamont@scriptkiddie.org> | 2015-07-09 08:45:46 -0700 |
commit | c1e912caf966bc29b346c193f1b74e23e0f66781 (patch) | |
tree | 70ddb27b5d8f32766e89fe6b86375373daedf013 | |
parent | 8fabdd3fddbd222109976fddb0d38255a9490f1d (diff) | |
download | ffi-yajl-c1e912caf966bc29b346c193f1b74e23e0f66781.tar.gz |
remaining autofixable cops
-rw-r--r-- | .rubocop.yml | 8 | ||||
-rw-r--r-- | Rakefile | 8 | ||||
-rw-r--r-- | ext/ffi_yajl/ext/encoder/extconf.rb | 2 | ||||
-rw-r--r-- | ext/ffi_yajl/ext/parser/extconf.rb | 2 | ||||
-rw-r--r-- | ffi-yajl-universal-java.gemspec | 2 | ||||
-rw-r--r-- | ffi-yajl.gemspec | 2 | ||||
-rw-r--r-- | lib/ffi_yajl/benchmark/encode.rb | 16 | ||||
-rw-r--r-- | lib/ffi_yajl/benchmark/parse.rb | 17 | ||||
-rw-r--r-- | lib/ffi_yajl/encoder.rb | 2 | ||||
-rw-r--r-- | lib/ffi_yajl/ffi.rb | 22 | ||||
-rw-r--r-- | lib/ffi_yajl/ffi/encoder.rb | 8 | ||||
-rw-r--r-- | lib/ffi_yajl/ffi/parser.rb | 48 | ||||
-rw-r--r-- | lib/ffi_yajl/parser.rb | 8 |
13 files changed, 72 insertions, 73 deletions
diff --git a/.rubocop.yml b/.rubocop.yml index 47de329..170fc40 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -31,7 +31,13 @@ ModuleLength: PerceivedComplexity: Enabled: false PercentLiteralDelimiters: - Enabled: false + PreferredDelimiters: + '%': '{}' + '%q': '{}' + '%Q': '{}' + '%w': '{}' + '%W': '{}' + '%x': '{}' RegexpLiteral: Enabled: false SignalException: @@ -5,7 +5,7 @@ require 'rubygems/package_task' require 'rake/extensiontask' require 'ffi_yajl/version' -Dir[File.expand_path("../*gemspec", __FILE__)].reverse.each do |gemspec_path| +Dir[File.expand_path("../*gemspec", __FILE__)].reverse_each do |gemspec_path| gemspec = eval(IO.read(gemspec_path)) Gem::PackageTask.new(gemspec).define end @@ -14,7 +14,7 @@ desc "Build it and ship it" task :ship => [:clean, :gem] do sh("git tag #{FFI_Yajl::VERSION}") sh("git push --tags") - Dir[File.expand_path("../pkg/*.gem", __FILE__)].reverse.each do |built_gem| + Dir[File.expand_path("../pkg/*.gem", __FILE__)].reverse_each do |built_gem| sh("gem push #{built_gem}") end end @@ -138,7 +138,7 @@ if RUBY_VERSION.to_f >= 1.9 else Reek::Rake::Task.new(:reek) do |t| t.fail_on_error = false -# t.config_files = '.reek.yml' + # t.config_files = '.reek.yml' end end end @@ -165,7 +165,7 @@ desc 'Run all style checks' task :style => ['style:rubocop', 'style:reek'] desc 'Run style + spec tests by default on travis' -task :travis => ['style', 'spec'] +task :travis => %w{style spec} desc 'Run style, spec and test kichen on travis' task :travis_all => ['style', 'spec', 'integration:cloud'] diff --git a/ext/ffi_yajl/ext/encoder/extconf.rb b/ext/ffi_yajl/ext/encoder/extconf.rb index 0281ea4..e46080a 100644 --- a/ext/ffi_yajl/ext/encoder/extconf.rb +++ b/ext/ffi_yajl/ext/encoder/extconf.rb @@ -55,7 +55,7 @@ if !windows? && !find_header('yajl/yajl_tree.h') dir_config('yajl', HEADER_DIRS, LIB_DIRS) # here we use find_library in order to deliberately link with -lyajl as a useful side-effect - if !(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 diff --git a/ext/ffi_yajl/ext/parser/extconf.rb b/ext/ffi_yajl/ext/parser/extconf.rb index 26bdca0..6f8526e 100644 --- a/ext/ffi_yajl/ext/parser/extconf.rb +++ b/ext/ffi_yajl/ext/parser/extconf.rb @@ -55,7 +55,7 @@ if !windows? && !find_header('yajl/yajl_tree.h') dir_config('yajl', HEADER_DIRS, LIB_DIRS) # here we use find_library in order to deliberately link with -lyajl as a useful side-effect - if !(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 diff --git a/ffi-yajl-universal-java.gemspec b/ffi-yajl-universal-java.gemspec index 4df0326..9e8f670 100644 --- a/ffi-yajl-universal-java.gemspec +++ b/ffi-yajl-universal-java.gemspec @@ -4,7 +4,7 @@ gemspec.platform = "universal-java" # XXX: after the libyajl2-gem, we don't need to fork the # extensions so can we simplify the gemspecs now? -#gemspec.extensions = %w{ ext/libyajl2/extconf.rb } +# gemspec.extensions = %w{ ext/libyajl2/extconf.rb } gemspec.add_runtime_dependency "ffi", "~> 1.5" diff --git a/ffi-yajl.gemspec b/ffi-yajl.gemspec index 03086fd..83af1f6 100644 --- a/ffi-yajl.gemspec +++ b/ffi-yajl.gemspec @@ -1,7 +1,7 @@ gemspec = eval(IO.read(File.expand_path(File.join(File.dirname(__FILE__), "ffi-yajl.gemspec.shared")))) gemspec.platform = Gem::Platform::RUBY -gemspec.extensions = %w{ ext/ffi_yajl/ext/encoder/extconf.rb ext/ffi_yajl/ext/parser/extconf.rb ext/ffi_yajl/ext/dlopen/extconf.rb } +gemspec.extensions = %w{ext/ffi_yajl/ext/encoder/extconf.rb ext/ffi_yajl/ext/parser/extconf.rb ext/ffi_yajl/ext/dlopen/extconf.rb} gemspec.add_development_dependency "ffi", "~> 1.5" diff --git a/lib/ffi_yajl/benchmark/encode.rb b/lib/ffi_yajl/benchmark/encode.rb index 5b7dbb1..eda4fe7 100644 --- a/lib/ffi_yajl/benchmark/encode.rb +++ b/lib/ffi_yajl/benchmark/encode.rb @@ -43,7 +43,7 @@ module FFI_Yajl class Benchmark class Encode def run - #filename = ARGV[0] || 'benchmark/subjects/ohai.json' + # 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) } @@ -123,13 +123,13 @@ module FFI_Yajl } end end -# if defined?(ActiveSupport::JSON) -# x.report("ActiveSupport::JSON.encode") { -# times.times { -# ActiveSupport::JSON.encode(hash) -# } -# } -# end + # if defined?(ActiveSupport::JSON) + # x.report("ActiveSupport::JSON.encode") { + # times.times { + # ActiveSupport::JSON.encode(hash) + # } + # } + # end } end end diff --git a/lib/ffi_yajl/benchmark/parse.rb b/lib/ffi_yajl/benchmark/parse.rb index ce22147..7e1f3a6 100644 --- a/lib/ffi_yajl/benchmark/parse.rb +++ b/lib/ffi_yajl/benchmark/parse.rb @@ -48,14 +48,14 @@ class FFI_Yajl::Benchmark::Parse FFI_Yajl::Parser.parse(json_str) } } -# ffi_parser = FFI_Yajl::Parser.new -# x.report { -# puts "FFI_Yajl::Parser#parse (from a String)" -# times.times { -# json.rewind -# ffi_parser.parse(json.read) -# } -# } + # ffi_parser = FFI_Yajl::Parser.new + # x.report { + # puts "FFI_Yajl::Parser#parse (from a String)" + # times.times { + # json.rewind + # ffi_parser.parse(json.read) + # } + # } if defined?(Yajl::Parser) x.report { puts "Yajl::Parser.parse (from a String)" @@ -139,6 +139,5 @@ class FFI_Yajl::Benchmark::Parse end } json.close - end end diff --git a/lib/ffi_yajl/encoder.rb b/lib/ffi_yajl/encoder.rb index a678221..9f2e564 100644 --- a/lib/ffi_yajl/encoder.rb +++ b/lib/ffi_yajl/encoder.rb @@ -54,7 +54,7 @@ module FFI_Yajl @opts ||= {} end - def self.raise_error_for_status(status, token=nil) + def self.raise_error_for_status(status, token = nil) # scrub token to valid utf-8 since we may be issuing an exception on an invalid utf-8 token token = token.to_s.encode("utf-8", "binary", :undef => :replace) case status diff --git a/lib/ffi_yajl/ffi.rb b/lib/ffi_yajl/ffi.rb index 094c51d..3b83bae 100644 --- a/lib/ffi_yajl/ffi.rb +++ b/lib/ffi_yajl/ffi.rb @@ -61,16 +61,16 @@ module FFI_Yajl :yajl_status_error, ] -# FFI::Enums are slow, should remove the rest -# enum :yajl_gen_status, [ -# :yajl_gen_status_ok, -# :yajl_gen_keys_must_be_strings, -# :yajl_max_depth_exceeded, -# :yajl_gen_in_error_state, -# :yajl_gen_generation_complete, -# :yajl_gen_invalid_number, -# :yajl_gen_no_buf, -# ] + # FFI::Enums are slow, should remove the rest + # enum :yajl_gen_status, [ + # :yajl_gen_status_ok, + # :yajl_gen_keys_must_be_strings, + # :yajl_max_depth_exceeded, + # :yajl_gen_in_error_state, + # :yajl_gen_generation_complete, + # :yajl_gen_invalid_number, + # :yajl_gen_no_buf, + # ] enum :yajl_option, [ :yajl_allow_comments, 0x01, @@ -132,7 +132,7 @@ 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 diff --git a/lib/ffi_yajl/ffi/encoder.rb b/lib/ffi_yajl/ffi/encoder.rb index 94588d0..250ed68 100644 --- a/lib/ffi_yajl/ffi/encoder.rb +++ b/lib/ffi_yajl/ffi/encoder.rb @@ -27,7 +27,7 @@ module FFI_Yajl module FFI module Encoder def do_yajl_encode(obj, yajl_gen_opts, opts) - yajl_gen = FFI_Yajl.yajl_gen_alloc(nil); + yajl_gen = FFI_Yajl.yajl_gen_alloc(nil) # configure the yajl encoder if yajl_gen_opts[:yajl_gen_beautify] @@ -58,7 +58,7 @@ module FFI_Yajl FFI_Yajl.yajl_gen_free(yajl_gen) - return string + string end end end @@ -273,8 +273,6 @@ class Object str = to_s status = FFI_Yajl.yajl_gen_string(yajl_gen, str, str.bytesize) end - if ( status ) != 0 - FFI_Yajl::Encoder.raise_error_for_status(status, str) - end + 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 d0d152a..e3226c0 100644 --- a/lib/ffi_yajl/ffi/parser.rb +++ b/lib/ffi_yajl/ffi/parser.rb @@ -23,34 +23,32 @@ module FFI_Yajl module FFI module Parser - def set_value(val) - case stack.last - when Hash - raise FFI_Yajl::ParseError.new("internal error: missing key in parse") if key.nil? - if @opts[:unique_key_checking] && stack.last.has_key?(key) - raise FFI_Yajl::ParseError.new("repeated key: #{key}") - end - stack.last[key] = val - when Array - stack.last.push(val) - else - stack.push(val) + def set_value(val) + case stack.last + when Hash + raise FFI_Yajl::ParseError.new("internal error: missing key in parse") if key.nil? + if @opts[:unique_key_checking] && stack.last.key?(key) + raise FFI_Yajl::ParseError.new("repeated key: #{key}") end + stack.last[key] = val + when Array + stack.last.push(val) + else + stack.push(val) end + end - def stack_pop - if stack.length > 1 - set_value( stack.pop ) - end - end + def stack_pop + set_value( stack.pop ) if stack.length > 1 + end - def key_push - key_stack.push(key) - end + def key_push + key_stack.push(key) + end - def key_pop - @key = key_stack.pop - end + def key_pop + @key = key_stack.pop + end def setup_callbacks @null_callback = ::FFI::Function.new(:int, [:pointer]) do |ctx| @@ -85,7 +83,7 @@ module FFI_Yajl end @start_map_callback = ::FFI::Function.new(:int, [:pointer]) do |ctx| key_push # for key => { } case, save the key - stack.push(Hash.new) + stack.push({}) 1 end @map_key_callback = ::FFI::Function.new(:int, [:pointer, :string, :size_t]) do |ctx, key, keylen| @@ -101,7 +99,7 @@ module FFI_Yajl end @start_array_callback = ::FFI::Function.new(:int, [:pointer]) do |ctx| key_push # for key => [ ] case, save the key - stack.push(Array.new) + stack.push([]) 1 end @end_array_callback = ::FFI::Function.new(:int, [:pointer]) do |ctx| diff --git a/lib/ffi_yajl/parser.rb b/lib/ffi_yajl/parser.rb index da9b704..6029691 100644 --- a/lib/ffi_yajl/parser.rb +++ b/lib/ffi_yajl/parser.rb @@ -32,14 +32,14 @@ module FFI_Yajl # stack used to build up our complex object # def stack - @stack ||= Array.new + @stack ||= [] end # # stack to keep track of keys as we create nested hashes # def key_stack - @key_stack ||= Array.new + @key_stack ||= [] end def self.parse(obj, *args) @@ -81,9 +81,7 @@ module FFI_Yajl # XXX: bug-compat with ruby-yajl return nil if str == "" - if str.respond_to?(:read) - str = str.read - end + str = str.read if str.respond_to?(:read) # call either the ext or ffi hook do_yajl_parse(str, yajl_opts) |