ree_lib 1.0.110 → 1.0.112

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0b8df95664f84438cd5e7c9b32c9f942bb4d39f3cf8c498d5da9ef3ee018bcdc
4
- data.tar.gz: c76b3c8f4edc5995b77dcc3be2fbdeb84a6145113b9709de45e3b0c72c6e8bb0
3
+ metadata.gz: 805e14e9b7c71c440d12245bffb67e6494ca4597ac93ffb3a96175ac95ea1db1
4
+ data.tar.gz: 4c907bd4276695b00e03265068d3576f2334a49153d25b31574f3fe63159e69a
5
5
  SHA512:
6
- metadata.gz: 76bc804c35d55a01a1819ec2a71648277c7dd722892774456f5cc8dfdabbbc98b4870535fca3a7fecd8d43a4d52091fb4bd4091ac906310d633089e7dfb135c8
7
- data.tar.gz: 69e33d02056be8fa3150c30489f4b35bb425788e5eb75afb7b71067fd7eafd9fa1231a3463a713f480276e2b5d3c37f8f82b2828ad65d156a204708cc2296e92
6
+ metadata.gz: 8f5fcce535a876c3d4ae1cd088ffcc145d5e370c3e51697f264bc3bfe7256b48d2b3823bf4a3a9f5849cbcf404a67007a8b6154f6736cca48063a70ff3414c06
7
+ data.tar.gz: 7dc29a59ff0816c0008feedbbabd9ac20749bd6eac95320da92b22b4f326f8cb3b9e3617f91d5296d8fcd19642377eacb3521a8e236ca2a8b72b486a5bcf5db5
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ree_lib (1.0.110)
4
+ ree_lib (1.0.112)
5
5
  bigdecimal (~> 3.1.6)
6
6
  binding_of_caller (~> 1.0.0)
7
7
  i18n (~> 1.14.1)
@@ -64,7 +64,7 @@ module ReeDto::DtoInstanceMethods
64
64
  def set_value(name, val)
65
65
  if has_value?(name)
66
66
  old = get_value(name)
67
- return if old == val
67
+ return old if old == val
68
68
  end
69
69
 
70
70
  @changed_fields ||= Set.new
@@ -9,7 +9,7 @@ class ReeMapper::Array < ReeMapper::AbstractWrapper
9
9
  ] => Array
10
10
  ).throws(ReeMapper::TypeError)
11
11
  def serialize(value, role: nil, fields_filters: nil)
12
- if !value.is_a?(Array)
12
+ if !check_value(value)
13
13
  raise ReeMapper::TypeError.new("should be an array, got `#{truncate(value.inspect)}`")
14
14
  end
15
15
 
@@ -40,7 +40,7 @@ class ReeMapper::Array < ReeMapper::AbstractWrapper
40
40
  ] => Array
41
41
  ).throws(ReeMapper::TypeError)
42
42
  def cast(value, role: nil, fields_filters: nil)
43
- if !value.is_a?(Array)
43
+ if !check_value(value)
44
44
  raise ReeMapper::TypeError.new("should be an array, got `#{truncate(value.inspect)}`")
45
45
  end
46
46
 
@@ -71,7 +71,7 @@ class ReeMapper::Array < ReeMapper::AbstractWrapper
71
71
  ] => Array
72
72
  ).throws(ReeMapper::TypeError)
73
73
  def db_dump(value, role: nil, fields_filters: nil)
74
- if !value.is_a?(Array)
74
+ if !check_value(value)
75
75
  raise ReeMapper::TypeError.new("should be an array, got `#{truncate(value.inspect)}`")
76
76
  end
77
77
 
@@ -102,7 +102,7 @@ class ReeMapper::Array < ReeMapper::AbstractWrapper
102
102
  ] => Array
103
103
  ).throws(ReeMapper::TypeError)
104
104
  def db_load(value, role: nil, fields_filters: nil)
105
- if !value.is_a?(Array)
105
+ if !check_value(value)
106
106
  raise ReeMapper::TypeError.new("should be an array, got `#{truncate(value.inspect)}`")
107
107
  end
108
108
 
@@ -124,4 +124,10 @@ class ReeMapper::Array < ReeMapper::AbstractWrapper
124
124
  raise e
125
125
  end
126
126
  end
127
+
128
+ private
129
+
130
+ def check_value(value)
131
+ value.is_a?(Array) || value.class.include?(Enumerable)
132
+ end
127
133
  end
@@ -22,7 +22,31 @@ RSpec.describe 'ReeMapper::Array' do
22
22
  }
23
23
  }
24
24
 
25
+ class EnumerableArray
26
+ include Enumerable
27
+
28
+ def initialize
29
+ @list = []
30
+ end
31
+
32
+ def each(&proc)
33
+ @list.each &proc
34
+ end
35
+
36
+ def add(v)
37
+ @list << v
38
+ end
39
+ end
40
+
25
41
  describe '#serialize' do
42
+ it {
43
+ ar = EnumerableArray.new
44
+ ar.add(1)
45
+ ar.add(2)
46
+
47
+ expect(mapper.serialize({ tags: ar, ary_of_ary: [[1]] })).to eq({ tags: [1, 2], ary_of_ary: [[1]] })
48
+ }
49
+
26
50
  it {
27
51
  expect(mapper.serialize({ tags: [1, 2], ary_of_ary: [[1]] })).to eq({ tags: [1, 2], ary_of_ary: [[1]] })
28
52
  }
@@ -41,6 +65,14 @@ RSpec.describe 'ReeMapper::Array' do
41
65
  end
42
66
 
43
67
  describe '#cast' do
68
+ it {
69
+ ar = EnumerableArray.new
70
+ ar.add(1)
71
+ ar.add(2)
72
+
73
+ expect(mapper.cast({ 'tags' => ar })).to eq({ tags: [1, 2] })
74
+ }
75
+
44
76
  it {
45
77
  expect(mapper.cast({ 'tags' => [1, 2] })).to eq({ tags: [1, 2] })
46
78
  }
@@ -51,6 +83,14 @@ RSpec.describe 'ReeMapper::Array' do
51
83
  end
52
84
 
53
85
  describe '#db_dump' do
86
+ it {
87
+ ar = EnumerableArray.new
88
+ ar.add(1)
89
+ ar.add(2)
90
+
91
+ expect(mapper.db_dump(OpenStruct.new({ tags: ar }))).to eq({ tags: [1, 2] })
92
+ }
93
+
54
94
  it {
55
95
  expect(mapper.db_dump(OpenStruct.new({ tags: [1, 2] }))).to eq({ tags: [1, 2] })
56
96
  }
@@ -61,6 +101,14 @@ RSpec.describe 'ReeMapper::Array' do
61
101
  end
62
102
 
63
103
  describe '#db_load' do
104
+ it {
105
+ ar = EnumerableArray.new
106
+ ar.add(1)
107
+ ar.add(2)
108
+
109
+ expect(mapper.db_load({ 'tags' => ar })).to eq({ tags: [1, 2] })
110
+ }
111
+
64
112
  it {
65
113
  expect(mapper.db_load({ 'tags' => [1, 2] })).to eq({ tags: [1, 2] })
66
114
  }
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ReeLib
4
- VERSION = "1.0.110"
4
+ VERSION = "1.0.112"
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.110
4
+ version: 1.0.112
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ruslan Gatiyatov