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: dba2a15bc40ef492def433376e96f7599893f6759b280b2159928564fe3b61a7
4
- data.tar.gz: df41d9d2fcfb8c3f9b868bf5e6106b23c912d921161c36415d4751ee1ab1438d
3
+ metadata.gz: 632b7488235344fae01cfe265c0f3cc452e6a718b81fb58a5ebce2eb513338e8
4
+ data.tar.gz: b9cef8eab2c262922ea420174267e7c2d7ceebb360a807961ee562c44aa8ba29
5
5
  SHA512:
6
- metadata.gz: 3c27c70601c3f87e8083600873a113caa49b315230d40dd33c47510a9c097a60dcd6856e16d34f68118acdb55f32d4b12c1598f43e50c87ef263ac4a23f69f1c
7
- data.tar.gz: 3c224e65029a57f28d0468e98937098665c72bb7884b434506de6e0ec71d228461667af1319a161c519381d6b89e3f4bb4c18cb4d1053e949a588f6c46327ff0
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
- self.class.to_s.underscore.split('/').last.downcase[0..4]
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
- options ||= {}
33
- @options = @options.merge(options)
32
+ Result.try do
33
+ options ||= {}
34
+ @options = @options.merge(options)
34
35
 
35
- collection.map { |item| serialize(object: item, options: @options) }
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
- options ||= {}
40
- @options = @options.merge(options)
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
- def as_json(object:)
46
- attributes = serialized_attributes(object: object)
47
- relationships = serialized_relationships(object: object)
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, original_backtrace: e.backtrace })
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module WolfCore
4
- VERSION = "1.0.125"
4
+ VERSION = "1.0.127"
5
5
  end
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.125
4
+ version: 1.0.127
5
5
  platform: ruby
6
6
  authors:
7
7
  - Javier Roncallo