ree_lib 1.0.110 → 1.0.112
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_dto/package/ree_dto/dto/dto_instance_methods.rb +1 -1
- data/lib/ree_lib/packages/ree_mapper/package/ree_mapper/wrappers/array.rb +10 -4
- data/lib/ree_lib/packages/ree_mapper/spec/ree_mapper/wrappers/array_spec.rb +48 -0
- 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: 805e14e9b7c71c440d12245bffb67e6494ca4597ac93ffb3a96175ac95ea1db1
|
4
|
+
data.tar.gz: 4c907bd4276695b00e03265068d3576f2334a49153d25b31574f3fe63159e69a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8f5fcce535a876c3d4ae1cd088ffcc145d5e370c3e51697f264bc3bfe7256b48d2b3823bf4a3a9f5849cbcf404a67007a8b6154f6736cca48063a70ff3414c06
|
7
|
+
data.tar.gz: 7dc29a59ff0816c0008feedbbabd9ac20749bd6eac95320da92b22b4f326f8cb3b9e3617f91d5296d8fcd19642377eacb3521a8e236ca2a8b72b486a5bcf5db5
|
data/Gemfile.lock
CHANGED
@@ -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
|
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
|
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
|
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
|
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
|
}
|
data/lib/ree_lib/version.rb
CHANGED