quickstep 0.2.0 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +50 -3
- data/lib/quickstep/result.rb +14 -6
- data/lib/quickstep/version.rb +1 -1
- data/lib/quickstep.rb +14 -3
- 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: 2f14a3a824fcc4213fdceb8bd15d1a2e4912207c7e7bcc3760854e4cb137ff22
|
4
|
+
data.tar.gz: 282e253ac3fe9e47b227c9c6aa26e7e34c80ce922a5874bf6a9bfccf9d145739
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d68a3ffb2eea14980103f7ab1fe1c5f1b6017dd66dd79d0656eda6707af8f5a547c0fa4a73783d8850c46dc9dcfff860e9af32312dc1ab4ded0dfffcde243771
|
7
|
+
data.tar.gz: 95e07911222e32c5ccb2bdb9e5f23b50523b9b85832bebcc182fa6bcdaf8847bd196cd817343a11b7ef9d2038983c62f3ec7215abe319247bb19966aaf4f9503
|
data/README.md
CHANGED
@@ -10,7 +10,7 @@ Quickstep is a lightweight business operation tool inspired by [dry-operation](h
|
|
10
10
|
Add this line to your application's Gemfile:
|
11
11
|
|
12
12
|
```ruby
|
13
|
-
gem 'quickstep'
|
13
|
+
gem 'quickstep', '1.0.0'
|
14
14
|
```
|
15
15
|
|
16
16
|
Or install it manually:
|
@@ -48,8 +48,6 @@ class MyOperation
|
|
48
48
|
end
|
49
49
|
|
50
50
|
result = MyOperation.new.call(valid: true, value: 5)
|
51
|
-
# or
|
52
|
-
# result = MyOperation.call(valid: true, value: 5)
|
53
51
|
|
54
52
|
if result.success?
|
55
53
|
puts "Success: #{result.value}"
|
@@ -58,6 +56,55 @@ else
|
|
58
56
|
end
|
59
57
|
```
|
60
58
|
|
59
|
+
### Chaining Operations
|
60
|
+
|
61
|
+
In Quickstep, you can use the result of another operation as a step in your operation.
|
62
|
+
This allows you to compose operations naturally and reuse existing logic.
|
63
|
+
|
64
|
+
```ruby
|
65
|
+
class MainOperation
|
66
|
+
include Quickstep
|
67
|
+
|
68
|
+
def call
|
69
|
+
step step1
|
70
|
+
step SecondOperation.new.call # chaining another operation
|
71
|
+
end
|
72
|
+
|
73
|
+
private
|
74
|
+
|
75
|
+
def first_step
|
76
|
+
Success("first step")
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
class SecondOperation
|
81
|
+
include Quickstep
|
82
|
+
|
83
|
+
def call
|
84
|
+
step first_step
|
85
|
+
step second_step
|
86
|
+
end
|
87
|
+
|
88
|
+
private
|
89
|
+
|
90
|
+
def first_step
|
91
|
+
Success("Step from SecondOperation")
|
92
|
+
end
|
93
|
+
end
|
94
|
+
```
|
95
|
+
|
96
|
+
### Notes
|
97
|
+
- Any value returned by `call` that is not already a `Success` or `Failure` will be wrapped in a `Success` automatically.
|
98
|
+
- Operations can be executed either via an **instance** or directly on the **class**:
|
99
|
+
```ruby
|
100
|
+
# Using an instance
|
101
|
+
result = MyOperation.new.call(:input)
|
102
|
+
|
103
|
+
# Using the class method shortcut
|
104
|
+
result = MyOperation.call(:input)
|
105
|
+
```
|
106
|
+
|
107
|
+
|
61
108
|
## License
|
62
109
|
|
63
110
|
Quickstep is available under the MIT License.
|
data/lib/quickstep/result.rb
CHANGED
@@ -5,7 +5,7 @@ module Quickstep
|
|
5
5
|
class Success
|
6
6
|
attr_reader :value
|
7
7
|
|
8
|
-
def initialize(value)
|
8
|
+
def initialize(value = nil)
|
9
9
|
@value = value
|
10
10
|
end
|
11
11
|
|
@@ -18,14 +18,18 @@ module Quickstep
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def inspect
|
21
|
-
"Success(#{value.inspect})"
|
21
|
+
value.nil? ? 'Success()' : "Success(#{value.inspect})"
|
22
|
+
end
|
23
|
+
|
24
|
+
def ==(other)
|
25
|
+
other.is_a?(Success) && other.value == value
|
22
26
|
end
|
23
27
|
end
|
24
28
|
|
25
29
|
class Failure
|
26
30
|
attr_reader :value
|
27
31
|
|
28
|
-
def initialize(value)
|
32
|
+
def initialize(value = nil)
|
29
33
|
@value = value
|
30
34
|
end
|
31
35
|
|
@@ -38,15 +42,19 @@ module Quickstep
|
|
38
42
|
end
|
39
43
|
|
40
44
|
def inspect
|
41
|
-
"Failure(#{value.inspect})"
|
45
|
+
value.nil? ? 'Failure()' : "Failure(#{value.inspect})"
|
46
|
+
end
|
47
|
+
|
48
|
+
def ==(other)
|
49
|
+
other.is_a?(Failure) && other.value == value
|
42
50
|
end
|
43
51
|
end
|
44
52
|
|
45
|
-
def Success(value)
|
53
|
+
def Success(value = nil)
|
46
54
|
Success.new(value)
|
47
55
|
end
|
48
56
|
|
49
|
-
def Failure(value)
|
57
|
+
def Failure(value = nil)
|
50
58
|
Failure.new(value)
|
51
59
|
end
|
52
60
|
end
|
data/lib/quickstep/version.rb
CHANGED
data/lib/quickstep.rb
CHANGED
@@ -13,23 +13,34 @@ module Quickstep
|
|
13
13
|
|
14
14
|
module ClassMethods
|
15
15
|
def call(*args)
|
16
|
-
catch :halt do
|
16
|
+
result = catch :halt do
|
17
17
|
new.call(*args)
|
18
18
|
end
|
19
|
+
if result.respond_to?(:failure?)
|
20
|
+
result
|
21
|
+
else
|
22
|
+
Quickstep::Result::Success.new(result)
|
23
|
+
end
|
19
24
|
end
|
20
25
|
end
|
21
26
|
|
22
27
|
module InstanceMethods
|
23
28
|
def call(*args)
|
24
|
-
catch :halt do
|
29
|
+
result = catch :halt do
|
25
30
|
super
|
26
31
|
end
|
32
|
+
|
33
|
+
if result.respond_to?(:failure?)
|
34
|
+
result
|
35
|
+
else
|
36
|
+
Quickstep::Result::Success.new(result)
|
37
|
+
end
|
27
38
|
end
|
28
39
|
end
|
29
40
|
|
30
41
|
def step(result)
|
31
42
|
if result.success?
|
32
|
-
result
|
43
|
+
result.value
|
33
44
|
else
|
34
45
|
throw :halt, result
|
35
46
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: quickstep
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Igor Korepanov
|
8
8
|
bindir: bin
|
9
9
|
cert_chain: []
|
10
|
-
date: 2025-
|
10
|
+
date: 2025-08-28 00:00:00.000000000 Z
|
11
11
|
dependencies: []
|
12
12
|
description: |2
|
13
13
|
Quickstep provides a structured way to execute multi-step business operations with built-in success and
|