Skip to content

Commit

Permalink
Revert "Add frozen_string_literal to all files and some static code c…
Browse files Browse the repository at this point in the history
…leanup"

This reverts commit 62dd7b3.
  • Loading branch information
geophilusd committed May 23, 2022
1 parent 62dd7b3 commit 9e861c7
Show file tree
Hide file tree
Showing 45 changed files with 475 additions and 482 deletions.
4 changes: 1 addition & 3 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
# frozen_string_literal: true

source 'https://rubygems.org'

gem 'rake', require: false
gem 'rspec', '~> 3.0'

group :docs do
gem 'rdiscount', require: false
gem 'yard'
gem 'yard-sitemap', '~> 1.0'
gem 'rdiscount', require: false
end

group :release do
Expand Down
4 changes: 1 addition & 3 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# frozen_string_literal: true

$GEM_ROOT = File.dirname(__FILE__)

$LOAD_PATH << File.join($GEM_ROOT, 'lib')
$: << File.join($GEM_ROOT, 'lib')

$VERSION = ENV['VERSION'] || File.read(File.join($GEM_ROOT, 'VERSION'))
$GITHUB_ACCESS_TOKEN = ENV['JMESPATH_GITHUB_ACCESS_TOKEN']
Expand Down
5 changes: 2 additions & 3 deletions bin/jmespath.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
$:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))

require 'jmespath'
require 'json'

expression = ARGV[0]
json = JSON.parse($stdin.read)
json = JSON.parse(STDIN.read)

$stdout.puts(JSON.dump(JMESPath.search(expression, json)))
4 changes: 1 addition & 3 deletions gemfiles/json-latest.gemfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# frozen_string_literal: true

eval_gemfile(File.expand_path('../Gemfile', __dir__))
eval_gemfile(File.expand_path('../../Gemfile', __FILE__))

gem 'json'
4 changes: 1 addition & 3 deletions gemfiles/json-old.gemfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# frozen_string_literal: true

eval_gemfile(File.expand_path('../Gemfile', __dir__))
eval_gemfile(File.expand_path('../../Gemfile', __FILE__))

gem 'json', '< 2.0'
4 changes: 1 addition & 3 deletions gemfiles/json-pure.gemfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# frozen_string_literal: true

eval_gemfile(File.expand_path('../Gemfile', __dir__))
eval_gemfile(File.expand_path('../../Gemfile', __FILE__))

gem 'json_pure', require: 'json/pure'
4 changes: 1 addition & 3 deletions gemfiles/no-deps.gemfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# frozen_string_literal: true

eval_gemfile(File.expand_path('../Gemfile', __dir__))
eval_gemfile(File.expand_path('../../Gemfile', __FILE__))

# no dependency on `json` gem
4 changes: 1 addition & 3 deletions jmespath.gemspec
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# frozen_string_literal: true

Gem::Specification.new do |spec|
spec.name = 'jmespath'
spec.version = File.read(File.expand_path('VERSION', __dir__)).strip
spec.version = File.read(File.expand_path('../VERSION', __FILE__)).strip
spec.summary = 'JMESPath - Ruby Edition'
spec.description = 'Implements JMESPath for Ruby'
spec.author = 'Trevor Rowe'
Expand Down
17 changes: 9 additions & 8 deletions lib/jmespath.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
# frozen_string_literal: true

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

module JMESPath

require 'jmespath/caching_parser'
require 'jmespath/errors'
require 'jmespath/lexer'
Expand All @@ -17,24 +16,26 @@ module JMESPath
require 'jmespath/version'

class << self

# @param [String] expression A valid
# [JMESPath](https://github.com/boto/jmespath) expression.
# @param [Hash] data
# @return [Mixed,nil] Returns the matched values. Returns `nil` if the
# expression does not resolve inside `data`.
def search(expression, data, runtime_options = {})
data = case data
when Hash, Struct then data # check for most common case first
when Pathname then load_json(data)
when IO, StringIO then JSON.parse(data.read)
else data
end
when Hash, Struct then data # check for most common case first
when Pathname then load_json(data)
when IO, StringIO then JSON.parse(data.read)
else data
end
Runtime.new(runtime_options).search(expression, data)
end

# @api private
def load_json(path)
JSON.parse(File.open(path, 'r', encoding: 'UTF-8', &:read))
JSON.parse(File.open(path, 'r', encoding: 'UTF-8') { |f| f.read })
end

end
end
4 changes: 3 additions & 1 deletion lib/jmespath/caching_parser.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# frozen_string_literal: true
require 'thread'

module JMESPath
class CachingParser

def initialize(options = {})
@parser = options[:parser] || Parser.new(options)
@mutex = Mutex.new
Expand All @@ -24,5 +25,6 @@ def cache_expression(expression)
@cache[expression] = @parser.parse(expression)
end
end

end
end
4 changes: 2 additions & 2 deletions lib/jmespath/errors.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# frozen_string_literal: true

module JMESPath
module Errors

class Error < StandardError; end

class RuntimeError < Error; end
Expand All @@ -15,5 +14,6 @@ class InvalidValueError < Error; end
class InvalidArityError < Error; end

class UnknownFunctionError < Error; end

end
end
Loading

0 comments on commit 9e861c7

Please sign in to comment.