u-service 0.8.0 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +2 -2
- data/README.md +2 -2
- data/lib/micro/service/pipeline.rb +1 -1
- data/lib/micro/service/result/failure.rb +11 -0
- data/lib/micro/service/result/helpers.rb +19 -0
- data/lib/micro/service/result/success.rb +11 -0
- data/lib/micro/service/result.rb +13 -27
- data/lib/micro/service/version.rb +1 -1
- data/lib/micro/service.rb +5 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '03877b6389a946be9418d0d4f41d8efe5a67811920bcdaacbb7467cc31d86275'
|
4
|
+
data.tar.gz: d560985874aa56cfb429fcca22520c37ff6acc5ae74a5a1b8f6aa682e84c2084
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 40681884ea919c82a08cf7e454582f5f0135567efd2d80f63bff464b7d11aab9ae523a25432dd557433d8b58c6a4e9f3493e47e8d1f791d0849976060b3cc438
|
7
|
+
data.tar.gz: 79a7ed2f656c80a39d554a09777c2affba64e3897b606cf666e5a607912113464bd95d3b94cc516c450f03f1bf02868363a4f9b4f9332127b9b329b8b4995dc2
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
u-service (0.
|
4
|
+
u-service (0.9.0)
|
5
5
|
u-attributes (~> 1.1)
|
6
6
|
|
7
7
|
GEM
|
@@ -16,7 +16,7 @@ GEM
|
|
16
16
|
json (>= 1.8, < 3)
|
17
17
|
simplecov-html (~> 0.10.0)
|
18
18
|
simplecov-html (0.10.2)
|
19
|
-
u-attributes (1.
|
19
|
+
u-attributes (1.2.0)
|
20
20
|
|
21
21
|
PLATFORMS
|
22
22
|
ruby
|
data/README.md
CHANGED
@@ -158,7 +158,7 @@ module Steps
|
|
158
158
|
attribute :numbers
|
159
159
|
|
160
160
|
def call!
|
161
|
-
Success(numbers.map { |number| number *
|
161
|
+
Success(numbers.map { |number| number * 2 })
|
162
162
|
end
|
163
163
|
end
|
164
164
|
end
|
@@ -195,7 +195,7 @@ class Double < Micro::Service::Strict
|
|
195
195
|
attribute :numbers
|
196
196
|
|
197
197
|
def call!
|
198
|
-
Success(numbers.map { |number| number *
|
198
|
+
Success(numbers.map { |number| number * 2 })
|
199
199
|
end
|
200
200
|
end
|
201
201
|
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Micro
|
4
|
+
module Service
|
5
|
+
class Result
|
6
|
+
module Helpers
|
7
|
+
private def Success(arg=nil)
|
8
|
+
value, type = block_given? ? [yield, arg] : [arg, nil]
|
9
|
+
Result::Success[value: value, type: type]
|
10
|
+
end
|
11
|
+
|
12
|
+
private def Failure(arg=nil)
|
13
|
+
value, type = block_given? ? [yield, arg] : [arg, nil]
|
14
|
+
Result::Failure[value: value, type: type]
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/lib/micro/service/result.rb
CHANGED
@@ -3,27 +3,27 @@
|
|
3
3
|
module Micro
|
4
4
|
module Service
|
5
5
|
class Result
|
6
|
-
|
6
|
+
module Type
|
7
|
+
INVALID = 'type must be nil or a symbol'.freeze
|
7
8
|
|
8
|
-
|
9
|
+
def self.[](arg)
|
10
|
+
return arg if arg.nil? || arg.is_a?(Symbol)
|
11
|
+
raise TypeError, INVALID
|
12
|
+
end
|
13
|
+
end
|
9
14
|
|
10
|
-
|
15
|
+
private_constant :Type
|
11
16
|
|
12
|
-
|
13
|
-
return arg if arg.nil? || arg.is_a?(Symbol)
|
14
|
-
raise TypeError, INVALID_TYPE
|
15
|
-
end
|
17
|
+
include Micro::Attributes.with(:strict_initialize)
|
16
18
|
|
17
|
-
def self.
|
18
|
-
|
19
|
+
def self.[](value:, type: nil)
|
20
|
+
new(value: value, type: Type[type])
|
19
21
|
end
|
20
22
|
|
21
|
-
|
22
|
-
self.new(success: false, type: Type(type), value: value)
|
23
|
-
end
|
23
|
+
attributes :type, :value
|
24
24
|
|
25
25
|
def success?
|
26
|
-
|
26
|
+
raise NotImplementedError
|
27
27
|
end
|
28
28
|
|
29
29
|
def failure?
|
@@ -47,20 +47,6 @@ module Micro
|
|
47
47
|
def failure_type?(arg)
|
48
48
|
failure? && (arg.nil? || arg == type)
|
49
49
|
end
|
50
|
-
|
51
|
-
module Helpers
|
52
|
-
private
|
53
|
-
|
54
|
-
def Success(arg=nil)
|
55
|
-
value, type = block_given? ? [yield, arg] : [arg, nil]
|
56
|
-
Result::Success(value: value, type: type)
|
57
|
-
end
|
58
|
-
|
59
|
-
def Failure(arg=nil)
|
60
|
-
value, type = block_given? ? [yield, arg] : [arg, nil]
|
61
|
-
Result::Failure(value: value, type: type)
|
62
|
-
end
|
63
|
-
end
|
64
50
|
end
|
65
51
|
end
|
66
52
|
end
|
data/lib/micro/service.rb
CHANGED
@@ -3,7 +3,12 @@
|
|
3
3
|
require 'micro/attributes'
|
4
4
|
|
5
5
|
require 'micro/service/version'
|
6
|
+
|
6
7
|
require 'micro/service/result'
|
8
|
+
require 'micro/service/result/success'
|
9
|
+
require 'micro/service/result/failure'
|
10
|
+
require 'micro/service/result/helpers'
|
11
|
+
|
7
12
|
require 'micro/service/base'
|
8
13
|
require 'micro/service/strict'
|
9
14
|
require 'micro/service/pipeline'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: u-service
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.9.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rodrigo Serradura
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-08-
|
11
|
+
date: 2019-08-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: u-attributes
|
@@ -89,6 +89,9 @@ files:
|
|
89
89
|
- lib/micro/service/base.rb
|
90
90
|
- lib/micro/service/pipeline.rb
|
91
91
|
- lib/micro/service/result.rb
|
92
|
+
- lib/micro/service/result/failure.rb
|
93
|
+
- lib/micro/service/result/helpers.rb
|
94
|
+
- lib/micro/service/result/success.rb
|
92
95
|
- lib/micro/service/strict.rb
|
93
96
|
- lib/micro/service/version.rb
|
94
97
|
- lib/micro/service/with_validation.rb
|