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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 896dcde182ff4343261aa23d3973237260f81e82b9a9a349b7c93f429737fef3
4
- data.tar.gz: 1cf94f98559f130796b3ac6e66c11071d6cc47fc17f8d6f2ab5792e881c6324b
3
+ metadata.gz: 0b8df95664f84438cd5e7c9b32c9f942bb4d39f3cf8c498d5da9ef3ee018bcdc
4
+ data.tar.gz: c76b3c8f4edc5995b77dcc3be2fbdeb84a6145113b9709de45e3b0c72c6e8bb0
5
5
  SHA512:
6
- metadata.gz: 8827e41de3987b8bf0bbbf8f0178e3612f4ad2303fbce7375510256fcb123ea7432c5cbc5325e8833efe872b8ee9604b2ba8e4237707f539250faca86bb27ab1
7
- data.tar.gz: 1ab05f373d35931c0750355b4c9fe652e133bc75583a363ebc17973f640d848dc7baba1517d6ed43820136ef0bf0e9957880a0713d72e4e0405f0cc6d433e363
6
+ metadata.gz: 76bc804c35d55a01a1819ec2a71648277c7dd722892774456f5cc8dfdabbbc98b4870535fca3a7fecd8d43a4d52091fb4bd4091ac906310d633089e7dfb135c8
7
+ data.tar.gz: 69e33d02056be8fa3150c30489f4b35bb425788e5eb75afb7b71067fd7eafd9fa1231a3463a713f480276e2b5d3c37f8f82b2828ad65d156a204708cc2296e92
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ree_lib (1.0.108)
4
+ ree_lib (1.0.110)
5
5
  bigdecimal (~> 3.1.6)
6
6
  binding_of_caller (~> 1.0.0)
7
7
  i18n (~> 1.14.1)
@@ -6,7 +6,7 @@ class ReeArray::GroupBy
6
6
  fn :group_by
7
7
 
8
8
  contract(
9
- ArrayOf[Any], Block => HashOf[Any, ArrayOf[Any]]
9
+ Or[ArrayOf[Any], Enumerable], Block => HashOf[Any, ArrayOf[Any]]
10
10
  )
11
11
  def call(list, &proc)
12
12
  result = {}
@@ -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: '&nbsp;') {|group| p group}
18
18
  ["1", "2", "3", "4"]
19
19
  ["5", "6", "7", "&nbsp;"]
20
20
  ["8", "9", "10", "&nbsp;"]
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: '&nbsp;') {|group| p group}
19
19
  ["1", "2"]
20
20
  ["3", "4"]
21
21
  ["5", "&nbsp;"]
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]]]
@@ -5,7 +5,7 @@ class ReeArray::IndexBy
5
5
 
6
6
  fn :index_by
7
7
 
8
- contract(ArrayOf[Any], Block => Hash)
8
+ contract(Or[ArrayOf[Any], Enumerable], Block => Hash)
9
9
  def call(list, &proc)
10
10
  result = {}
11
11
  list.each { result[yield(_1)] = _1 }
@@ -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
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ReeLib
4
- VERSION = "1.0.108"
4
+ VERSION = "1.0.110"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ree_lib
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.108
4
+ version: 1.0.110
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ruslan Gatiyatov