operabl 0.1.1 → 0.1.2
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 +42 -4
- data/lib/operabl.rb +11 -13
- data/lib/operabl/version.rb +1 -1
- data/operabl.gemspec +2 -2
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 168cb99f7ba5539c9e4f086f417e08533a2dc7d6
|
4
|
+
data.tar.gz: ecc885a0319bc0e81ec58d32224419334f67ed56
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 985dfd83d846deb7f01efa44d92776561e585402f44c1ce34eb85d29ba3f340e27cf16454591c4fc3a41b57320af93def9b751883e515348b7ef42b0495c1734
|
7
|
+
data.tar.gz: dcf5ecc1a8c14bb2c73be1f40aaa4efd40823c0837487a308ef6afcc799ae3d7cd22f0e14d63a5bdb0d687b76bf4d7b4901ad16379b3160d55ff890d9309a518
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Operabl
|
2
2
|
|
3
|
-
Railway oriented aproach for your classes. Operabl let you define steps in your class to be executed sequentially
|
3
|
+
Railway oriented aproach for your classes. Operabl let you define steps in your class or module to be executed sequentially. Steps can be class methods, procs or other Operabl classes/modules.
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
@@ -20,6 +20,8 @@ Or install it yourself as:
|
|
20
20
|
|
21
21
|
## Usage
|
22
22
|
|
23
|
+
Include Operable in your Class/Module. Steps can be class methods, procs or other Operabl class/module
|
24
|
+
|
23
25
|
```ruby
|
24
26
|
class ProcOp
|
25
27
|
|
@@ -30,7 +32,7 @@ class ProcOp
|
|
30
32
|
ctx[:amethod_call] = amethod
|
31
33
|
}
|
32
34
|
|
33
|
-
def amethod
|
35
|
+
def self.amethod
|
34
36
|
return "something else"
|
35
37
|
end
|
36
38
|
|
@@ -41,14 +43,19 @@ op.failure? # => false
|
|
41
43
|
op.success? # => true
|
42
44
|
op[:key] # => "something"
|
43
45
|
op[:amethod_call] # => "something else"
|
46
|
+
```
|
47
|
+
|
48
|
+
|
49
|
+
Steps are Class level methods. This is because steps only work with a context provided, they don't change classes state.
|
44
50
|
|
51
|
+
```ruby
|
45
52
|
class MethodOp
|
46
53
|
|
47
54
|
include Operabl
|
48
55
|
|
49
56
|
step :a
|
50
57
|
|
51
|
-
def a(ctx)
|
58
|
+
def self.a(ctx)
|
52
59
|
ctx[:key] = ctx.params[:pkey]
|
53
60
|
end
|
54
61
|
end
|
@@ -56,7 +63,11 @@ end
|
|
56
63
|
op = MethodOp.call({pkey: "something"})
|
57
64
|
op.success? # => true
|
58
65
|
op.result # => {}
|
66
|
+
```
|
67
|
+
|
68
|
+
Another example of an Operabl as a step.
|
59
69
|
|
70
|
+
```ruby
|
60
71
|
class ComposedOp
|
61
72
|
|
62
73
|
include Operabl
|
@@ -64,7 +75,7 @@ class ComposedOp
|
|
64
75
|
step MethodOp
|
65
76
|
step :b
|
66
77
|
|
67
|
-
def b(ctx)
|
78
|
+
def self.b(ctx)
|
68
79
|
ctx.success!({status: 200, response: "OK"})
|
69
80
|
end
|
70
81
|
|
@@ -76,6 +87,33 @@ op[:key] # => "something else"
|
|
76
87
|
op.result # => {status: 200, response: "OK"}
|
77
88
|
```
|
78
89
|
|
90
|
+
The result from #call is a Operabl::Context, it can be passed to a new Operabl call.
|
91
|
+
|
92
|
+
If Operation failed, AnotherOp is not going to succed but it will run any :failure step defined in it.
|
93
|
+
|
94
|
+
```ruby
|
95
|
+
|
96
|
+
class AnotherOp
|
97
|
+
|
98
|
+
include Operabl
|
99
|
+
|
100
|
+
step :a
|
101
|
+
failure :b
|
102
|
+
|
103
|
+
def self.a(ctx)
|
104
|
+
#do something
|
105
|
+
end
|
106
|
+
|
107
|
+
def self.b(ctx)
|
108
|
+
#recover from failure
|
109
|
+
end
|
110
|
+
|
111
|
+
end
|
112
|
+
|
113
|
+
op = Operation.call({pkey: "something else"})
|
114
|
+
op2 = AnotherOp.call(op)
|
115
|
+
```
|
116
|
+
|
79
117
|
## License
|
80
118
|
|
81
119
|
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/lib/operabl.rb
CHANGED
@@ -20,20 +20,18 @@ module Operabl
|
|
20
20
|
Operabl::Context.new({})
|
21
21
|
end
|
22
22
|
|
23
|
-
|
24
|
-
|
25
|
-
steps.each do |step_branch, step_obj, options|
|
23
|
+
steps.each do |step_branch, step_def, options|
|
26
24
|
if step_branch == ctx.branch
|
27
|
-
case
|
25
|
+
case step_def
|
28
26
|
when String, Symbol
|
29
|
-
|
27
|
+
self.method(step_def).call(ctx)
|
30
28
|
when Proc
|
31
|
-
|
29
|
+
self.instance_exec ctx, &step_def
|
32
30
|
else
|
33
|
-
if
|
34
|
-
|
31
|
+
if step_def.respond_to? :call
|
32
|
+
step_def.call(ctx)
|
35
33
|
else
|
36
|
-
raise "#{
|
34
|
+
raise "#{step_def.inspect} is invalid step argument"
|
37
35
|
end
|
38
36
|
end
|
39
37
|
break if options[:fastforward]
|
@@ -49,12 +47,12 @@ module Operabl
|
|
49
47
|
@steps ||= []
|
50
48
|
end
|
51
49
|
|
52
|
-
def step(
|
53
|
-
steps << [:success,
|
50
|
+
def step(step_def, options={})
|
51
|
+
steps << [:success, step_def, options]
|
54
52
|
end
|
55
53
|
|
56
|
-
def failure(
|
57
|
-
steps << [:failure,
|
54
|
+
def failure(step_def, options={})
|
55
|
+
steps << [:failure, step_def, options]
|
58
56
|
end
|
59
57
|
end
|
60
58
|
|
data/lib/operabl/version.rb
CHANGED
data/operabl.gemspec
CHANGED
@@ -9,8 +9,8 @@ Gem::Specification.new do |spec|
|
|
9
9
|
spec.authors = ["Monkey Square Lab"]
|
10
10
|
spec.email = ["monkeysquarelab@gmail.com"]
|
11
11
|
|
12
|
-
spec.summary = %q{Railway oriented aproach for your classes.}
|
13
|
-
spec.description = %q{
|
12
|
+
spec.summary = %q{Railway oriented aproach for your classes and modules.}
|
13
|
+
spec.description = %q{Railway oriented aproach for your classes and modules.}
|
14
14
|
spec.homepage = "https://github.com/monkeysquarelab/operabl"
|
15
15
|
spec.license = "MIT"
|
16
16
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: operabl
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Monkey Square Lab
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-03-
|
11
|
+
date: 2018-03-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -52,7 +52,7 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '5.0'
|
55
|
-
description:
|
55
|
+
description: Railway oriented aproach for your classes and modules.
|
56
56
|
email:
|
57
57
|
- monkeysquarelab@gmail.com
|
58
58
|
executables: []
|
@@ -96,5 +96,5 @@ rubyforge_project:
|
|
96
96
|
rubygems_version: 2.6.13
|
97
97
|
signing_key:
|
98
98
|
specification_version: 4
|
99
|
-
summary: Railway oriented aproach for your classes.
|
99
|
+
summary: Railway oriented aproach for your classes and modules.
|
100
100
|
test_files: []
|