serviz 0.2.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/serviz/version.rb +1 -1
- data/lib/serviz.rb +16 -2
- data/spec/scenarios.rb +11 -0
- data/spec/serviz_spec.rb +17 -0
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 996c470857cef304582ab365344d4918e3ee35c5baacd64b2d5b068a2b323707
|
4
|
+
data.tar.gz: 3c77f8932bee0fb30543975094f8d1ce025e8455ca031e028b9b97f1a134835d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d5b429c64601d9a4b9f829cb723e99c995659c64cf5901eb34240047ee2611ab7b10bd2aa27a2ab54339e99c6b63466deab752d5998f3a74efd528d4d16afb9a
|
7
|
+
data.tar.gz: 7a89f2b36fe02e78d75cec00280659ae0fc7f740730a373c07e62b444534b844a784b1b828acb0291b9f8328833466d66bcbb1fd476f85337aaefab6604cc7ab
|
data/lib/serviz/version.rb
CHANGED
data/lib/serviz.rb
CHANGED
@@ -4,10 +4,18 @@ module Serviz
|
|
4
4
|
class Base
|
5
5
|
attr_accessor :errors, :result
|
6
6
|
|
7
|
-
def self.call(*args)
|
8
|
-
instance =
|
7
|
+
def self.call(*args, **kwargs)
|
8
|
+
instance = if args.length > 0 && kwargs.length > 0
|
9
|
+
new(*args, **kwargs)
|
10
|
+
elsif kwargs.length > 0
|
11
|
+
new(**kwargs)
|
12
|
+
else
|
13
|
+
new(*args)
|
14
|
+
end
|
9
15
|
instance.call
|
10
16
|
|
17
|
+
yield(instance) if block_given?
|
18
|
+
|
11
19
|
instance
|
12
20
|
end
|
13
21
|
|
@@ -19,12 +27,18 @@ module Serviz
|
|
19
27
|
@errors ||= []
|
20
28
|
end
|
21
29
|
|
30
|
+
def error_messages(separator = ", ")
|
31
|
+
errors.join(separator)
|
32
|
+
end
|
33
|
+
|
22
34
|
def success?
|
23
35
|
!failure?
|
24
36
|
end
|
37
|
+
alias_method :ok?, :success?
|
25
38
|
|
26
39
|
def failure?
|
27
40
|
errors.any?
|
28
41
|
end
|
42
|
+
alias_method :error?, :failure?
|
29
43
|
end
|
30
44
|
end
|
data/spec/scenarios.rb
CHANGED
@@ -12,5 +12,16 @@ class RegisterUser < Serviz::Base
|
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
|
+
class PositionalAndKeyword < Serviz::Base
|
16
|
+
def initialize(positional, keyword:)
|
17
|
+
@positional = positional
|
18
|
+
@keyword = keyword
|
19
|
+
end
|
20
|
+
|
21
|
+
def call
|
22
|
+
self.result = [@positional, @keyword]
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
15
26
|
class NoCall < Serviz::Base
|
16
27
|
end
|
data/spec/serviz_spec.rb
CHANGED
@@ -4,8 +4,10 @@ RSpec.describe Serviz::Base do
|
|
4
4
|
operation = RegisterUser.call(user)
|
5
5
|
|
6
6
|
expect(operation.success?).to eq true
|
7
|
+
expect(operation.ok?).to eq true
|
7
8
|
expect(operation.failure?).to eq false
|
8
9
|
expect(operation.errors).to be_empty
|
10
|
+
expect(operation.error_messages).to eq ''
|
9
11
|
expect(operation.result).to eq user
|
10
12
|
end
|
11
13
|
|
@@ -14,11 +16,26 @@ RSpec.describe Serviz::Base do
|
|
14
16
|
|
15
17
|
expect(operation.success?).to eq false
|
16
18
|
expect(operation.failure?).to eq true
|
19
|
+
expect(operation.error?).to eq true
|
17
20
|
expect(operation.errors).not_to be_empty
|
21
|
+
expect(operation.error_messages).to eq 'No user!'
|
18
22
|
expect(operation.result).to eq nil
|
19
23
|
end
|
20
24
|
|
21
25
|
it "raises exception if #call is not defined" do
|
22
26
|
expect { NoCall.call }.to raise_error NotImplementedError
|
23
27
|
end
|
28
|
+
|
29
|
+
it "accepts positional and keywords args" do
|
30
|
+
operation = PositionalAndKeyword.call('foo', keyword: 'bar')
|
31
|
+
|
32
|
+
expect(operation.success?).to eq true
|
33
|
+
expect(operation.result).to eq(['foo', 'bar'])
|
34
|
+
end
|
35
|
+
|
36
|
+
it "accepts a block" do
|
37
|
+
expect {
|
38
|
+
RegisterUser.call { |operation| puts 'error!' if operation.failure? }
|
39
|
+
}.to output("error!\n").to_stdout
|
40
|
+
end
|
24
41
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: serviz
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- markets
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-04-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -68,7 +68,7 @@ homepage: https://github.com/markets/serviz
|
|
68
68
|
licenses:
|
69
69
|
- MIT
|
70
70
|
metadata: {}
|
71
|
-
post_install_message:
|
71
|
+
post_install_message:
|
72
72
|
rdoc_options: []
|
73
73
|
require_paths:
|
74
74
|
- lib
|
@@ -83,8 +83,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
83
83
|
- !ruby/object:Gem::Version
|
84
84
|
version: '0'
|
85
85
|
requirements: []
|
86
|
-
rubygems_version: 3.
|
87
|
-
signing_key:
|
86
|
+
rubygems_version: 3.4.10
|
87
|
+
signing_key:
|
88
88
|
specification_version: 4
|
89
89
|
summary: Command object Interface for Ruby
|
90
90
|
test_files:
|