ree_lib 1.0.108 → 1.0.110
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/ree_lib/packages/ree_array/package/ree_array/functions/group_by.rb +1 -1
- data/lib/ree_lib/packages/ree_array/package/ree_array/functions/in_groups.rb +4 -4
- data/lib/ree_lib/packages/ree_array/package/ree_array/functions/in_groups_of.rb +4 -4
- data/lib/ree_lib/packages/ree_array/package/ree_array/functions/index_by.rb +1 -1
- data/lib/ree_lib/packages/ree_array/package/ree_array/functions/split_by.rb +2 -2
- data/lib/ree_lib/packages/ree_array/package/ree_array/functions/wrap.rb +4 -4
- data/lib/ree_lib/packages/ree_array/spec/ree_array/functions/index_by_spec.rb +31 -0
- data/lib/ree_lib/packages/ree_dto/package/ree_dto/dto/dto_collection.rb +0 -10
- data/lib/ree_lib/version.rb +1 -1
- 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: 0b8df95664f84438cd5e7c9b32c9f942bb4d39f3cf8c498d5da9ef3ee018bcdc
|
4
|
+
data.tar.gz: c76b3c8f4edc5995b77dcc3be2fbdeb84a6145113b9709de45e3b0c72c6e8bb0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 76bc804c35d55a01a1819ec2a71648277c7dd722892774456f5cc8dfdabbbc98b4870535fca3a7fecd8d43a4d52091fb4bd4091ac906310d633089e7dfb135c8
|
7
|
+
data.tar.gz: 69e33d02056be8fa3150c30489f4b35bb425788e5eb75afb7b71067fd7eafd9fa1231a3463a713f480276e2b5d3c37f8f82b2828ad65d156a204708cc2296e92
|
data/Gemfile.lock
CHANGED
@@ -8,24 +8,24 @@ class ReeArray::InGroups
|
|
8
8
|
doc(<<~DOC)
|
9
9
|
Splits or iterates over the array in +number+ of groups, padding any
|
10
10
|
remaining slots with +fill_with+ unless it is +false+.
|
11
|
-
|
11
|
+
|
12
12
|
in_groups(%w(1 2 3 4 5 6 7 8 9 10), 3, fill_with: nil) {|group| p group}
|
13
13
|
["1", "2", "3", "4"]
|
14
14
|
["5", "6", "7", nil]
|
15
15
|
["8", "9", "10", nil]
|
16
|
-
|
16
|
+
|
17
17
|
in_groups(%w(1 2 3 4 5 6 7 8 9 10, 3, fill_with: ' ') {|group| p group}
|
18
18
|
["1", "2", "3", "4"]
|
19
19
|
["5", "6", "7", " "]
|
20
20
|
["8", "9", "10", " "]
|
21
|
-
|
21
|
+
|
22
22
|
in_groups(%w(1 2 3 4 5 6 7), 3) {|group| p group}
|
23
23
|
["1", "2", "3"]
|
24
24
|
["4", "5"]
|
25
25
|
["6", "7"]
|
26
26
|
DOC
|
27
27
|
contract(
|
28
|
-
ArrayOf[Any],
|
28
|
+
Or[ArrayOf[Any], Enumerable],
|
29
29
|
Integer,
|
30
30
|
Ksplat[fill_with?: Any],
|
31
31
|
Optblock => Or[ArrayOf[Any], Any]
|
@@ -8,25 +8,25 @@ class ReeArray::InGroupsOf
|
|
8
8
|
doc(<<~DOC)
|
9
9
|
Splits or iterates over the array in groups of size +number+,
|
10
10
|
padding any remaining slots with +fill_with+ unless it is +false+.
|
11
|
-
|
11
|
+
|
12
12
|
in_groups_of(%w(1 2 3 4 5 6 7 8 9 10), 3, fill_with: nil) {|group| p group}
|
13
13
|
["1", "2", "3"]
|
14
14
|
["4", "5", "6"]
|
15
15
|
["7", "8", "9"]
|
16
16
|
["10", nil, nil]
|
17
|
-
|
17
|
+
|
18
18
|
in_groups_of(%w(1 2 3 4 5), 2, fill_with: ' ') {|group| p group}
|
19
19
|
["1", "2"]
|
20
20
|
["3", "4"]
|
21
21
|
["5", " "]
|
22
|
-
|
22
|
+
|
23
23
|
in_groups_of(%w(1 2 3 4 5), 2) {|group| p group}
|
24
24
|
["1", "2"]
|
25
25
|
["3", "4"]
|
26
26
|
["5"]
|
27
27
|
DOC
|
28
28
|
contract(
|
29
|
-
ArrayOf[Any],
|
29
|
+
Or[ArrayOf[Any], Enumerable],
|
30
30
|
Integer,
|
31
31
|
Ksplat[fill_with?: Any],
|
32
32
|
Optblock => Or[ArrayOf[Any], ArrayOf[ArrayOf[Any]]]
|
@@ -8,11 +8,11 @@ class ReeArray::SplitBy
|
|
8
8
|
doc(<<~DOC)
|
9
9
|
Divides the array into one or more subarrays based on a delimiting +value+
|
10
10
|
or the result of an optional block.
|
11
|
-
|
11
|
+
|
12
12
|
split([1, 2, 3, 4, 5], 3) # => [[1, 2], [4, 5]]
|
13
13
|
split((1..10).to_a) { |i| i % 3 == 0 } # => [[1, 2], [4, 5], [7, 8], [10]]
|
14
14
|
DOC
|
15
|
-
contract(ArrayOf[Any], Any, Optblock => ArrayOf[Any])
|
15
|
+
contract(Or[ArrayOf[Any], Enumerable], Any, Optblock => ArrayOf[Any])
|
16
16
|
def call(array, value = nil, &block)
|
17
17
|
arr = array.dup
|
18
18
|
result = []
|
@@ -7,13 +7,13 @@ class ReeArray::Wrap
|
|
7
7
|
|
8
8
|
doc(<<~DOC)
|
9
9
|
Wraps its argument in an array unless it is already an array (or array-like).
|
10
|
-
|
10
|
+
|
11
11
|
Specifically:
|
12
|
-
|
12
|
+
|
13
13
|
* If the argument is +nil+ an empty array is returned.
|
14
14
|
* Otherwise, if the argument responds to +to_ary+ it is invoked, and its result returned.
|
15
15
|
* Otherwise, returns an array with the argument as its single element.
|
16
|
-
|
16
|
+
|
17
17
|
wrap(nil) # => []
|
18
18
|
wrap([1, 2, 3]) # => [1, 2, 3]
|
19
19
|
wrap(0) # => [0]
|
@@ -22,7 +22,7 @@ class ReeArray::Wrap
|
|
22
22
|
def call(object)
|
23
23
|
if object.nil?
|
24
24
|
[]
|
25
|
-
elsif object.is_a?(Array)
|
25
|
+
elsif object.is_a?(Array) || object.is_a?(Enumerable)
|
26
26
|
object
|
27
27
|
else
|
28
28
|
[object]
|
@@ -14,4 +14,35 @@ RSpec.describe :index_by do
|
|
14
14
|
}
|
15
15
|
)
|
16
16
|
}
|
17
|
+
|
18
|
+
it {
|
19
|
+
class EnumerableArray
|
20
|
+
include Enumerable
|
21
|
+
|
22
|
+
def initialize
|
23
|
+
@list = []
|
24
|
+
end
|
25
|
+
|
26
|
+
def each(&proc)
|
27
|
+
@list.each &proc
|
28
|
+
end
|
29
|
+
|
30
|
+
def add(v)
|
31
|
+
@list << v
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
list = EnumerableArray.new
|
36
|
+
list.add({id: 1})
|
37
|
+
list.add({id: 2})
|
38
|
+
|
39
|
+
result = index_by(list) { _1[:id] }
|
40
|
+
|
41
|
+
expect(result).to eq(
|
42
|
+
{
|
43
|
+
1 => {id: 1},
|
44
|
+
2 => {id: 2}
|
45
|
+
}
|
46
|
+
)
|
47
|
+
}
|
17
48
|
end
|
@@ -12,21 +12,11 @@ class ReeDto::DtoCollection
|
|
12
12
|
@parent_class = parent_class
|
13
13
|
@contract = contract
|
14
14
|
@name = name
|
15
|
-
@list = nil
|
16
|
-
end
|
17
|
-
|
18
|
-
contract None => nil
|
19
|
-
def reset
|
20
15
|
@list = []
|
21
|
-
nil
|
22
16
|
end
|
23
17
|
|
24
18
|
contract Optblock => Any
|
25
19
|
def each(&block)
|
26
|
-
if @list.nil?
|
27
|
-
raise LoadError.new("collection :#{@name} for #{@parent_class} is not loaded")
|
28
|
-
end
|
29
|
-
|
30
20
|
@list.each(&block)
|
31
21
|
end
|
32
22
|
|
data/lib/ree_lib/version.rb
CHANGED