wolf_core 1.0.125 → 1.0.127
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: 632b7488235344fae01cfe265c0f3cc452e6a718b81fb58a5ebce2eb513338e8
|
4
|
+
data.tar.gz: b9cef8eab2c262922ea420174267e7c2d7ceebb360a807961ee562c44aa8ba29
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3b8e90b105ce69fd807842a1683362902d63b9b8f2789d668d5aef81f53a4073bc44f7132372a8caf4fa4fe65a51857354e7b9d9753c27d4c9dae777198a3350
|
7
|
+
data.tar.gz: cc55ef9c9780cbe39b86e3cfe6b33bb169a98a4850855cb952f1198a60d3f51494a347a6005b75bd64c946a795dd96cdd0b1fc9341dfb2a38ffdc64975040804
|
@@ -30,7 +30,11 @@ module WolfCore
|
|
30
30
|
end
|
31
31
|
|
32
32
|
def generate_id_prefix
|
33
|
-
|
33
|
+
complete_generate_id_prefix[0..4]
|
34
|
+
end
|
35
|
+
|
36
|
+
def complete_generate_id_prefix
|
37
|
+
self.class.to_s.underscore.split('/').last.downcase
|
34
38
|
end
|
35
39
|
end
|
36
40
|
end
|
@@ -4,8 +4,8 @@ module WolfCore
|
|
4
4
|
class InstanceApplicationSerializer
|
5
5
|
attr_reader :options
|
6
6
|
|
7
|
-
def initialize(options:
|
8
|
-
@options = options
|
7
|
+
def initialize(options: nil)
|
8
|
+
@options = options || {}
|
9
9
|
end
|
10
10
|
|
11
11
|
def self.attributes(*attrs)
|
@@ -29,23 +29,27 @@ module WolfCore
|
|
29
29
|
end
|
30
30
|
|
31
31
|
def serialize_all(collection:, options: nil)
|
32
|
-
|
33
|
-
|
32
|
+
Result.try do
|
33
|
+
options ||= {}
|
34
|
+
@options = @options.merge(options)
|
34
35
|
|
35
|
-
|
36
|
+
results = collection.map do |item|
|
37
|
+
result = serialize(object: item, options: @options)
|
38
|
+
result.raise_error
|
39
|
+
result
|
40
|
+
end
|
41
|
+
Result.success(data: { serialized_collection: results.map { |result| result.data.serialized_object } })
|
42
|
+
end
|
36
43
|
end
|
37
44
|
|
38
45
|
def serialize(object:, options: nil)
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
as_json(object: object).with_indifferent_access
|
43
|
-
end
|
46
|
+
Result.try do
|
47
|
+
options ||= {}
|
48
|
+
@options = @options.merge(options)
|
44
49
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
attributes.merge(relationships)
|
50
|
+
serialized_object = as_json(object: object).with_indifferent_access
|
51
|
+
Result.success(data: { serialized_object: serialized_object })
|
52
|
+
end
|
49
53
|
end
|
50
54
|
|
51
55
|
private
|
@@ -71,5 +75,11 @@ module WolfCore
|
|
71
75
|
end
|
72
76
|
end
|
73
77
|
end
|
78
|
+
|
79
|
+
def as_json(object:)
|
80
|
+
attributes = serialized_attributes(object: object)
|
81
|
+
relationships = serialized_relationships(object: object)
|
82
|
+
attributes.merge(relationships)
|
83
|
+
end
|
74
84
|
end
|
75
85
|
end
|
@@ -16,9 +16,13 @@ class Result
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def self.try
|
19
|
-
yield
|
19
|
+
try_result = yield
|
20
|
+
unless try_result.is_a?(Result)
|
21
|
+
raise StandardError, "Try result must be a Result object, got: #{try_result.class}"
|
22
|
+
end
|
23
|
+
try_result
|
20
24
|
rescue StandardError => e
|
21
|
-
Result.failure(error: { message: e.message,
|
25
|
+
Result.failure(error: { message: e.message, error_class: e.class, backtrace: e.backtrace })
|
22
26
|
end
|
23
27
|
|
24
28
|
def success?
|
@@ -71,4 +75,15 @@ class Result
|
|
71
75
|
end
|
72
76
|
fold_result
|
73
77
|
end
|
78
|
+
|
79
|
+
def raise_error
|
80
|
+
if failure?
|
81
|
+
err_class = error.error_class || StandardError
|
82
|
+
e = err_class.new(error.message)
|
83
|
+
if error.backtrace
|
84
|
+
e.set_backtrace(error.backtrace)
|
85
|
+
end
|
86
|
+
raise e
|
87
|
+
end
|
88
|
+
end
|
74
89
|
end
|
data/lib/wolf_core/version.rb
CHANGED