light_service_object 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/light_service_object.rb +21 -14
- data/lib/light_service_object/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fe7f5ce500fc97da2f221d27f178dadce48bfd13cc6241cb1f934e52af591761
|
4
|
+
data.tar.gz: d21d1c296cc99aef3600d6a49a4d0275cdc98c42387b97f88b29efba210b70a8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e288b1a3b6da66486d7adabe406689af6bb970ff74709be254ed60f931dc0bda9665b9011d207f93acdf991cc0e2020d883a7d64f7f0dcebdd24ecee78cbdd05
|
7
|
+
data.tar.gz: ecdc7a15394eeb532ac5f73711c57f8c89a7f4919bce77f2554e5a7728353864dff7ffa499bf7831277efca523c1e3506f744055b481119722c53352afb432a0
|
data/lib/light_service_object.rb
CHANGED
@@ -34,6 +34,12 @@ module LightServiceObject
|
|
34
34
|
extend Dry::Initializer
|
35
35
|
include Dry::Monads::Result::Mixin
|
36
36
|
|
37
|
+
|
38
|
+
## — CLASS METHODS
|
39
|
+
def self.result_class
|
40
|
+
@result_class
|
41
|
+
end
|
42
|
+
|
37
43
|
def self.param(key, **options)
|
38
44
|
raise Error.new("Do not use param in a service object")
|
39
45
|
end
|
@@ -52,10 +58,6 @@ module LightServiceObject
|
|
52
58
|
@result_class = klass.constantize if klass.is_a?(String)
|
53
59
|
end
|
54
60
|
|
55
|
-
class << self
|
56
|
-
attr_reader :result_class
|
57
|
-
end
|
58
|
-
|
59
61
|
def self.call(**options)
|
60
62
|
obj = self.new(**options)
|
61
63
|
|
@@ -65,6 +67,15 @@ module LightServiceObject
|
|
65
67
|
# ap("#{self.name} > Unknown Parameters #{unknown_params}") if unknown_params.present?
|
66
68
|
|
67
69
|
result = obj.call
|
70
|
+
end
|
71
|
+
|
72
|
+
## — INSTANCE METHODS
|
73
|
+
def result_class
|
74
|
+
self.class.result_class
|
75
|
+
end
|
76
|
+
|
77
|
+
def call
|
78
|
+
result = self.perform
|
68
79
|
if self.result_class.present?
|
69
80
|
if !result.is_a?(self.result_class)
|
70
81
|
a_name = "#{self.result_class}"
|
@@ -73,24 +84,20 @@ module LightServiceObject
|
|
73
84
|
fail!("#{self.name} is not returning #{a_name}")
|
74
85
|
end
|
75
86
|
end
|
76
|
-
|
77
87
|
Dry::Monads.Success(result)
|
78
88
|
rescue StandardError => error
|
79
|
-
self.
|
80
|
-
Dry::Monads.Failure(
|
89
|
+
reason = self.error_reason(error)
|
90
|
+
Dry::Monads.Failure(reason)
|
81
91
|
end
|
82
92
|
|
83
93
|
def fail!(error)
|
84
|
-
|
94
|
+
error = ::StandardError.new(error.to_s) if !error.is_a?(::StandardError)
|
95
|
+
raise error
|
85
96
|
end
|
86
97
|
|
87
|
-
def
|
98
|
+
def error_reason(error)
|
88
99
|
# Give subclasses a chance to see errors first
|
100
|
+
"#{self}: #{error}"
|
89
101
|
end
|
90
|
-
|
91
|
-
private
|
92
|
-
|
93
|
-
def call
|
94
|
-
end
|
95
102
|
end
|
96
103
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: light_service_object
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ben Sharpe
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-03-
|
11
|
+
date: 2019-03-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|