light_service_object 0.1.6 → 0.1.7
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 +4 -4
- data/Gemfile.lock +1 -1
- data/lib/light_service_object/version.rb +1 -1
- data/lib/light_service_object.rb +9 -14
- 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: e700271db3a2b52514ce8b2174a4f955c1926c70b60f370ecdcd69e71698b4dc
|
4
|
+
data.tar.gz: d13ece90b9a57c819b6b028ec19a0dc88d60af261883c8862bffe7d856b09986
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '095296979110b150d06f473690212b2a9085e6595367622649b01eea8b3f4a1df6be9d56b3d9288ac2e60a40fe72faa997197ed34cf3cfc92dc06ed6e86be8c1'
|
7
|
+
data.tar.gz: 6dac101c8261634d7c099d9ba73505e539021b91a26c9c4f6d7685345bf99eb93197d1772015a359decbfd60c6818a0e775ad62088a577172bee6db248c9fa7a
|
data/Gemfile.lock
CHANGED
data/lib/light_service_object.rb
CHANGED
@@ -30,11 +30,12 @@ if defined?(Ensurance)
|
|
30
30
|
end
|
31
31
|
|
32
32
|
module LightServiceObject
|
33
|
+
class ServiceError < StandardError; end
|
34
|
+
|
33
35
|
class Base
|
34
36
|
extend Dry::Initializer
|
35
37
|
include Dry::Monads::Result::Mixin
|
36
38
|
|
37
|
-
|
38
39
|
## — CLASS METHODS
|
39
40
|
class << self
|
40
41
|
def result_class
|
@@ -71,16 +72,10 @@ module LightServiceObject
|
|
71
72
|
def call(**options)
|
72
73
|
begin
|
73
74
|
obj = self.new(**options)
|
74
|
-
|
75
|
-
|
75
|
+
obj.call
|
76
|
+
rescue KeyError => error
|
77
|
+
Dry::Monads.Failure(error.message)
|
76
78
|
end
|
77
|
-
|
78
|
-
# Identify incoming params that weren't specified
|
79
|
-
# set_params = obj.instance_variables.map{|e| e.to_s.tr("@","").to_sym }
|
80
|
-
# unknown_params = (options.keys - set_params)
|
81
|
-
# ap("#{self.name} > Unknown Parameters #{unknown_params}") if unknown_params.present?
|
82
|
-
|
83
|
-
result = obj.call
|
84
79
|
end
|
85
80
|
end
|
86
81
|
|
@@ -103,15 +98,15 @@ module LightServiceObject
|
|
103
98
|
end
|
104
99
|
end
|
105
100
|
Dry::Monads.Success(result)
|
106
|
-
rescue
|
107
|
-
|
101
|
+
rescue Exception => error
|
102
|
+
Dry::Monads.Failure(error.message)
|
108
103
|
end
|
109
104
|
|
110
105
|
def fail!(error)
|
111
|
-
error =
|
106
|
+
error = ServiceError.new(error.to_s) if !error.is_a?(ServiceError)
|
112
107
|
reason = self.error_reason(error)
|
113
108
|
self.class.failed(error)
|
114
|
-
|
109
|
+
raise error
|
115
110
|
end
|
116
111
|
|
117
112
|
def error_reason(error)
|