u-service 0.3.0 → 0.4.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: 5a687992a7448d7f960dc8cde7a2cdcd84a0372683ec779cc6cb5d762cf5a32b
4
- data.tar.gz: 4cbf493636de858653a43aa29ea340fee60ee4540fa18042e88366096a05bae7
3
+ metadata.gz: e6318b522443f18f20b9cc6d6df3df66bac3b47ec00c0cf634c8e5093cd1e9c8
4
+ data.tar.gz: abe048fdae03253fca5e46ef35a7c95c104bdafedb32358983533470a46958b7
5
5
  SHA512:
6
- metadata.gz: 9369b4a41c8239db271fd5c1ad87e910afe77a18b0b5371806197bb014b5d886fcb206783354339b70513e9e1862ce785306873f02b7ce68a2724db072740f5b
7
- data.tar.gz: 6dead66303540f70ca8d7dabd22f8580c81f43d1a0b127148a1c37698f72f1fe009a78d21486e3f1858eacf05a760a90da0e53ced0a276f932de3afcc3ae55e4
6
+ metadata.gz: 020b873f0b7c0326b5ad26c72c64a412ec4383709d626804af0147e2a80a9274a41228cb100332a41f12400c96a4251a8c900fe13851bf4ffaabbe7874ce488c
7
+ data.tar.gz: d17ba3915f0fa3d1d69e0b02f46f0a14d44ea707255a78a3ac9386a9cf14e86201832b3f3c04cd3e4ead9f93323123092b752fcab5218355e538ecbcd4f9738e
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- u-service (0.3.0)
4
+ u-service (0.4.0)
5
5
  u-attributes (~> 1.1)
6
6
 
7
7
  GEM
@@ -15,11 +15,10 @@ module Micro
15
15
  end
16
16
 
17
17
  def call(arg={})
18
- first_result = Micro::Service::Result::Success(arg, type: nil)
18
+ initial_result = Micro::Service::Result::Success(value: arg)
19
19
 
20
- @services.reduce(first_result) do |result, service|
20
+ @services.reduce(initial_result) do |result, service|
21
21
  break result if result.failure?
22
-
23
22
  service.call(result.value)
24
23
  end
25
24
  end
@@ -5,15 +5,22 @@ module Micro
5
5
  class Result
6
6
  include Micro::Attributes.with(:initialize)
7
7
 
8
- def self.Success(value, type:)
9
- self.new(success: true, type: type, value: value)
8
+ attributes :success, :type, :value
9
+
10
+ INVALID_TYPE = "#{self.name}#type must be nil or a symbol".freeze
11
+
12
+ def self.Type(arg)
13
+ return arg if arg.nil? || arg.is_a?(Symbol)
14
+ raise TypeError, INVALID_TYPE
10
15
  end
11
16
 
12
- def self.Failure(value, type:)
13
- self.new(success: false, type: type, value: value)
17
+ def self.Success(value:, type: nil)
18
+ self.new(success: true, type: Type(type), value: value)
14
19
  end
15
20
 
16
- attributes :success, :type, :value
21
+ def self.Failure(value:, type: nil)
22
+ self.new(success: false, type: Type(type), value: value)
23
+ end
17
24
 
18
25
  def success?
19
26
  success
@@ -44,14 +51,14 @@ module Micro
44
51
  module Helpers
45
52
  private
46
53
 
47
- def Success(value=nil, type: nil)
48
- yielded_value = yield if block_given?
49
- Result::Success(yielded_value || value, type: type)
54
+ def Success(arg=nil)
55
+ value, type = block_given? ? [yield, arg] : [arg, nil]
56
+ Result::Success(value: value, type: type)
50
57
  end
51
58
 
52
- def Failure(value=nil, type: nil)
53
- yielded_value = yield if block_given?
54
- Result::Failure(yielded_value || value, type: type)
59
+ def Failure(arg=nil)
60
+ value, type = block_given? ? [yield, arg] : [arg, nil]
61
+ Result::Failure(value: value, type: type)
55
62
  end
56
63
  end
57
64
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Micro
4
4
  module Service
5
- VERSION = '0.3.0'.freeze
5
+ VERSION = '0.4.0'.freeze
6
6
  end
7
7
  end
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.3.0
4
+ version: 0.4.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-05 00:00:00.000000000 Z
11
+ date: 2019-08-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: u-attributes
@@ -110,7 +110,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
110
110
  - !ruby/object:Gem::Version
111
111
  version: '0'
112
112
  requirements: []
113
- rubygems_version: 3.0.1
113
+ rubygems_version: 3.0.3
114
114
  signing_key:
115
115
  specification_version: 4
116
116
  summary: Create simple and powerful service objects.