Skip to content
This repository has been archived by the owner on Sep 19, 2020. It is now read-only.

Switch from yajl-ruby to ffi-yajl #650

Merged
merged 3 commits into from
Jul 9, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion foodcritic.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Gem::Specification.new do |s|
s.add_dependency("nokogiri", ">= 1.5", "< 2.0")
s.add_dependency("rake")
s.add_dependency("treetop", "~> 1.4")
s.add_dependency("yajl-ruby", "~> 1.1")
s.add_dependency("ffi-yajl", "~> 2.0")
s.add_dependency("erubis")
s.add_dependency("rufus-lru", "~> 1.0")

Expand Down
2 changes: 1 addition & 1 deletion lib/foodcritic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
require "cucumber/core"
require "treetop"
require "ripper"
require "yajl"
require "ffi_yajl"
require "erubis"

require_relative "foodcritic/chef"
Expand Down
5 changes: 2 additions & 3 deletions lib/foodcritic/api.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
require "nokogiri"
require "rufus-lru"
require "json"

module FoodCritic
# Helper methods that form part of the Rules DSL.
Expand Down Expand Up @@ -424,8 +423,8 @@ def json_file_to_hash(filename)

file = File.read(filename)
begin
JSON.parse(file)
rescue RuntimeError
FFI_Yajl::Parser.parse(file)
rescue FFI_Yajl::ParseError
raise "File #{filename} does not appear to contain valid JSON"
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/foodcritic/chef.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def load_metadata
Linter::DEFAULT_CHEF_VERSION].map do |version|
metadata_path(version)
end.find { |m| File.exist?(m) }
@dsl_metadata ||= Yajl::Parser.parse(IO.read(metadata_path),
@dsl_metadata ||= FFI_Yajl::Parser.parse(IO.read(metadata_path),
symbolize_keys: true)
end

Expand Down
2 changes: 1 addition & 1 deletion spec/unit/api_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1928,7 +1928,7 @@ def template_ast(content)
it "raises if the json is not valid" do
expect(::File).to receive(:exist?).with("/some/path/with/a/file").and_return(true)
allow(File).to receive(:read).with("/some/path/with/a/file").and_return("I am bogus data")
expect { api.json_file_to_hash("/some/path/with/a/file") }.to raise_error JSON::ParserError
expect { api.json_file_to_hash("/some/path/with/a/file") }.to raise_error RuntimeError
end
end

Expand Down