workflows 0.1.0 → 0.1.1

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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +87 -5
  3. data/lib/workflows/version.rb +1 -1
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 82262e54a1a6ddd11b7c05f8169f4035ff289677
4
- data.tar.gz: 3562c0579e24c0b92dbc3d23426f2c31d840f167
3
+ metadata.gz: f04dc0293e71b313565f3fd0ef0d7ed890e71daf
4
+ data.tar.gz: 1383744ebe41d421c1d7a12a03716f7823bea67b
5
5
  SHA512:
6
- metadata.gz: f9346dde057c147c66444331dc18570906db016f862b27b77dda6760fc635bf19a30244d18e5c8a8c87dc92f927e698cf4b2aa8232a4ead91ee300aa69feffbd
7
- data.tar.gz: fc07d9ecf4933fc9ea77488528df903a11440a96c4e3cc35e21b1ef586aa1bf02aa48b098f97ebfc7cbe631360f98aae6be0bfb7acbdeac61b604fdcf0f876aa
6
+ metadata.gz: 78534b357ba6f368f087799d0d9728b350d62ae5bfc4d2c7561e8f98fff482a438ec3d46dcca2e0ac8a60048d71ad4ca4434be7604e66c1442e11a3f349a13d4
7
+ data.tar.gz: 859e56d98fac93caf713ed2afb9f85bcdd62fe9dba727ceb35bd190ce01f8c6ed40642b306be1dc1f82ffd38481f53c867852d02db3a8d764db5f299c09e2fbc
data/README.md CHANGED
@@ -1,8 +1,14 @@
1
1
  # Workflows
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/workflows`. To experiment with that code, run `bin/console` for an interactive prompt.
4
-
5
- TODO: Delete this and the text above, and describe your gem
3
+ Workflows is an attempt to create multiple-step services. each step of
4
+ the workflow is service by itself that has a run method. it can fail or
5
+ succeed and the status of the step will change to :fail or :ok
6
+ respectively. each service in this model has two types of output. one
7
+ that is called state and another that is called output. state will be
8
+ passed to the next step of the workflow, so if there are objects that
9
+ need to be passed between the steps, they should be kept in state.
10
+ outputs are not passed between the steps and are only holding the output
11
+ value of each executed step of the workflow.
6
12
 
7
13
  ## Installation
8
14
 
@@ -20,9 +26,85 @@ Or install it yourself as:
20
26
 
21
27
  $ gem install workflows
22
28
 
23
- ## Usage
29
+ ## Example
30
+
31
+ You can find more examples in the example directory of the gem.
32
+
33
+ If you have a workflow such as the following:
24
34
 
25
- TODO: Write usage instructions here
35
+ ```ruby
36
+ class BarbieMakerFlow
37
+ include Workflows
38
+
39
+
40
+ has_flow [
41
+ {
42
+ name: 'design',
43
+ service: Design,
44
+ args: [:gender, :specification]
45
+ },
46
+ {
47
+ name: 'make',
48
+ service: Make,
49
+ args: [:outfit]
50
+ }
51
+ ]
52
+
53
+ end
54
+
55
+ class Design
56
+ include Workflows::StepService
57
+
58
+ def run
59
+ set_state(
60
+ barbie: Barbie.new(args.gender, args.specification)
61
+ )
62
+ end
63
+ end
64
+
65
+ class Make
66
+ include Workflows::StepService
67
+
68
+ def run
69
+ barbie = get_state[:barbie]
70
+ msg = barbie.dress_up(args.outfit)
71
+
72
+ set_output(msg)
73
+ set_state(barbie: barbie)
74
+ end
75
+ end
76
+
77
+ class Barbie
78
+ attr_reader :gender,
79
+ :specification,
80
+ :outfit
81
+
82
+ def initialize(gender, specification)
83
+ @gender = gender
84
+ @specification = specification
85
+ end
86
+
87
+ def dress_up(outfit)
88
+ @outfit = outfit
89
+ "#{@gender} #{@specification} barbie is wearing a #{outfit}"
90
+ end
91
+ end
92
+ ```
93
+
94
+ you can now run your flow by providing input arguments for each step:
95
+
96
+ ```ruby
97
+ bmf = BarbieMakerFlow.new(
98
+ design: { gender: 'female', specification: 'Software Engineer' },
99
+ make: { outfit: 'white shirt and navy shorts' }
100
+ )
101
+
102
+ bmf.run #=> runs the flow with provided inputs
103
+ bmf.status #=> [:ok, :ok] | [:ok, :fail] | [:fail, :fail]
104
+ bmf.output #=> ['output of design', 'output of make']
105
+ bmf.state #=> Barbie.new(gender: 'female',
106
+ specification: ....)
107
+ ```
26
108
 
27
109
  ## Development
28
110
 
@@ -1,3 +1,3 @@
1
1
  module Workflows
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: workflows
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shamim