enumpath 0.1.1 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +196 -42
- data/lib/enumpath/logger.rb +14 -11
- data/lib/enumpath/operator/base.rb +25 -10
- data/lib/enumpath/operator/child.rb +2 -2
- data/lib/enumpath/operator/filter_expression.rb +32 -26
- data/lib/enumpath/operator/recursive_descent.rb +7 -7
- data/lib/enumpath/operator/slice.rb +2 -2
- data/lib/enumpath/operator/subscript_expression.rb +16 -14
- data/lib/enumpath/operator/union.rb +1 -1
- data/lib/enumpath/operator/wildcard.rb +1 -1
- data/lib/enumpath/operator.rb +47 -26
- data/lib/enumpath/path/normalized_path.rb +24 -15
- data/lib/enumpath/path.rb +19 -10
- data/lib/enumpath/resolver/object_inspector.rb +70 -0
- data/lib/enumpath/resolver/property.rb +227 -8
- data/lib/enumpath/resolver/simple.rb +35 -1
- data/lib/enumpath/version.rb +1 -1
- data/lib/enumpath.rb +21 -10
- metadata +67 -39
- data/.gitignore +0 -15
- data/.rspec +0 -3
- data/.travis.yml +0 -5
- data/.yardopts +0 -1
- data/CONTRIBUTING.md +0 -91
- data/Gemfile +0 -6
- data/Gemfile.lock +0 -56
- data/Rakefile +0 -11
- data/bin/console +0 -14
- data/bin/setup +0 -8
- data/enumpath.gemspec +0 -42
|
@@ -2,21 +2,240 @@
|
|
|
2
2
|
|
|
3
3
|
module Enumpath
|
|
4
4
|
module Resolver
|
|
5
|
-
# A utility for resolving a string as a property of an object
|
|
5
|
+
# A utility for resolving a string as a property (a public method that expects no arguments) of an object.
|
|
6
|
+
#
|
|
7
|
+
# Which properties resolve is decided by a property resolver policy, set with the `:property_resolver` option of
|
|
8
|
+
# {Enumpath.apply}:
|
|
9
|
+
#
|
|
10
|
+
# - `:safe` (the default): read-only access only. See {.safe?}.
|
|
11
|
+
# - `:readers`: `:safe`, plus public methods written in Ruby (including those of installed gems) and
|
|
12
|
+
# ActiveModel-style `attributes`. See {.reader?}. This runs application and gem code and is not read-only.
|
|
13
|
+
# - `:none`: never call methods. Indexes, keys and Struct or Data members still resolve through
|
|
14
|
+
# {Resolver::Simple}.
|
|
15
|
+
# - `:all`: call any public method that expects no arguments. This was the behavior of version 0.1 and lets a
|
|
16
|
+
# path run mutating or destructive methods such as `clear`, `pop` or `destroy`. Only use it with trusted paths.
|
|
17
|
+
# - a callable (anything that responds to `call`, such as a lambda): called as `callable.call(object, name)` with
|
|
18
|
+
# the property name as a String; the method is called only when it returns a truthy value. The callable has
|
|
19
|
+
# full control: none of the checks of the other policies are applied. It can call {.safe?} or {.reader?} to
|
|
20
|
+
# build on them.
|
|
21
|
+
#
|
|
22
|
+
# The policy for the current {Enumpath.apply} call is kept in a fiber-local variable (`Thread.current`), so it
|
|
23
|
+
# reaches every operator without being passed through each one, and calls running in other threads or fibers do
|
|
24
|
+
# not see it. Outside of {Enumpath.apply}, and in a chained {Enumpath::Results#apply} that does not pass the
|
|
25
|
+
# option again, the default (`:safe`) applies.
|
|
6
26
|
class Property
|
|
27
|
+
# The policies accepted by the `:property_resolver` option, besides a callable
|
|
28
|
+
POLICIES = %i[safe readers none all].freeze
|
|
29
|
+
|
|
30
|
+
# The policy used when none is given
|
|
31
|
+
DEFAULT_POLICY = :safe
|
|
32
|
+
|
|
33
|
+
# Property names `:safe` and `:readers` will consider: plain identifiers, optionally ending in `?`. Names ending
|
|
34
|
+
# in `!` or `=`, operators and constant-like names are never called.
|
|
35
|
+
IDENTIFIER = /\A[a-z_][A-Za-z0-9_]*\??\z/.freeze
|
|
36
|
+
|
|
37
|
+
# Read-only methods `:safe` calls on {SAFE_RECEIVERS}. Each returns a new value and leaves the receiver
|
|
38
|
+
# unchanged in Ruby's own implementation. Mutating methods (`clear`, `pop`, `shift`, `delete`, `freeze`, any `!`
|
|
39
|
+
# method) are deliberately absent.
|
|
40
|
+
SAFE_METHODS = %w[
|
|
41
|
+
length size count empty? any? all? none? one?
|
|
42
|
+
first last min max minmax sum
|
|
43
|
+
keys values entries to_a to_h
|
|
44
|
+
reverse compact sort uniq flatten
|
|
45
|
+
to_s to_sym to_i to_f to_r to_c
|
|
46
|
+
nil? zero? nonzero? positive? negative? even? odd? finite? infinite? integer?
|
|
47
|
+
abs floor ceil round truncate next pred succ
|
|
48
|
+
upcase downcase capitalize swapcase strip lstrip rstrip chomp chop bytesize
|
|
49
|
+
].freeze
|
|
50
|
+
|
|
51
|
+
# The plain data classes on which `:safe` calls {SAFE_METHODS}. Other objects that define methods with the same
|
|
52
|
+
# names (an IO, an Enumerator, a database relation, a custom collection) could run arbitrary code or consume
|
|
53
|
+
# input. Range is left out because methods like `sum` and `sort` never return on an endless range.
|
|
54
|
+
SAFE_RECEIVERS = ([Array, Hash, String, Symbol, Numeric, NilClass, TrueClass, FalseClass, Struct] +
|
|
55
|
+
[Simple::DATA_CLASS].compact).freeze
|
|
56
|
+
|
|
57
|
+
# Modules whose implementation of a {SAFE_METHODS} name is trusted. A subclass of a {SAFE_RECEIVERS} class that
|
|
58
|
+
# overrides one of these methods is not trusted.
|
|
59
|
+
CORE_OWNERS = (SAFE_RECEIVERS + [Kernel, Comparable, Enumerable, Integer, Float, Rational, Complex]).freeze
|
|
60
|
+
|
|
61
|
+
# Instances of these classes are core objects: their instance variables never make a property resolvable, and
|
|
62
|
+
# `:readers` treats them exactly like `:safe`. Modules and classes are included because their instance
|
|
63
|
+
# variables are usually internal state (memoized values, configuration), not data.
|
|
64
|
+
CORE_CLASSES = (SAFE_RECEIVERS + [Range, Module, Proc, Method, UnboundMethod, IO, Enumerator, Thread]).freeze
|
|
65
|
+
|
|
66
|
+
# Common persistence verbs `:readers` refuses to call even when the object's class defines them. This is a
|
|
67
|
+
# safety net for ActiveRecord-style models, not a guarantee: `:readers` still runs any other public method that
|
|
68
|
+
# expects no arguments.
|
|
69
|
+
READERS_DENYLIST = %w[destroy delete save update reload touch delete_all destroy_all toggle].freeze
|
|
70
|
+
|
|
71
|
+
# The `Thread.current` key that holds the policy for the current {Enumpath.apply} call
|
|
72
|
+
THREAD_KEY = :enumpath_property_resolver
|
|
73
|
+
|
|
7
74
|
class << self
|
|
8
|
-
# Attempts to resolve a string as a property of an object
|
|
9
|
-
# expects no arguments.
|
|
75
|
+
# Attempts to resolve a string as a property of an object, as the policy allows
|
|
10
76
|
#
|
|
11
77
|
# @param property [String] the name of the property to attempt to resolve
|
|
12
78
|
# @param object [Object] the object to resolve the property against
|
|
13
|
-
# @
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
object
|
|
17
|
-
rescue ArgumentError, NoMethodError
|
|
79
|
+
# @param policy [Symbol, #call] the property resolver policy to apply; defaults to {.current_policy}
|
|
80
|
+
# @return the resolved property value, or nil if it could not be resolved or the policy does not allow it
|
|
81
|
+
def resolve(property, object, policy = current_policy)
|
|
82
|
+
access(policy, object, property.to_s)&.call
|
|
83
|
+
rescue ArgumentError, NoMethodError, TypeError, RangeError
|
|
18
84
|
nil
|
|
19
85
|
end
|
|
86
|
+
|
|
87
|
+
# The policy for the current {Enumpath.apply} call in this thread or fiber
|
|
88
|
+
#
|
|
89
|
+
# @return [Symbol, #call] the current policy, or {DEFAULT_POLICY} when none is set
|
|
90
|
+
def current_policy
|
|
91
|
+
Thread.current[THREAD_KEY] || DEFAULT_POLICY
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
# Runs the block with a policy as the {.current_policy}, then restores the previous policy, even if the block
|
|
95
|
+
# raises. Used by {Enumpath.apply}.
|
|
96
|
+
#
|
|
97
|
+
# @private
|
|
98
|
+
# @param policy [Symbol, #call, nil] the policy to use; nil means {DEFAULT_POLICY}
|
|
99
|
+
# @raise [ArgumentError] if the policy is not valid
|
|
100
|
+
# @return the value of the block
|
|
101
|
+
def with_policy(policy)
|
|
102
|
+
policy = validate_policy!(policy.nil? ? DEFAULT_POLICY : policy)
|
|
103
|
+
previous = Thread.current[THREAD_KEY]
|
|
104
|
+
Thread.current[THREAD_KEY] = policy
|
|
105
|
+
begin
|
|
106
|
+
yield
|
|
107
|
+
ensure
|
|
108
|
+
Thread.current[THREAD_KEY] = previous
|
|
109
|
+
end
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
# Whether the `:safe` policy resolves a property of an object. All of these must hold:
|
|
113
|
+
#
|
|
114
|
+
# - the name is a plain identifier (see {IDENTIFIER});
|
|
115
|
+
# - the object publicly responds to it and the method has no required arguments;
|
|
116
|
+
# - and either
|
|
117
|
+
# - the name is in {SAFE_METHODS}, the object is one of {SAFE_RECEIVERS}, and the method is Ruby's own
|
|
118
|
+
# (owned by one of {CORE_OWNERS}, not overridden), in which case the method is called; or
|
|
119
|
+
# - the object is not one of {CORE_CLASSES} and has an instance variable of the same name (`@name` for
|
|
120
|
+
# `name`), as an attr_reader on a plain Ruby object does. In that case the instance variable is read
|
|
121
|
+
# directly and the method itself is never called, so a method that merely shares its name with an
|
|
122
|
+
# instance variable cannot run.
|
|
123
|
+
#
|
|
124
|
+
# Struct and Data members are not handled here: they resolve as members through {Resolver::Simple}.
|
|
125
|
+
#
|
|
126
|
+
# A callable policy can build on this check to allow more methods while keeping the safe ones:
|
|
127
|
+
#
|
|
128
|
+
# @example Keep the safe defaults and allow specific methods per class
|
|
129
|
+
# ALLOWED = { 'Invoice' => %w[total due_on], 'Customer' => %w[name email] }.freeze
|
|
130
|
+
# policy = lambda do |object, name|
|
|
131
|
+
# Enumpath::Resolver::Property.safe?(object, name) || ALLOWED.fetch(object.class.name, []).include?(name)
|
|
132
|
+
# end
|
|
133
|
+
# Enumpath.apply('invoices.*.total', account, property_resolver: policy)
|
|
134
|
+
#
|
|
135
|
+
# @param object [Object] the object to read from
|
|
136
|
+
# @param name [String] the property name
|
|
137
|
+
# @return [true, false]
|
|
138
|
+
def safe?(object, name)
|
|
139
|
+
!safe_access(object, name).nil?
|
|
140
|
+
rescue StandardError
|
|
141
|
+
false
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
# Whether the `:readers` policy resolves a property of an object. Core objects (see {CORE_CLASSES}) are
|
|
145
|
+
# treated exactly like {.safe?}. For any other object, either
|
|
146
|
+
#
|
|
147
|
+
# - the name is a plain identifier (see {IDENTIFIER}), not in {READERS_DENYLIST}, and the object publicly
|
|
148
|
+
# responds to it with a method that expects no arguments and is written in Ruby outside of Ruby itself (see
|
|
149
|
+
# {ObjectInspector.application_method?}), so computed readers like `full_name` work; or
|
|
150
|
+
# - the object has an ActiveModel-style `attributes` method (no arguments, written in Ruby outside of Ruby
|
|
151
|
+
# itself) that returns a Hash with the name as a String key, so attributes like `email` work even before
|
|
152
|
+
# their reader methods are defined; or
|
|
153
|
+
# - {.safe?} allows it.
|
|
154
|
+
#
|
|
155
|
+
# In short, `:readers` runs any public method that expects no arguments and is written in Ruby, except Ruby's
|
|
156
|
+
# built-in methods, methods in the Ruby standard library directory, and {READERS_DENYLIST}. Methods
|
|
157
|
+
# implemented in C (core classes, StringIO, C-extension gems) are never called; objects of C-extension classes
|
|
158
|
+
# need a callable policy or `:all`. Methods from installed gems are called, including default and bundled gems
|
|
159
|
+
# such as Logger and CSV, and ActiveModel or ActiveRecord: for example `Logger#close` would run.
|
|
160
|
+
#
|
|
161
|
+
# So `:readers` is not read-only. Use it for data you trust or objects you built. For untrusted paths use
|
|
162
|
+
# `:safe`, or a callable that builds on {.safe?} with a per-class allowlist.
|
|
163
|
+
#
|
|
164
|
+
# @param object [Object] the object to read from
|
|
165
|
+
# @param name [String] the property name
|
|
166
|
+
# @return [true, false]
|
|
167
|
+
def reader?(object, name)
|
|
168
|
+
!reader_access(object, name).nil?
|
|
169
|
+
rescue StandardError
|
|
170
|
+
false
|
|
171
|
+
end
|
|
172
|
+
|
|
173
|
+
private
|
|
174
|
+
|
|
175
|
+
# Each *access method returns nil when the property may not be resolved, or a lambda that resolves it
|
|
176
|
+
def access(policy, object, name)
|
|
177
|
+
case policy
|
|
178
|
+
when :all then -> { object.public_send(name.to_sym) }
|
|
179
|
+
when :none then nil
|
|
180
|
+
when :safe then safe_access(object, name)
|
|
181
|
+
when :readers then reader_access(object, name)
|
|
182
|
+
else (-> { object.public_send(name.to_sym) } if policy.call(object, name))
|
|
183
|
+
end
|
|
184
|
+
end
|
|
185
|
+
|
|
186
|
+
def safe_access(object, name)
|
|
187
|
+
return unless name.match?(IDENTIFIER)
|
|
188
|
+
|
|
189
|
+
method = ObjectInspector.public_method_without_required_args(object, name)
|
|
190
|
+
return if method.nil?
|
|
191
|
+
return -> { object.public_send(name.to_sym) } if core_reader?(object, name, method)
|
|
192
|
+
|
|
193
|
+
instance_variable_access(object, name)
|
|
194
|
+
end
|
|
195
|
+
|
|
196
|
+
def reader_access(object, name)
|
|
197
|
+
return safe_access(object, name) if ObjectInspector.instance_of_any?(object, CORE_CLASSES)
|
|
198
|
+
return unless name.match?(IDENTIFIER)
|
|
199
|
+
return if READERS_DENYLIST.include?(name)
|
|
200
|
+
|
|
201
|
+
app_method_access(object, name) || attribute_access(object, name) || safe_access(object, name)
|
|
202
|
+
end
|
|
203
|
+
|
|
204
|
+
def app_method_access(object, name)
|
|
205
|
+
method = ObjectInspector.public_method_without_required_args(object, name)
|
|
206
|
+
return unless ObjectInspector.application_method?(method)
|
|
207
|
+
|
|
208
|
+
-> { object.public_send(name.to_sym) }
|
|
209
|
+
end
|
|
210
|
+
|
|
211
|
+
def attribute_access(object, name)
|
|
212
|
+
method = ObjectInspector.public_method_without_required_args(object, 'attributes')
|
|
213
|
+
return unless ObjectInspector.application_method?(method)
|
|
214
|
+
|
|
215
|
+
attributes = object.public_send(:attributes)
|
|
216
|
+
-> { attributes[name] } if attributes.is_a?(Hash) && attributes.key?(name)
|
|
217
|
+
end
|
|
218
|
+
|
|
219
|
+
def validate_policy!(policy)
|
|
220
|
+
return policy if POLICIES.include?(policy) || policy.respond_to?(:call)
|
|
221
|
+
|
|
222
|
+
raise ArgumentError, "Invalid property_resolver #{policy.inspect}: use :#{POLICIES.join(', :')} or a callable"
|
|
223
|
+
end
|
|
224
|
+
|
|
225
|
+
def core_reader?(object, name, method)
|
|
226
|
+
SAFE_METHODS.include?(name) &&
|
|
227
|
+
ObjectInspector.instance_of_any?(object, SAFE_RECEIVERS) &&
|
|
228
|
+
CORE_OWNERS.include?(method.owner)
|
|
229
|
+
end
|
|
230
|
+
|
|
231
|
+
def instance_variable_access(object, name)
|
|
232
|
+
return if name.end_with?('?') || ObjectInspector.instance_of_any?(object, CORE_CLASSES)
|
|
233
|
+
|
|
234
|
+
ivar = "@#{name}"
|
|
235
|
+
return unless ObjectInspector.kernel(object, :instance_variable_defined?, ivar)
|
|
236
|
+
|
|
237
|
+
-> { ObjectInspector.kernel(object, :instance_variable_get, ivar) }
|
|
238
|
+
end
|
|
20
239
|
end
|
|
21
240
|
end
|
|
22
241
|
end
|
|
@@ -6,8 +6,13 @@ module Enumpath
|
|
|
6
6
|
class Simple
|
|
7
7
|
NUMERIC_INDEX_TEST = /\A\-?(?:0|[1-9][0-9]*)\z/
|
|
8
8
|
|
|
9
|
+
# Ruby's `Data` class (3.2 and later), or nil on older Rubies. Older Rubies have an unrelated, deprecated `Data`
|
|
10
|
+
# constant, so it is only looked up on 3.2 and later.
|
|
11
|
+
DATA_CLASS = ((RUBY_VERSION.split('.').map(&:to_i) <=> [3, 2]) >= 0 ? Object.const_get(:Data) : nil)
|
|
12
|
+
|
|
9
13
|
class << self
|
|
10
|
-
# Attempts to resolve a string as an index, key, or member of an enumerable
|
|
14
|
+
# Attempts to resolve a string as an index, key, or member of an enumerable. Members of `Data` objects
|
|
15
|
+
# (Ruby 3.2 and later) resolve like Struct members.
|
|
11
16
|
#
|
|
12
17
|
# @param variable [String] the value to attempt to resolve
|
|
13
18
|
# @param enum [Enumerable] the enumerable to resolve the value against
|
|
@@ -17,11 +22,40 @@ module Enumpath
|
|
|
17
22
|
value = rescued_dig(enum, variable.to_i) if variable =~ NUMERIC_INDEX_TEST
|
|
18
23
|
value = rescued_dig(enum, variable) if value.nil?
|
|
19
24
|
value = rescued_dig(enum, variable.to_sym) if value.nil?
|
|
25
|
+
value = data_member(enum, variable) if value.nil?
|
|
20
26
|
value
|
|
21
27
|
end
|
|
22
28
|
|
|
29
|
+
# Whether an object is a `Data` object (Ruby 3.2 and later)
|
|
30
|
+
#
|
|
31
|
+
# @private
|
|
32
|
+
# @param object [Object]
|
|
33
|
+
# @return [true, false]
|
|
34
|
+
def data?(object)
|
|
35
|
+
!DATA_CLASS.nil? && Kernel.instance_method(:is_a?).bind(object).call(DATA_CLASS)
|
|
36
|
+
rescue TypeError
|
|
37
|
+
false
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
# The member names of a `Data` object, read without calling any method the object's class defines
|
|
41
|
+
#
|
|
42
|
+
# @private
|
|
43
|
+
# @param object [Data]
|
|
44
|
+
# @return [Array<Symbol>]
|
|
45
|
+
def data_members(object)
|
|
46
|
+
DATA_CLASS.instance_method(:members).bind(object).call
|
|
47
|
+
end
|
|
48
|
+
|
|
23
49
|
private
|
|
24
50
|
|
|
51
|
+
# Reads a member of a `Data` object through Data#to_h, which reads the stored values directly, so a member
|
|
52
|
+
# reader overridden in the class is not called
|
|
53
|
+
def data_member(enum, variable)
|
|
54
|
+
return unless data?(enum) && data_members(enum).include?(variable.to_sym)
|
|
55
|
+
|
|
56
|
+
DATA_CLASS.instance_method(:to_h).bind(enum).call[variable.to_sym]
|
|
57
|
+
end
|
|
58
|
+
|
|
25
59
|
def rescued_dig(enum, typecast_variable)
|
|
26
60
|
enum.dig(typecast_variable)
|
|
27
61
|
rescue NoMethodError, TypeError
|
data/lib/enumpath/version.rb
CHANGED
data/lib/enumpath.rb
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require 'mini_cache'
|
|
4
|
-
require
|
|
5
|
-
require
|
|
6
|
-
require
|
|
7
|
-
require
|
|
8
|
-
require
|
|
9
|
-
require
|
|
10
|
-
require
|
|
4
|
+
require 'enumpath/logger'
|
|
5
|
+
require 'enumpath/operator'
|
|
6
|
+
require 'enumpath/path'
|
|
7
|
+
require 'enumpath/results'
|
|
8
|
+
require 'enumpath/resolver/object_inspector'
|
|
9
|
+
require 'enumpath/resolver/simple'
|
|
10
|
+
require 'enumpath/resolver/property'
|
|
11
|
+
require 'enumpath/version'
|
|
11
12
|
|
|
12
13
|
# A JSONPath-compatible library for navigating Ruby objects using path expressions
|
|
13
14
|
module Enumpath
|
|
@@ -28,11 +29,21 @@ module Enumpath
|
|
|
28
29
|
# @param options [optional, Hash]
|
|
29
30
|
# @option options [Symbol] :result_type (:value) The type of results to return, `:value` or `:path`
|
|
30
31
|
# @option options [true, false] :verbose (false) Whether to enable additional output for debugging
|
|
32
|
+
# @option options [Symbol, #call] :property_resolver (:safe) Which methods a path may call on an object when a
|
|
33
|
+
# segment is not an index, key, or member: `:safe` (read-only methods only), `:readers` (`:safe` plus public
|
|
34
|
+
# no-argument methods written in Ruby, including those of installed gems, and ActiveModel-style `attributes`;
|
|
35
|
+
# not read-only, for trusted data only), `:none`, `:all` (any public method that expects no arguments, the
|
|
36
|
+
# behavior of version 0.1), or a callable `->(object, name) { ... }` that returns true to allow the call.
|
|
37
|
+
# Applies only to this call; a chained {Enumpath::Results#apply} uses the default unless the option is passed
|
|
38
|
+
# again. See {Enumpath::Resolver::Property}.
|
|
39
|
+
# @raise [ArgumentError] if `:property_resolver` is not one of the values above
|
|
31
40
|
# @return (see Enumpath::Path#apply)
|
|
32
41
|
def apply(path, enum, options = {})
|
|
33
42
|
logger.level = 0
|
|
34
|
-
@verbose = options
|
|
35
|
-
Enumpath::
|
|
43
|
+
@verbose = options[:verbose] || false
|
|
44
|
+
Enumpath::Resolver::Property.with_policy(options[:property_resolver]) do
|
|
45
|
+
Enumpath::Path.new(path, result_type: options[:result_type]).apply(enum)
|
|
46
|
+
end
|
|
36
47
|
end
|
|
37
48
|
|
|
38
49
|
# The {Enumpath::Logger} instance to use with verbose mode
|
|
@@ -48,7 +59,7 @@ module Enumpath
|
|
|
48
59
|
# @private
|
|
49
60
|
# @see Enumpath::Logger#log
|
|
50
61
|
def log(title)
|
|
51
|
-
block_given? ? logger.log(title,
|
|
62
|
+
block_given? ? logger.log(title, &-> { yield }) : logger.log(title)
|
|
52
63
|
end
|
|
53
64
|
|
|
54
65
|
# A lightweight in-memory cache for caching normalized path expressions
|
metadata
CHANGED
|
@@ -1,29 +1,28 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: enumpath
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Chris Bloom
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: bin
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
11
|
dependencies:
|
|
13
12
|
- !ruby/object:Gem::Dependency
|
|
14
|
-
name:
|
|
13
|
+
name: logger
|
|
15
14
|
requirement: !ruby/object:Gem::Requirement
|
|
16
15
|
requirements:
|
|
17
|
-
- - "
|
|
16
|
+
- - ">="
|
|
18
17
|
- !ruby/object:Gem::Version
|
|
19
|
-
version:
|
|
18
|
+
version: '1.4'
|
|
20
19
|
type: :runtime
|
|
21
20
|
prerelease: false
|
|
22
21
|
version_requirements: !ruby/object:Gem::Requirement
|
|
23
22
|
requirements:
|
|
24
|
-
- - "
|
|
23
|
+
- - ">="
|
|
25
24
|
- !ruby/object:Gem::Version
|
|
26
|
-
version:
|
|
25
|
+
version: '1.4'
|
|
27
26
|
- !ruby/object:Gem::Dependency
|
|
28
27
|
name: mini_cache
|
|
29
28
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -39,19 +38,19 @@ dependencies:
|
|
|
39
38
|
- !ruby/object:Gem::Version
|
|
40
39
|
version: 1.1.0
|
|
41
40
|
- !ruby/object:Gem::Dependency
|
|
42
|
-
name:
|
|
41
|
+
name: to_regexp
|
|
43
42
|
requirement: !ruby/object:Gem::Requirement
|
|
44
43
|
requirements:
|
|
45
44
|
- - "~>"
|
|
46
45
|
- !ruby/object:Gem::Version
|
|
47
|
-
version:
|
|
48
|
-
type: :
|
|
46
|
+
version: 0.2.1
|
|
47
|
+
type: :runtime
|
|
49
48
|
prerelease: false
|
|
50
49
|
version_requirements: !ruby/object:Gem::Requirement
|
|
51
50
|
requirements:
|
|
52
51
|
- - "~>"
|
|
53
52
|
- !ruby/object:Gem::Version
|
|
54
|
-
version:
|
|
53
|
+
version: 0.2.1
|
|
55
54
|
- !ruby/object:Gem::Dependency
|
|
56
55
|
name: null-logger
|
|
57
56
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -72,56 +71,98 @@ dependencies:
|
|
|
72
71
|
requirements:
|
|
73
72
|
- - "~>"
|
|
74
73
|
- !ruby/object:Gem::Version
|
|
75
|
-
version: '3.
|
|
74
|
+
version: '3.9'
|
|
76
75
|
type: :development
|
|
77
76
|
prerelease: false
|
|
78
77
|
version_requirements: !ruby/object:Gem::Requirement
|
|
79
78
|
requirements:
|
|
80
79
|
- - "~>"
|
|
81
80
|
- !ruby/object:Gem::Version
|
|
82
|
-
version: '3.
|
|
81
|
+
version: '3.9'
|
|
83
82
|
- !ruby/object:Gem::Dependency
|
|
84
83
|
name: rake
|
|
85
84
|
requirement: !ruby/object:Gem::Requirement
|
|
86
85
|
requirements:
|
|
87
86
|
- - "~>"
|
|
88
87
|
- !ruby/object:Gem::Version
|
|
89
|
-
version: '
|
|
88
|
+
version: '13.0'
|
|
89
|
+
type: :development
|
|
90
|
+
prerelease: false
|
|
91
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
92
|
+
requirements:
|
|
93
|
+
- - "~>"
|
|
94
|
+
- !ruby/object:Gem::Version
|
|
95
|
+
version: '13.0'
|
|
96
|
+
- !ruby/object:Gem::Dependency
|
|
97
|
+
name: redcarpet
|
|
98
|
+
requirement: !ruby/object:Gem::Requirement
|
|
99
|
+
requirements:
|
|
100
|
+
- - "~>"
|
|
101
|
+
- !ruby/object:Gem::Version
|
|
102
|
+
version: '3.5'
|
|
90
103
|
type: :development
|
|
91
104
|
prerelease: false
|
|
92
105
|
version_requirements: !ruby/object:Gem::Requirement
|
|
93
106
|
requirements:
|
|
94
107
|
- - "~>"
|
|
95
108
|
- !ruby/object:Gem::Version
|
|
96
|
-
version: '
|
|
109
|
+
version: '3.5'
|
|
110
|
+
- !ruby/object:Gem::Dependency
|
|
111
|
+
name: rspec_junit_formatter
|
|
112
|
+
requirement: !ruby/object:Gem::Requirement
|
|
113
|
+
requirements:
|
|
114
|
+
- - "~>"
|
|
115
|
+
- !ruby/object:Gem::Version
|
|
116
|
+
version: '0.4'
|
|
117
|
+
type: :development
|
|
118
|
+
prerelease: false
|
|
119
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
120
|
+
requirements:
|
|
121
|
+
- - "~>"
|
|
122
|
+
- !ruby/object:Gem::Version
|
|
123
|
+
version: '0.4'
|
|
97
124
|
- !ruby/object:Gem::Dependency
|
|
98
125
|
name: rspec-benchmark
|
|
99
126
|
requirement: !ruby/object:Gem::Requirement
|
|
100
127
|
requirements:
|
|
101
128
|
- - "~>"
|
|
102
129
|
- !ruby/object:Gem::Version
|
|
103
|
-
version: 0.
|
|
130
|
+
version: '0.6'
|
|
104
131
|
type: :development
|
|
105
132
|
prerelease: false
|
|
106
133
|
version_requirements: !ruby/object:Gem::Requirement
|
|
107
134
|
requirements:
|
|
108
135
|
- - "~>"
|
|
109
136
|
- !ruby/object:Gem::Version
|
|
110
|
-
version: 0.
|
|
137
|
+
version: '0.6'
|
|
111
138
|
- !ruby/object:Gem::Dependency
|
|
112
139
|
name: rspec
|
|
113
140
|
requirement: !ruby/object:Gem::Requirement
|
|
114
141
|
requirements:
|
|
115
142
|
- - "~>"
|
|
116
143
|
- !ruby/object:Gem::Version
|
|
117
|
-
version: '3.
|
|
144
|
+
version: '3.10'
|
|
145
|
+
type: :development
|
|
146
|
+
prerelease: false
|
|
147
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
148
|
+
requirements:
|
|
149
|
+
- - "~>"
|
|
150
|
+
- !ruby/object:Gem::Version
|
|
151
|
+
version: '3.10'
|
|
152
|
+
- !ruby/object:Gem::Dependency
|
|
153
|
+
name: yard
|
|
154
|
+
requirement: !ruby/object:Gem::Requirement
|
|
155
|
+
requirements:
|
|
156
|
+
- - "~>"
|
|
157
|
+
- !ruby/object:Gem::Version
|
|
158
|
+
version: '0.9'
|
|
118
159
|
type: :development
|
|
119
160
|
prerelease: false
|
|
120
161
|
version_requirements: !ruby/object:Gem::Requirement
|
|
121
162
|
requirements:
|
|
122
163
|
- - "~>"
|
|
123
164
|
- !ruby/object:Gem::Version
|
|
124
|
-
version: '
|
|
165
|
+
version: '0.9'
|
|
125
166
|
description: |
|
|
126
167
|
Enumpath is an implementation of the JSONPath spec for Ruby objects,
|
|
127
168
|
plus some added sugar. It's like Ruby's native Enumerable#dig method,
|
|
@@ -131,25 +172,13 @@ description: |
|
|
|
131
172
|
(Extract, Transform, Load) processes by allowing you to define paths
|
|
132
173
|
through your data in a simple, easily readable, easily storable syntax.
|
|
133
174
|
email:
|
|
134
|
-
- open-source@youearnedit.com
|
|
135
175
|
- chrisbloom7@gmail.com
|
|
136
176
|
executables: []
|
|
137
177
|
extensions: []
|
|
138
178
|
extra_rdoc_files: []
|
|
139
179
|
files:
|
|
140
|
-
- ".gitignore"
|
|
141
|
-
- ".rspec"
|
|
142
|
-
- ".travis.yml"
|
|
143
|
-
- ".yardopts"
|
|
144
|
-
- CONTRIBUTING.md
|
|
145
|
-
- Gemfile
|
|
146
|
-
- Gemfile.lock
|
|
147
180
|
- LICENSE
|
|
148
181
|
- README.md
|
|
149
|
-
- Rakefile
|
|
150
|
-
- bin/console
|
|
151
|
-
- bin/setup
|
|
152
|
-
- enumpath.gemspec
|
|
153
182
|
- lib/enumpath.rb
|
|
154
183
|
- lib/enumpath/logger.rb
|
|
155
184
|
- lib/enumpath/operator.rb
|
|
@@ -163,15 +192,16 @@ files:
|
|
|
163
192
|
- lib/enumpath/operator/wildcard.rb
|
|
164
193
|
- lib/enumpath/path.rb
|
|
165
194
|
- lib/enumpath/path/normalized_path.rb
|
|
195
|
+
- lib/enumpath/resolver/object_inspector.rb
|
|
166
196
|
- lib/enumpath/resolver/property.rb
|
|
167
197
|
- lib/enumpath/resolver/simple.rb
|
|
168
198
|
- lib/enumpath/results.rb
|
|
169
199
|
- lib/enumpath/version.rb
|
|
170
|
-
homepage: https://github.com/
|
|
200
|
+
homepage: https://github.com/chrisbloom7/enumpath
|
|
171
201
|
licenses:
|
|
172
202
|
- Apache-2.0
|
|
173
|
-
metadata:
|
|
174
|
-
|
|
203
|
+
metadata:
|
|
204
|
+
rubygems_mfa_required: 'true'
|
|
175
205
|
rdoc_options: []
|
|
176
206
|
require_paths:
|
|
177
207
|
- lib
|
|
@@ -179,16 +209,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
179
209
|
requirements:
|
|
180
210
|
- - ">="
|
|
181
211
|
- !ruby/object:Gem::Version
|
|
182
|
-
version: 2.
|
|
212
|
+
version: 2.6.0
|
|
183
213
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
184
214
|
requirements:
|
|
185
215
|
- - ">="
|
|
186
216
|
- !ruby/object:Gem::Version
|
|
187
217
|
version: '0'
|
|
188
218
|
requirements: []
|
|
189
|
-
|
|
190
|
-
rubygems_version: 2.7.7
|
|
191
|
-
signing_key:
|
|
219
|
+
rubygems_version: 3.6.9
|
|
192
220
|
specification_version: 4
|
|
193
221
|
summary: A JSONPath-compatible library for navigating nested Ruby objects using path
|
|
194
222
|
expressions
|
data/.gitignore
DELETED
data/.rspec
DELETED
data/.travis.yml
DELETED
data/.yardopts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
--no-private - LICENSE
|