iteraptor 0.8.2 → 0.10.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +3 -3
- data/iteraptor.gemspec +2 -2
- data/lib/iteraptor/delegator.rb +3 -1
- data/lib/iteraptor/version.rb +1 -1
- data/lib/iteraptor.rb +62 -1
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 850485a23254567575960edcb3d1d6cc1a35ac68
|
4
|
+
data.tar.gz: 7a960bb2c35962b03eb30831dcb277e03a66ba4e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '004919dd612bde265edeaeaa1c7989aee61817d0d44ac7daea19daa82ecb92ac8b1b0553d8bf6a796bda0892c094e128503ea0567429a1a6413b56dde238f0f7'
|
7
|
+
data.tar.gz: baa763e6b9e34733fe60d98f43d99be43b5f9be8f40a58aa3d39d4cbb9f396977444663755d6142e87ab101b60ce7c1f2729559bc0f94fed9d02c39cb0b11c1d
|
data/.travis.yml
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
language: ruby
|
2
2
|
rvm:
|
3
|
-
- 2.1.8
|
4
|
-
- 2.2.3
|
5
3
|
- 2.3.2
|
6
4
|
- 2.4.1
|
7
5
|
- 2.5.0
|
8
|
-
|
6
|
+
- 2.6.0
|
7
|
+
- 2.7.0
|
8
|
+
before_install: gem install bundler -v 2.1.2
|
9
9
|
addons:
|
10
10
|
code_climate:
|
11
11
|
repo_token: 1afbd216b9257514ff1afcaa7b8a121bc83e5238b4c3c6f4dad80107c4ea487d
|
data/iteraptor.gemspec
CHANGED
@@ -24,8 +24,8 @@ Gem::Specification.new do |spec|
|
|
24
24
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
25
25
|
spec.require_paths = ['lib']
|
26
26
|
|
27
|
-
spec.add_development_dependency 'bundler', '~>
|
28
|
-
spec.add_development_dependency 'rake', '~>
|
27
|
+
spec.add_development_dependency 'bundler', '~> 2'
|
28
|
+
spec.add_development_dependency 'rake', '~> 13'
|
29
29
|
spec.add_development_dependency 'rspec', '~> 3'
|
30
30
|
spec.add_development_dependency 'pry'
|
31
31
|
spec .add_development_dependency 'awesome_print'
|
data/lib/iteraptor/delegator.rb
CHANGED
data/lib/iteraptor/version.rb
CHANGED
data/lib/iteraptor.rb
CHANGED
@@ -3,7 +3,6 @@ require "iteraptor/version"
|
|
3
3
|
# rubocop:disable Style/VariableNumber
|
4
4
|
# rubocop:disable Metrics/ModuleLength
|
5
5
|
module Iteraptor
|
6
|
-
|
7
6
|
def self.included base
|
8
7
|
raise "This module might be included into Enumerables only" unless base.ancestors.include? Enumerable
|
9
8
|
end
|
@@ -12,6 +11,30 @@ module Iteraptor
|
|
12
11
|
@__iteraptor__ ||= Iteraptor::Delegator.new(self)
|
13
12
|
end
|
14
13
|
|
14
|
+
def get_in path
|
15
|
+
hash =
|
16
|
+
cada(full_parent: true, yield_all: true).with_object({}) do |(key, value), memo|
|
17
|
+
next unless path.length == key.length
|
18
|
+
next unless H.path_matcher(path).(key, value)
|
19
|
+
|
20
|
+
memo.enterrar!(key, value)
|
21
|
+
end.compactar
|
22
|
+
|
23
|
+
Iteraptor.apretar(hash)
|
24
|
+
end
|
25
|
+
|
26
|
+
def put_in path, value
|
27
|
+
update_in(path) { |_| value }
|
28
|
+
end
|
29
|
+
|
30
|
+
def update_in path, &λ
|
31
|
+
match_path = ->(key) { H.path_matcher(path, key, value) }
|
32
|
+
|
33
|
+
mapa(full_parent: true, yield_all: false) do |key, (k, value)|
|
34
|
+
H.path_matcher(path).(key, value) ? [k, λ.(value)] : [k, value]
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
15
38
|
%i[cada mapa].each do |m|
|
16
39
|
define_method m do |key = nil, value = nil, **params, &λ|
|
17
40
|
return enum_for(m, key, value, **params) unless λ
|
@@ -44,6 +67,16 @@ module Iteraptor
|
|
44
67
|
end
|
45
68
|
end
|
46
69
|
|
70
|
+
def self.apretar(object)
|
71
|
+
case object
|
72
|
+
when Enumerable
|
73
|
+
object.
|
74
|
+
map { |*maybe_kv| apretar(maybe_kv.flatten(1).last) }.
|
75
|
+
tap { |e| break e.first if !object.is_a?(Array) && e.is_a?(Array) && e.size == 1 }
|
76
|
+
else object
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
47
80
|
# rubocop:disable Style/Alias
|
48
81
|
alias_method :segar, :escoger
|
49
82
|
# rubocop:enable Style/Alias
|
@@ -84,6 +117,16 @@ module Iteraptor
|
|
84
117
|
end
|
85
118
|
end
|
86
119
|
|
120
|
+
def enterrar! key, value
|
121
|
+
key = [key] unless key.is_a?(Array)
|
122
|
+
|
123
|
+
if key.size == 1
|
124
|
+
self.tap { |this| this[key.first] = value }
|
125
|
+
else
|
126
|
+
(self[key.first] ||= key[1].is_a?(Integer) ? [] : {}).enterrar!(key[1..-1], value)
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
87
130
|
private
|
88
131
|
|
89
132
|
##############################################################################
|
@@ -233,6 +276,24 @@ module Iteraptor
|
|
233
276
|
def enumerable_parent?(receiver)
|
234
277
|
[Hash, Array, Enumerable].detect(&receiver.method(:is_a?))
|
235
278
|
end
|
279
|
+
|
280
|
+
def path_matcher path
|
281
|
+
pm =
|
282
|
+
path.map do |kind, value|
|
283
|
+
case kind
|
284
|
+
when :key, :elem, :at then ->(k, _) { value == k }
|
285
|
+
when :value then ->(_, v) { value == v }
|
286
|
+
when :filter then ->(_, v) { value.to_proc.(v) }
|
287
|
+
when :slice then ->(k, _) { value.cover?(k) }
|
288
|
+
when :filter_key
|
289
|
+
case value
|
290
|
+
when :all then ->(_, _) { true }
|
291
|
+
when ->(p) { p.respond_to?(:to_proc) } then ->(k, _) { value.to_proc.(k) }
|
292
|
+
end
|
293
|
+
end
|
294
|
+
end
|
295
|
+
->(key, value) { path.length == key.length && pm.zip(key).all? { |m, k| m.(k, value) } }
|
296
|
+
end
|
236
297
|
end
|
237
298
|
end
|
238
299
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: iteraptor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.10.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aleksei Matiushkin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-03-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -16,28 +16,28 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '2'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '2'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '13'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '13'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rspec
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -128,7 +128,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
128
128
|
version: '0'
|
129
129
|
requirements: []
|
130
130
|
rubyforge_project:
|
131
|
-
rubygems_version: 2.4
|
131
|
+
rubygems_version: 2.6.14.4
|
132
132
|
signing_key:
|
133
133
|
specification_version: 4
|
134
134
|
summary: 'Iterator on steroids: allows thorough iteration through nested Enumerables'
|