iteraptor 0.9.0 → 0.10.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.travis.yml +3 -3
- data/lib/iteraptor/delegator.rb +3 -1
- data/lib/iteraptor/version.rb +1 -1
- data/lib/iteraptor.rb +62 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA1:
|
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/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
|
@@ -127,7 +127,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
127
127
|
- !ruby/object:Gem::Version
|
128
128
|
version: '0'
|
129
129
|
requirements: []
|
130
|
-
|
130
|
+
rubyforge_project:
|
131
|
+
rubygems_version: 2.6.14.4
|
131
132
|
signing_key:
|
132
133
|
specification_version: 4
|
133
134
|
summary: 'Iterator on steroids: allows thorough iteration through nested Enumerables'
|