remap 2.2.49 → 2.2.50
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/remap/selector/all.rb +9 -9
- data/lib/remap/selector/index.rb +8 -10
- data/lib/remap/selector/key.rb +8 -10
- data/lib/remap/selector.rb +0 -10
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a036948beb3769bca586002c771569e54639a3a60314bac615a8f2dbb25a546b
|
4
|
+
data.tar.gz: 966315eb1929aa681d95d477e72a4545bdc435a4a4e3583d1cec875e8061d479
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f9afa516dd3d8248b714744598c847d04525f1d2d0e0f320128c6b785281b0a40e93d1b444cca6b4d1b6199bdb85dffa5fe4cda1c1d9ef97ec58f348a4994271
|
7
|
+
data.tar.gz: 72c2bfaaecc2553b3097f5b464cb03772314dab2127b5154d64b6e99e7e0c028ccba987c94acda788c7fa9229f48a626c895d558a6a974d8cbf95ae16b2d7ea5
|
data/lib/remap/selector/all.rb
CHANGED
@@ -15,28 +15,28 @@ module Remap
|
|
15
15
|
# end
|
16
16
|
# result.fetch(:value) # => [Hash, Hash]
|
17
17
|
class All < Concrete
|
18
|
-
requirement Types::Enumerable
|
19
|
-
|
20
18
|
# Iterates over state and passes each value to block
|
21
19
|
#
|
22
|
-
# @param
|
20
|
+
# @param state [State<Enumerable<T>>]
|
23
21
|
#
|
24
22
|
# @yieldparam [State<T>]
|
25
23
|
# @yieldreturn [State<U>]
|
26
24
|
#
|
27
25
|
# @return [State<U>]
|
28
|
-
def call(
|
26
|
+
def call(state, &block)
|
29
27
|
unless block
|
30
28
|
raise ArgumentError, "All selector requires an iteration block"
|
31
29
|
end
|
32
30
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
end
|
31
|
+
value = state.fetch(:value) do
|
32
|
+
return state
|
33
|
+
end
|
37
34
|
|
38
|
-
|
35
|
+
unless value.is_a?(Enumerable)
|
36
|
+
state.fatal!("Not an enumerator")
|
39
37
|
end
|
38
|
+
|
39
|
+
state.map(&block)
|
40
40
|
end
|
41
41
|
end
|
42
42
|
end
|
data/lib/remap/selector/index.rb
CHANGED
@@ -20,8 +20,6 @@ module Remap
|
|
20
20
|
# @return [Integer]
|
21
21
|
attribute :index, Integer
|
22
22
|
|
23
|
-
requirement Types::Array
|
24
|
-
|
25
23
|
# Selects the {#index}th element from state and passes it to block
|
26
24
|
#
|
27
25
|
# @param state [State<Array<T>>]
|
@@ -35,17 +33,17 @@ module Remap
|
|
35
33
|
raise ArgumentError, "The index selector requires an iteration block"
|
36
34
|
end
|
37
35
|
|
38
|
-
state.
|
39
|
-
requirement[array] do
|
40
|
-
s.fatal!("Expected an array")
|
41
|
-
end
|
36
|
+
array = state.fetch(:value) { return state }
|
42
37
|
|
43
|
-
|
44
|
-
|
45
|
-
|
38
|
+
unless array.is_a?(Array)
|
39
|
+
state.fatal!("Expected an array got %s", array.class)
|
40
|
+
end
|
46
41
|
|
47
|
-
|
42
|
+
value = array.fetch(index) do
|
43
|
+
state.ignore!("Index [%s] (%s) not found", index, index.class)
|
48
44
|
end
|
45
|
+
|
46
|
+
state.set(value, index: index).then(&block)
|
49
47
|
end
|
50
48
|
end
|
51
49
|
end
|
data/lib/remap/selector/key.rb
CHANGED
@@ -17,8 +17,6 @@ module Remap
|
|
17
17
|
# @return [#hash
|
18
18
|
attribute :key, Types::Key
|
19
19
|
|
20
|
-
requirement Types::Hash
|
21
|
-
|
22
20
|
# Selects {#key} from state and passes it to block
|
23
21
|
#
|
24
22
|
# @param state [State<Hash<K, V>>]
|
@@ -32,17 +30,17 @@ module Remap
|
|
32
30
|
raise ArgumentError, "The key selector requires an iteration block"
|
33
31
|
end
|
34
32
|
|
35
|
-
state.
|
36
|
-
requirement[hash] do
|
37
|
-
s.fatal!("Expected hash")
|
38
|
-
end
|
33
|
+
hash = state.fetch(:value) { return state }
|
39
34
|
|
40
|
-
|
41
|
-
|
42
|
-
|
35
|
+
unless hash.is_a?(Hash)
|
36
|
+
state.fatal!("Expected hash got %s", hash.class)
|
37
|
+
end
|
43
38
|
|
44
|
-
|
39
|
+
value = hash.fetch(key) do
|
40
|
+
state.ignore!("Key [%s] (%s) not found", key, key.class)
|
45
41
|
end
|
42
|
+
|
43
|
+
state.set(value, key: key).then(&block)
|
46
44
|
end
|
47
45
|
end
|
48
46
|
end
|
data/lib/remap/selector.rb
CHANGED
@@ -4,9 +4,6 @@ module Remap
|
|
4
4
|
# Defines how a path element, or selector
|
5
5
|
# Specifies how a value is extracted from a state
|
6
6
|
class Selector < Dry::Interface
|
7
|
-
defines :requirement, type: Types::Any.constrained(type: Dry::Types::Type)
|
8
|
-
requirement Types::Any
|
9
|
-
|
10
7
|
# Selects value from state, package it as a state and passes it to block
|
11
8
|
#
|
12
9
|
# @param state [State]
|
@@ -20,12 +17,5 @@ module Remap
|
|
20
17
|
def call(state)
|
21
18
|
raise NotImplementedError, "#{self.class}#call not implemented"
|
22
19
|
end
|
23
|
-
|
24
|
-
private
|
25
|
-
|
26
|
-
# @return [Dry::Types::Type]
|
27
|
-
def requirement
|
28
|
-
self.class.requirement
|
29
|
-
end
|
30
20
|
end
|
31
21
|
end
|