active_model_serializers_pg 0.0.2 → 0.0.3
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:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: c61aa96dfaadcdbb0304b0a8ea50b05468ad7474c6d3b740419c8bf525f28c01
|
|
4
|
+
data.tar.gz: 1d5dfd08ff5168add108de4854246f48ed564b0548d8a66155068d26d41f4805
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 32d433d676644d637de1cfda49d340f35221a6f1a08a5b8b74f605018e5f4169a45ec50bfcafe2c2fc20cb95e53cdaa98123e2b25b3246cafb276c2e68926301
|
|
7
|
+
data.tar.gz: d21913bd9baa516e016adcea39c28f4ce05446753553676485fd75cca1fbce1e36727df16bca2d6004b999ba6850d9ec14dc6bf29ac2f1c25660ee3b84dd31ae
|
|
@@ -15,6 +15,7 @@ module ActiveModelSerializersPg
|
|
|
15
15
|
include Enumerable
|
|
16
16
|
# PATCHED: implement this below so we don't need @serializers
|
|
17
17
|
# delegate :each, to: :@serializers
|
|
18
|
+
delegate :each, to: :serializers
|
|
18
19
|
|
|
19
20
|
attr_reader :object, :root
|
|
20
21
|
|
|
@@ -22,8 +23,13 @@ module ActiveModelSerializersPg
|
|
|
22
23
|
@object = resources
|
|
23
24
|
@options = options
|
|
24
25
|
@root = options[:root]
|
|
25
|
-
# PATCHED: We don't want to
|
|
26
|
-
#
|
|
26
|
+
# PATCHED: We don't want to materialize a Relation by iterating unless we have to.
|
|
27
|
+
# On the other hand, if we don't have a serializer we *do* want to `throw :no_serializer`
|
|
28
|
+
# right away. That should only happen for basic types (like a String or Hash),
|
|
29
|
+
# so we act lazy when we have a Relation, and eager otherwise:
|
|
30
|
+
unless resources.is_a? ActiveRecord::Relation
|
|
31
|
+
@serializers = serializers_from_resources
|
|
32
|
+
end
|
|
27
33
|
end
|
|
28
34
|
|
|
29
35
|
# PATCH: Give ourselves access to the serializer for the individual elements:
|
|
@@ -76,25 +82,17 @@ module ActiveModelSerializersPg
|
|
|
76
82
|
object.respond_to?(:size)
|
|
77
83
|
end
|
|
78
84
|
|
|
79
|
-
# PATCHED: Add a replacement to `each` so we don't change the interface:
|
|
80
|
-
def each
|
|
81
|
-
Rails.logger.debug caller.join("\n")
|
|
82
|
-
Enumerator.new do |y|
|
|
83
|
-
serializers_from_resources.each do |ser|
|
|
84
|
-
y.yield ser
|
|
85
|
-
end
|
|
86
|
-
end
|
|
87
|
-
end
|
|
88
|
-
|
|
89
85
|
protected
|
|
90
86
|
|
|
91
|
-
attr_reader :
|
|
87
|
+
attr_reader :options
|
|
88
|
+
|
|
89
|
+
def serializers
|
|
90
|
+
@serializers ||= serializers_from_resources
|
|
91
|
+
end
|
|
92
92
|
|
|
93
93
|
private
|
|
94
94
|
|
|
95
95
|
def serializers_from_resources
|
|
96
|
-
puts "options here"
|
|
97
|
-
pp options
|
|
98
96
|
serializer_context_class = options.fetch(:serializer_context_class, ActiveModel::Serializer)
|
|
99
97
|
object.map do |resource|
|
|
100
98
|
serializer_from_resource(resource, serializer_context_class, options)
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: active_model_serializers_pg
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Paul A. Jungwirth
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2019-10-
|
|
11
|
+
date: 2019-10-16 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: active_model_serializers
|