wolf_core 1.0.123 → 1.0.125
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: dba2a15bc40ef492def433376e96f7599893f6759b280b2159928564fe3b61a7
|
4
|
+
data.tar.gz: df41d9d2fcfb8c3f9b868bf5e6106b23c912d921161c36415d4751ee1ab1438d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3c27c70601c3f87e8083600873a113caa49b315230d40dd33c47510a9c097a60dcd6856e16d34f68118acdb55f32d4b12c1598f43e50c87ef263ac4a23f69f1c
|
7
|
+
data.tar.gz: 3c224e65029a57f28d0468e98937098665c72bb7884b434506de6e0ec71d228461667af1319a161c519381d6b89e3f4bb4c18cb4d1053e949a588f6c46327ff0
|
@@ -0,0 +1,75 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module WolfCore
|
4
|
+
class InstanceApplicationSerializer
|
5
|
+
attr_reader :options
|
6
|
+
|
7
|
+
def initialize(options: {})
|
8
|
+
@options = options
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.attributes(*attrs)
|
12
|
+
_attributes.concat(attrs.map(&:to_sym))
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.has_many(relationship, serializer:) # rubocop:disable Naming/PredicateName
|
16
|
+
_relationships[relationship.to_sym] = serializer
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.has_one(relationship, serializer:) # rubocop:disable Naming/PredicateName
|
20
|
+
_relationships[relationship.to_sym] = serializer
|
21
|
+
end
|
22
|
+
|
23
|
+
def self._attributes
|
24
|
+
@_attributes ||= []
|
25
|
+
end
|
26
|
+
|
27
|
+
def self._relationships
|
28
|
+
@_relationships ||= {}
|
29
|
+
end
|
30
|
+
|
31
|
+
def serialize_all(collection:, options: nil)
|
32
|
+
options ||= {}
|
33
|
+
@options = @options.merge(options)
|
34
|
+
|
35
|
+
collection.map { |item| serialize(object: item, options: @options) }
|
36
|
+
end
|
37
|
+
|
38
|
+
def serialize(object:, options: nil)
|
39
|
+
options ||= {}
|
40
|
+
@options = @options.merge(options)
|
41
|
+
|
42
|
+
as_json(object: object).with_indifferent_access
|
43
|
+
end
|
44
|
+
|
45
|
+
def as_json(object:)
|
46
|
+
attributes = serialized_attributes(object: object)
|
47
|
+
relationships = serialized_relationships(object: object)
|
48
|
+
attributes.merge(relationships)
|
49
|
+
end
|
50
|
+
|
51
|
+
private
|
52
|
+
|
53
|
+
def serialized_attributes(object:)
|
54
|
+
self.class._attributes.each_with_object({}) do |attribute, hash|
|
55
|
+
hash[attribute] = if respond_to?(attribute, true)
|
56
|
+
send(attribute)
|
57
|
+
elsif object.respond_to?(attribute)
|
58
|
+
object.public_send(attribute)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def serialized_relationships(object:)
|
64
|
+
self.class._relationships.each_with_object({}) do |(key, serializer_class), hash|
|
65
|
+
serializer = serializer_class.new(options: @options)
|
66
|
+
related_object = object.public_send(key)
|
67
|
+
hash[key] = if related_object.is_a?(Enumerable)
|
68
|
+
serializer.serialize_all(collection: related_object)
|
69
|
+
else
|
70
|
+
serializer.serialize(object: related_object)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
data/lib/wolf_core/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wolf_core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.125
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Javier Roncallo
|
@@ -142,6 +142,7 @@ files:
|
|
142
142
|
- lib/wolf_core/infrastructure/http_operations.rb
|
143
143
|
- lib/wolf_core/infrastructure/in_memory_storage_data_source.rb
|
144
144
|
- lib/wolf_core/infrastructure/in_memory_storage_operations.rb
|
145
|
+
- lib/wolf_core/infrastructure/instance_application_serializer.rb
|
145
146
|
- lib/wolf_core/infrastructure/lambda_function_data_source.rb
|
146
147
|
- lib/wolf_core/infrastructure/lambda_function_operations.rb
|
147
148
|
- lib/wolf_core/infrastructure/no_sql_db_data_source.rb
|