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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8b8bd72203e123ab248a7b0a510d1eb7f457d3b68a04bc257cdc08f8e6a949ab
4
- data.tar.gz: 022a4b90b46b1d10a238b37bc9a168b984f21f9d75ab144d5c97159b864b04c9
3
+ metadata.gz: '03877b6389a946be9418d0d4f41d8efe5a67811920bcdaacbb7467cc31d86275'
4
+ data.tar.gz: d560985874aa56cfb429fcca22520c37ff6acc5ae74a5a1b8f6aa682e84c2084
5
5
  SHA512:
6
- metadata.gz: 9adc08c22019f4aab1559bdd017e1b92775acd612d102e27bf9a3726c9a3c88eacd250a556cfc11bf40da95dca85b08711b075c5f85806480dc15d09baacbf73
7
- data.tar.gz: 68606ccb04d38d3ccd5549242a9faa7bc0004c751f4d72d834c9adfd649d04723b7267b3b8e84a57e2c54da01b5d9e6074bc93f0ad0537674344b529706b562a
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.8.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.1.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 * 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 * number })
198
+ Success(numbers.map { |number| number * 2 })
199
199
  end
200
200
  end
201
201
 
@@ -30,7 +30,7 @@ module Micro
30
30
 
31
31
  def initial_result(arg)
32
32
  return arg if arg.is_a?(Micro::Service::Result)
33
- Micro::Service::Result::Success(value: arg)
33
+ Micro::Service::Result::Success[value: arg]
34
34
  end
35
35
  end
36
36
 
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Micro
4
+ module Service
5
+ class Result
6
+ class Failure < Micro::Service::Result
7
+ def success?; false; end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -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
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Micro
4
+ module Service
5
+ class Result
6
+ class Success < Micro::Service::Result
7
+ def success?; true; end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -3,27 +3,27 @@
3
3
  module Micro
4
4
  module Service
5
5
  class Result
6
- include Micro::Attributes.with(:initialize)
6
+ module Type
7
+ INVALID = 'type must be nil or a symbol'.freeze
7
8
 
8
- attributes :success, :type, :value
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
- INVALID_TYPE = "#{self.name}#type must be nil or a symbol".freeze
15
+ private_constant :Type
11
16
 
12
- def self.Type(arg)
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.Success(value:, type: nil)
18
- self.new(success: true, type: Type(type), value: value)
19
+ def self.[](value:, type: nil)
20
+ new(value: value, type: Type[type])
19
21
  end
20
22
 
21
- def self.Failure(value:, type: nil)
22
- self.new(success: false, type: Type(type), value: value)
23
- end
23
+ attributes :type, :value
24
24
 
25
25
  def success?
26
- success
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
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Micro
4
4
  module Service
5
- VERSION = '0.8.0'.freeze
5
+ VERSION = '0.9.0'.freeze
6
6
  end
7
7
  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.8.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-08 00:00:00.000000000 Z
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