brace_comb 0.1.3 → 0.2.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 +12 -14
- data/lib/brace_comb.rb +0 -1
- data/lib/brace_comb/dependency_model.rb +4 -1
- data/lib/brace_comb/version.rb +1 -1
- data/spec/brace_comb/dependency_model_spec.rb +3 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 225cef0fa8aeb8117ae666819ecbbba48205e45a
|
4
|
+
data.tar.gz: c722dc8360a165d39a6f569429dae35ce4d5b05b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 95197f8bc990fe35f9cb641a24b38e9b546344e4763aaee3c86c2d28078f1e608fa5ed10584c4b246a80012dc7d20e03705854bd7584d56a7eecabd33c4ddcf1
|
7
|
+
data.tar.gz: dec014b2be336b8624f960d7890430d190cb92816e07ea02b6e7f3d4cdca1dfb1db50657ba7568fd1c4259ee0d4877fa1ba1155c33b21b48b7075b21a041772d
|
data/README.md
CHANGED
@@ -9,18 +9,18 @@ This is akin to how workflows are connected to each other with dependencies.
|
|
9
9
|
In workflow management systems, there is often a need to define that certain tasks should only begin when another task(s) is complete. BraceComb can be used to define multiple types of workflows and handle each workflow consistently.
|
10
10
|
|
11
11
|
## Example
|
12
|
-
A factory production line
|
12
|
+
A factory production line system uses pre-defined workflows with strict dependencies between tasks. In a simplified scenario, let's say we need to define a workflow in which an item on the conveyor belt must be packed before it is dispatched. In this case:
|
13
13
|
|
14
14
|
- Dependents/Tasks are the actions such as packing and dispatching
|
15
15
|
- Dependencies are links that define that packing must finish before dispatching
|
16
16
|
|
17
|
-
In this system we can create a dependent entity called `
|
17
|
+
In this system we can create a dependent entity called `tasks` of type `packing` and another dependent entity `tasks` of type `dispatching`. A new `task_dependency` entity between the two entities can be created using the following command:
|
18
18
|
|
19
19
|
```
|
20
|
-
initialize_dependency! from:
|
20
|
+
initialize_dependency! from: task1.id, to: task2.id, dependency_type: 'dispatch'
|
21
21
|
```
|
22
22
|
|
23
|
-
This will create a
|
23
|
+
`dependency_type` is used to categorize the dependency. This will create a `task_dependency` entity in `pending` state. In this case `packing` task is a strict prerequisite for `dispatching` task, hence `dispatching` should not start unless `packing` is complete. Therefore the `task_dependency` between them should be in `resolved` state. This is also the case for any dependencies of dependency_type `dispatch`. This relationship can be defined by declaring a dependency characteristics on the `task_dependency` class using:
|
24
24
|
|
25
25
|
```
|
26
26
|
declare_dependency type: :dispatch,
|
@@ -29,13 +29,13 @@ This will create a dependency in `pending` state. In this case `packing` is a st
|
|
29
29
|
after_resolution: [:send_dispatch_notification]
|
30
30
|
```
|
31
31
|
|
32
|
-
This declaration will ensure that for all dependencies of type `dispatch`, all `before_resolution` hooks are first run. If any `before_resolution` functions returns false, then the operation is aborted. If all `before_resolution` functions return true, then the resolver code inside `send_packing_complete_confirmation` will be executed, and then all functions inside `after_resolution` would be executed.
|
32
|
+
This declaration will ensure that for all dependencies of type `dispatch`, when the `task_dependency` is marked as resolved, all `before_resolution` hooks are first run. If any `before_resolution` functions returns false, then the operation is aborted. If all `before_resolution` functions return true, then the resolver code inside `send_packing_complete_confirmation` will be executed, and then all functions inside `after_resolution` would be executed.
|
33
33
|
|
34
|
-
To kick-off this flow just call `
|
34
|
+
To kick-off this flow just call `task_dependency.resolve` and the before and after hooks will be invoked in the manner as described above.
|
35
35
|
|
36
36
|
## Installation
|
37
37
|
|
38
|
-
1. Add
|
38
|
+
1. Add to your `Gemfile`.
|
39
39
|
|
40
40
|
`gem 'brace_comb'`
|
41
41
|
|
@@ -56,12 +56,11 @@ To kick-off this flow just call `dependency.resolve` and the before and after ho
|
|
56
56
|
|
57
57
|
Entity names for dependencies and dependents are configurable and can be set in `config/initializers/brace_comb.rb` before creating the migrations.
|
58
58
|
|
59
|
-
1. Declare a dependency type by adding in the following to the dependency class:
|
59
|
+
1. Declare a dependency type by adding in the following to the dependency (`task_dependency`) class:
|
60
60
|
```
|
61
|
-
include BraceComb::
|
62
|
-
enum type: { shopping: 0 }
|
61
|
+
include BraceComb::Model
|
63
62
|
```
|
64
|
-
2. Declare a dependency by typing in the following in any ActiveRecord class. Only `resolver` is compulsory whereas `before_resolution` and `after_resolution` are optional.
|
63
|
+
2. Declare a dependency by typing in the following in any ActiveRecord class. Only `resolver` is compulsory whereas `before_resolution` and `after_resolution` are optional. `type` is a unique string and is used to identify the resolution behaviour for all dependents with `dependency_type` the same as that defined in `type`.
|
65
64
|
|
66
65
|
a. Using a method name in the resolver
|
67
66
|
```
|
@@ -84,11 +83,11 @@ Entity names for dependencies and dependents are configurable and can be set in
|
|
84
83
|
3. Create dependencies between the dependent class by using the following helper in any instance method of a model class:
|
85
84
|
|
86
85
|
- When an exception needs to be raised:
|
87
|
-
`initialize_dependency! from:
|
86
|
+
`initialize_dependency! from: task1.id, to: task2.id, type: 'shopping'`
|
88
87
|
|
89
88
|
or
|
90
89
|
- When a boolean needs to be returned:
|
91
|
-
`initialize_dependency from:
|
90
|
+
`initialize_dependency from: task1.id, to: task2.id, type: 'shopping'`
|
92
91
|
|
93
92
|
5. Resolve dependencies from any active record model by using:
|
94
93
|
|
@@ -107,7 +106,6 @@ Entity names for dependencies and dependents are configurable and can be set in
|
|
107
106
|
|
108
107
|
## Under consideration
|
109
108
|
- Allowing dependency declaration to accept multiple resolvers, and allowing resolve to accept the name of the resolver. This could possibly by done in `resolve` method itself instead of `declare_dependency`
|
110
|
-
- Automatically including the concern for `resolve` inside the dependency class
|
111
109
|
- Combining the installation steps into 1-2 steps
|
112
110
|
- And more...
|
113
111
|
## Contributing
|
data/lib/brace_comb.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'brace_comb/exceptions/callback_failure'
|
2
|
+
require 'brace_comb/dependency_helper'
|
2
3
|
|
3
4
|
module BraceComb
|
4
5
|
module Model
|
@@ -28,7 +29,7 @@ module BraceComb
|
|
28
29
|
|
29
30
|
def execute_after_callbacks(after_callbacks)
|
30
31
|
return unless after_callbacks
|
31
|
-
after_callbacks.
|
32
|
+
after_callbacks.map do |after_callback|
|
32
33
|
execute_callback(after_callback)
|
33
34
|
end
|
34
35
|
end
|
@@ -63,6 +64,8 @@ module BraceComb
|
|
63
64
|
|
64
65
|
def self.included(base)
|
65
66
|
base.send :include, InstanceMethods
|
67
|
+
base.send :include, BraceComb::Helper::InstanceMethods
|
68
|
+
base.send :extend, BraceComb::Helper::ClassMethods
|
66
69
|
end
|
67
70
|
end
|
68
71
|
end
|
data/lib/brace_comb/version.rb
CHANGED
@@ -23,7 +23,7 @@ describe BraceComb::Model do
|
|
23
23
|
|
24
24
|
before do
|
25
25
|
dependency_class.constantize.class_eval do
|
26
|
-
include BraceComb::
|
26
|
+
include BraceComb::Model
|
27
27
|
|
28
28
|
enum dependency_type: { shopping: 0 }
|
29
29
|
enum status: { pending: 0, resolved: 1 }
|
@@ -122,10 +122,10 @@ describe BraceComb::Model do
|
|
122
122
|
end
|
123
123
|
|
124
124
|
it 'resolves dependency if all before resolve hooks are satisfied' do
|
125
|
-
result = dependency.resolve
|
125
|
+
result = dependency.resolve!
|
126
126
|
expect(dependency).not_to receive(:complete_job).and_call_original
|
127
127
|
expect(dependency).to be_resolved
|
128
|
-
expect(result).to
|
128
|
+
expect(result).to eq [true]
|
129
129
|
end
|
130
130
|
end
|
131
131
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: brace_comb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ankita Gupta
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-02-
|
11
|
+
date: 2019-02-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|