Skip to content

Commit b208836

Browse files
authored
Merge pull request #56 from geophilusd/cleanup
Add frozen_string_literal to all files and some static code cleanup
2 parents 6e429f6 + fef3ed5 commit b208836

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

+237
-285
lines changed

Gemfile

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

34
gem 'rake', require: false

Rakefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
# frozen_string_literal: true
12
$GEM_ROOT = File.dirname(__FILE__)
23

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

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

bin/jmespath.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/usr/bin/env ruby
2+
# frozen_string_literal: true
23

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

56
require 'jmespath'
67
require 'json'

gemfiles/json-latest.gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# frozen_string_literal: true
12
eval_gemfile(File.expand_path('../../Gemfile', __FILE__))
23

34
gem 'json'

gemfiles/json-old.gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# frozen_string_literal: true
12
eval_gemfile(File.expand_path('../../Gemfile', __FILE__))
23

34
gem 'json', '< 2.0'

gemfiles/json-pure.gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# frozen_string_literal: true
12
eval_gemfile(File.expand_path('../../Gemfile', __FILE__))
23

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

gemfiles/no-deps.gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# frozen_string_literal: true
12
eval_gemfile(File.expand_path('../../Gemfile', __FILE__))
23

34
# no dependency on `json` gem

jmespath.gemspec

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# frozen_string_literal: true
12
Gem::Specification.new do |spec|
23
spec.name = 'jmespath'
34
spec.version = File.read(File.expand_path('../VERSION', __FILE__)).strip
@@ -8,5 +9,5 @@ Gem::Specification.new do |spec|
89
spec.homepage = 'http://github.com/trevorrowe/jmespath.rb'
910
spec.license = 'Apache-2.0'
1011
spec.require_paths = ['lib']
11-
spec.files = Dir['lib/**/*.rb'] + %w[LICENSE.txt VERSION]
12+
spec.files = Dir['lib/**/*.rb'] + %w(LICENSE.txt VERSION)
1213
end

lib/jmespath.rb

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1+
# frozen_string_literal: true
12
require 'json'
23
require 'stringio'
34
require 'pathname'
45

56
module JMESPath
6-
77
require 'jmespath/caching_parser'
88
require 'jmespath/errors'
99
require 'jmespath/lexer'
@@ -16,26 +16,24 @@ module JMESPath
1616
require 'jmespath/version'
1717

1818
class << self
19-
2019
# @param [String] expression A valid
2120
# [JMESPath](https://github.com/boto/jmespath) expression.
2221
# @param [Hash] data
2322
# @return [Mixed,nil] Returns the matched values. Returns `nil` if the
2423
# expression does not resolve inside `data`.
2524
def search(expression, data, runtime_options = {})
2625
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
26+
when Hash, Struct then data # check for most common case first
27+
when Pathname then load_json(data)
28+
when IO, StringIO then JSON.parse(data.read)
29+
else data
3130
end
3231
Runtime.new(runtime_options).search(expression, data)
3332
end
3433

3534
# @api private
3635
def load_json(path)
37-
JSON.parse(File.open(path, 'r', encoding: 'UTF-8') { |f| f.read })
36+
JSON.parse(File.open(path, 'r', encoding: 'UTF-8', &:read))
3837
end
39-
4038
end
4139
end

lib/jmespath/caching_parser.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1+
# frozen_string_literal: true
12
require 'thread'
23

34
module JMESPath
45
class CachingParser
5-
66
def initialize(options = {})
77
@parser = options[:parser] || Parser.new(options)
88
@mutex = Mutex.new
@@ -25,6 +25,5 @@ def cache_expression(expression)
2525
@cache[expression] = @parser.parse(expression)
2626
end
2727
end
28-
2928
end
3029
end

0 commit comments

Comments
 (0)