Skip to content

Commit 9e861c7

Browse files
author
Geophilus Durairaj
committed
Revert "Add frozen_string_literal to all files and some static code cleanup"
This reverts commit 62dd7b3.
1 parent 62dd7b3 commit 9e861c7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+475
-482
lines changed

Gemfile

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
1-
# frozen_string_literal: true
2-
31
source 'https://rubygems.org'
42

53
gem 'rake', require: false
64
gem 'rspec', '~> 3.0'
75

86
group :docs do
9-
gem 'rdiscount', require: false
107
gem 'yard'
118
gem 'yard-sitemap', '~> 1.0'
9+
gem 'rdiscount', require: false
1210
end
1311

1412
group :release do

Rakefile

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
# frozen_string_literal: true
2-
31
$GEM_ROOT = File.dirname(__FILE__)
42

5-
$LOAD_PATH << File.join($GEM_ROOT, 'lib')
3+
$: << File.join($GEM_ROOT, 'lib')
64

75
$VERSION = ENV['VERSION'] || File.read(File.join($GEM_ROOT, 'VERSION'))
86
$GITHUB_ACCESS_TOKEN = ENV['JMESPATH_GITHUB_ACCESS_TOKEN']

bin/jmespath.rb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
#!/usr/bin/env ruby
2-
# frozen_string_literal: true
32

4-
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3+
$:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
54

65
require 'jmespath'
76
require 'json'
87

98
expression = ARGV[0]
10-
json = JSON.parse($stdin.read)
9+
json = JSON.parse(STDIN.read)
1110

1211
$stdout.puts(JSON.dump(JMESPath.search(expression, json)))

gemfiles/json-latest.gemfile

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# frozen_string_literal: true
2-
3-
eval_gemfile(File.expand_path('../Gemfile', __dir__))
1+
eval_gemfile(File.expand_path('../../Gemfile', __FILE__))
42

53
gem 'json'

gemfiles/json-old.gemfile

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# frozen_string_literal: true
2-
3-
eval_gemfile(File.expand_path('../Gemfile', __dir__))
1+
eval_gemfile(File.expand_path('../../Gemfile', __FILE__))
42

53
gem 'json', '< 2.0'

gemfiles/json-pure.gemfile

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# frozen_string_literal: true
2-
3-
eval_gemfile(File.expand_path('../Gemfile', __dir__))
1+
eval_gemfile(File.expand_path('../../Gemfile', __FILE__))
42

53
gem 'json_pure', require: 'json/pure'

gemfiles/no-deps.gemfile

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# frozen_string_literal: true
2-
3-
eval_gemfile(File.expand_path('../Gemfile', __dir__))
1+
eval_gemfile(File.expand_path('../../Gemfile', __FILE__))
42

53
# no dependency on `json` gem

jmespath.gemspec

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
# frozen_string_literal: true
2-
31
Gem::Specification.new do |spec|
42
spec.name = 'jmespath'
5-
spec.version = File.read(File.expand_path('VERSION', __dir__)).strip
3+
spec.version = File.read(File.expand_path('../VERSION', __FILE__)).strip
64
spec.summary = 'JMESPath - Ruby Edition'
75
spec.description = 'Implements JMESPath for Ruby'
86
spec.author = 'Trevor Rowe'

lib/jmespath.rb

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
# frozen_string_literal: true
2-
31
require 'json'
42
require 'stringio'
53
require 'pathname'
64

75
module JMESPath
6+
87
require 'jmespath/caching_parser'
98
require 'jmespath/errors'
109
require 'jmespath/lexer'
@@ -17,24 +16,26 @@ module JMESPath
1716
require 'jmespath/version'
1817

1918
class << self
19+
2020
# @param [String] expression A valid
2121
# [JMESPath](https://github.com/boto/jmespath) expression.
2222
# @param [Hash] data
2323
# @return [Mixed,nil] Returns the matched values. Returns `nil` if the
2424
# expression does not resolve inside `data`.
2525
def search(expression, data, runtime_options = {})
2626
data = case data
27-
when Hash, Struct then data # check for most common case first
28-
when Pathname then load_json(data)
29-
when IO, StringIO then JSON.parse(data.read)
30-
else data
31-
end
27+
when Hash, Struct then data # check for most common case first
28+
when Pathname then load_json(data)
29+
when IO, StringIO then JSON.parse(data.read)
30+
else data
31+
end
3232
Runtime.new(runtime_options).search(expression, data)
3333
end
3434

3535
# @api private
3636
def load_json(path)
37-
JSON.parse(File.open(path, 'r', encoding: 'UTF-8', &:read))
37+
JSON.parse(File.open(path, 'r', encoding: 'UTF-8') { |f| f.read })
3838
end
39+
3940
end
4041
end

lib/jmespath/caching_parser.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
# frozen_string_literal: true
1+
require 'thread'
22

33
module JMESPath
44
class CachingParser
5+
56
def initialize(options = {})
67
@parser = options[:parser] || Parser.new(options)
78
@mutex = Mutex.new
@@ -24,5 +25,6 @@ def cache_expression(expression)
2425
@cache[expression] = @parser.parse(expression)
2526
end
2627
end
28+
2729
end
2830
end

0 commit comments

Comments
 (0)