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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9b3ba688d5654641a8e622b6015e181a8f46dadb
4
- data.tar.gz: a212c8298374b6626b05ee65a3af2417dbba4608
3
+ metadata.gz: 168cb99f7ba5539c9e4f086f417e08533a2dc7d6
4
+ data.tar.gz: ecc885a0319bc0e81ec58d32224419334f67ed56
5
5
  SHA512:
6
- metadata.gz: d8820785187c2acbca1eb1cd72b0dd7d723a47eb5daea54dc14ba2461110214f50afdae0dd575faa88dcd1151f8d2abf18ca4db21c6ebe1c6c9c111e3240f736
7
- data.tar.gz: 46330e1b4c9f30963b8e65acb0b09ce558e7559e74ac09714b3019e725669af9aa3dfc29aa74a885b2a8022429bece93f09dfb1f381c8843fed42f01ddea7474
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).
@@ -20,20 +20,18 @@ module Operabl
20
20
  Operabl::Context.new({})
21
21
  end
22
22
 
23
- operable = self.new
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 step_obj
25
+ case step_def
28
26
  when String, Symbol
29
- operable.method(step_obj).call(ctx)
27
+ self.method(step_def).call(ctx)
30
28
  when Proc
31
- operable.instance_exec ctx, &step_obj
29
+ self.instance_exec ctx, &step_def
32
30
  else
33
- if step_obj.respond_to? :call
34
- step_obj.call(ctx)
31
+ if step_def.respond_to? :call
32
+ step_def.call(ctx)
35
33
  else
36
- raise "#{step_obj.inspect} is invalid step argument"
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(symbol, options={})
53
- steps << [:success, symbol, options]
50
+ def step(step_def, options={})
51
+ steps << [:success, step_def, options]
54
52
  end
55
53
 
56
- def failure(symbol, options={})
57
- steps << [:failure, symbol, options]
54
+ def failure(step_def, options={})
55
+ steps << [:failure, step_def, options]
58
56
  end
59
57
  end
60
58
 
@@ -1,3 +1,3 @@
1
1
  module Operabl
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
@@ -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{Operabl let you define steps in your class to be executed sequentially.}
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.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-05 00:00:00.000000000 Z
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: Operabl let you define steps in your class to be executed sequentially.
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: []