Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove json pure gem #35

Merged
merged 2 commits into from
Jul 6, 2016
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
Unreleased Changes
------------------

* Removed depdendency on `pure_json` gem. Necessary code changes have been
made to ensure things work properly with Ruby 1.9.3 and JSON 1.5.5.

* Bug-fix for Ruby 2.3. JMESPath requires sort and sort_by functions to be stable.
There was a persistent test failure in Ruby 2.3 due to an unstable sort.

Expand Down
3 changes: 1 addition & 2 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
source 'https://rubygems.org'

gem 'rake', require: false
gem 'json_pure', '>= 1.8.1'

group :test do
gem 'rspec', '~> 3.0'
gem 'simplecov'
gem 'simplecov' unless RUBY_VERSION == '1.9.3'
end

group :docs do
Expand Down
1 change: 0 additions & 1 deletion jmespath.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,4 @@ Gem::Specification.new do |spec|
spec.license = 'Apache 2.0'
spec.require_paths = ['lib']
spec.files = Dir['lib/**/*.rb'] + ['LICENSE.txt']
spec.add_runtime_dependency 'json_pure', '>= 1.8.1'
end
16 changes: 1 addition & 15 deletions lib/jmespath.rb
Original file line number Diff line number Diff line change
@@ -1,18 +1,4 @@
if Object.const_defined?(:JSON) && JSON::VERSION < '1.8.1'
warn("WARNING: jmespath gem requires json gem >= 1.8.1; json #{JSON::VERSION} already loaded")
else
begin
# Attempt to load the native version if available, not availble
# by default for Ruby 1.9.3.
gem('json', '>= 1.8.1')
require 'json'
rescue Gem::LoadError
# Fallback on the json_pure gem dependency.
gem('json_pure', '>= 1.8.1')
require 'json'
end
end

require 'json'
require 'stringio'
require 'pathname'

Expand Down
23 changes: 17 additions & 6 deletions lib/jmespath/lexer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -295,13 +295,24 @@ def inside(chars, delim, type)
Token.new(type, buffer.join, position)
end

def parse_json(token)
begin
token.value = JSON.load(token.value)
rescue JSON::ParserError
token.type = T_UNKNOWN
if RUBY_VERSION.match(Regexp.escape('1.9.3'))
def parse_json(token)
begin
token.value = JSON.load("{\"value\":#{token.value}}")['value']
rescue JSON::ParserError
token.type = T_UNKNOWN
end
token
end
else
def parse_json(token)
begin
token.value = JSON.load(token.value)
rescue JSON::ParserError
token.type = T_UNKNOWN
end
token
end
token
end

class CharacterStream
Expand Down
2 changes: 1 addition & 1 deletion lib/jmespath/nodes/function.rb
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ class ToStringFunction < Function
def call(args)
if args.count == 1
value = args.first
String === value ? value : JSON.dump(value)
String === value ? value : value.to_json
else
return maybe_raise Errors::InvalidArityError, "function to_string() expects one argument"
end
Expand Down
2 changes: 1 addition & 1 deletion lib/jmespath/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def parse(expression)

# @api private
def method_missing(method_name, *args)
if matches = method_name.match(/^(nud_|led_)(.*)/)
if matches = method_name.to_s.match(/^(nud_|led_)(.*)/)
raise Errors::SyntaxError, "unexpected token #{matches[2]}"
else
super
Expand Down
14 changes: 8 additions & 6 deletions spec/compliance_spec.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
require 'simplecov'
require 'jmespath'
require 'rspec'

SimpleCov.command_name('test:compliance')
begin
require 'simplecov'
SimpleCov.command_name('test:compliance')
rescue LoadError
end
require 'jmespath'

describe 'Compliance' do
Dir.glob('spec/compliance/*.json').each do |path|
Expand All @@ -13,7 +15,7 @@

describe(test_file) do
JMESPath.load_json(path).each do |scenario|
describe("Given #{JSON.dump(scenario['given'])}") do
describe("Given #{scenario['given'].to_json}") do
scenario['cases'].each do |test_case|

if test_case['error']
Expand Down Expand Up @@ -42,7 +44,7 @@

else

it "searching #{test_case['expression'].inspect} returns #{JSON.dump(test_case['result'])}" do
it "searching #{test_case['expression'].inspect} returns #{test_case['result'].to_json}" do
result = JMESPath.search(test_case['expression'], scenario['given'])
expect(result).to eq(test_case['result'])
end
Expand Down
10 changes: 6 additions & 4 deletions spec/compliance_without_errors_spec.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
require 'simplecov'
require 'jmespath'
require 'rspec'

SimpleCov.command_name('test:compliance')
begin
require 'simplecov'
SimpleCov.command_name('test:compliance')
rescue LoadError
end
require 'jmespath'

describe 'Compliance' do
PARSER = JMESPath::Parser.new(:disable_visit_errors => true)
Expand Down
10 changes: 6 additions & 4 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
require 'simplecov'
require 'jmespath'
require 'rspec'

SimpleCov.command_name('test:unit')
begin
require 'simplecov'
SimpleCov.command_name('test:unit')
rescue LoadError
end
require 'jmespath'