praxis-mapper 4.4.1 → 4.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/lib/praxis-mapper/resource.rb +5 -4
- data/lib/praxis-mapper/version.rb +1 -1
- data/spec/praxis-mapper/resource_spec.rb +8 -0
- 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: 0006c7fa042540a90f59a1b0b5c46970a65992c784ec1aada8b277565065d3cd
|
4
|
+
data.tar.gz: 528bfc8868e9f5398dcc235ca6736d6c767fba72a0fdba114be21d03cd50105f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 528e131bae155211ecce7a8d6accd9296ecad5765e69988e32093712db6bd104839d23abfe86117907d12aa023b032d87bb847d8a7834fa6d041bb1dff472025
|
7
|
+
data.tar.gz: 79cd448c7622c39ca626147fec68b24f2e9273947542c497d65b4a4290a428fcc52d33704bee00fb5fa0a5a14e47a986a9f9bf731fbd35410dee4911b16fde14
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
# praxis-mapper changelog
|
2
2
|
|
3
|
+
## 4.5 (6/25/2019)
|
4
|
+
|
5
|
+
* Support wrapping associations in resources for targets that do not explicitly contain the `Enumerable` module. For example, `ActiveRecord::Associations::CollectionProxy` are actually not enumerable, yet they proxy the calls directly to the underlying objects when necessary.
|
6
|
+
|
3
7
|
## 4.4.1 (6/25/2019)
|
4
8
|
|
5
9
|
* Fix `Resource` to not override association methods already defined
|
@@ -145,11 +145,12 @@ module Praxis::Mapper
|
|
145
145
|
|
146
146
|
|
147
147
|
def self.wrap(records)
|
148
|
-
|
149
|
-
when nil
|
148
|
+
if records.nil?
|
150
149
|
return []
|
151
|
-
|
152
|
-
return records.compact.
|
150
|
+
elsif( records.is_a?(Enumerable) )
|
151
|
+
return records.compact.map { |record| self.for_record(record) }
|
152
|
+
elsif ( records.respond_to?(:to_a) )
|
153
|
+
return records.to_a.compact.map { |record| self.for_record(record) }
|
153
154
|
else
|
154
155
|
return self.for_record(records)
|
155
156
|
end
|
@@ -200,6 +200,14 @@ describe Praxis::Mapper::Resource do
|
|
200
200
|
wrapped_set.should be_kind_of(Array)
|
201
201
|
wrapped_set.length.should be(1)
|
202
202
|
end
|
203
|
+
|
204
|
+
it 'works with non-enumerable objects, that respond to collect' do
|
205
|
+
collectable = double("ArrayProxy")
|
206
|
+
collectable.stub(:to_a) { [record, record] }
|
207
|
+
|
208
|
+
wrapped_set = SimpleResource.wrap(collectable)
|
209
|
+
wrapped_set.length.should be(2)
|
210
|
+
end
|
203
211
|
|
204
212
|
it 'works regardless of the resource class used' do
|
205
213
|
SimpleResource.wrap(record).should be(OtherResource.wrap(record))
|