active_flow 0.0.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.
- checksums.yaml +7 -0
- data/lib/flow.rb +128 -0
- metadata +44 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 153bce6999c488dc9b1f3c6d55d169a2ca6d173ebd57987ecdd8335737dcbcf2
|
4
|
+
data.tar.gz: fcfd066d02ff56212d5364e38776a3eec95022d9be346401bb26eea3c5298936
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 80f081582c683ff17bf63bcc1bc8e8fcd3dcd1a7f892ad68a441577cf6068aa0e4055c33bedafce6d44408f359dc50339812d69ba3472a218fab893e0244558c
|
7
|
+
data.tar.gz: 35af5bbf64d14b8f416074e627ba04fe97ca4458746f4f87f605e6a03228611f77e344893385ebaae22bc019fdf5b7bb844e8d35b153bf8145192f213224def0
|
data/lib/flow.rb
ADDED
@@ -0,0 +1,128 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'yaml'
|
4
|
+
|
5
|
+
module Pm
|
6
|
+
module ExtendableByTag
|
7
|
+
def extend_by_tag
|
8
|
+
module_name = @config['tag'].split('_').collect(&:capitalize).join
|
9
|
+
|
10
|
+
module_defined = eval <<-RUBY, binding, __FILE__, __LINE__ + 1
|
11
|
+
defined? #{module_name}
|
12
|
+
RUBY
|
13
|
+
|
14
|
+
return unless module_defined
|
15
|
+
|
16
|
+
singleton_class.class_eval(
|
17
|
+
"include #{Object.const_get(module_name)}",
|
18
|
+
__FILE__,
|
19
|
+
__LINE__ - 2
|
20
|
+
)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
# Basic configuration for a processes
|
25
|
+
class Config
|
26
|
+
attr_reader :config
|
27
|
+
def load(dir = '.')
|
28
|
+
@config ||= {}
|
29
|
+
Dir[[dir, '*.yml'].join('/')].each do |file_name|
|
30
|
+
pc = YAML.load_file(file_name)
|
31
|
+
@config[pc['tag']] = pc
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
# Basic process
|
37
|
+
class Process
|
38
|
+
include ExtendableByTag
|
39
|
+
|
40
|
+
attr_reader :config, :context
|
41
|
+
|
42
|
+
def initialize(config, context)
|
43
|
+
@config = config
|
44
|
+
@context = context
|
45
|
+
@operations = []
|
46
|
+
|
47
|
+
extend_by_tag
|
48
|
+
end
|
49
|
+
|
50
|
+
def start
|
51
|
+
@operations = config['start'].map do |tag|
|
52
|
+
new_config = config['operations'].find { |o| o['tag'] == tag }
|
53
|
+
Operation.new(new_config, context)
|
54
|
+
end
|
55
|
+
run_iteration
|
56
|
+
end
|
57
|
+
|
58
|
+
def run_iteration
|
59
|
+
next_operations = @operations.select(&:ready?)
|
60
|
+
next_operations.map(&:complete)
|
61
|
+
|
62
|
+
next_operations.map do |old_operation|
|
63
|
+
next if old_operation.config[old_operation.status].nil?
|
64
|
+
|
65
|
+
build_next_operations(old_operation)
|
66
|
+
end
|
67
|
+
|
68
|
+
run_iteration if @operations.any?(&:ready?)
|
69
|
+
end
|
70
|
+
|
71
|
+
def build_next_operations(old_operation)
|
72
|
+
old_operation.config[old_operation.status].each do |operation_conf|
|
73
|
+
operation_conf.each do |tag, _value|
|
74
|
+
new_config = config['operations'].find { |o| o['tag'] == tag }
|
75
|
+
new_operations = Operation.new(new_config, old_operation.context)
|
76
|
+
@operations << new_operations
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
# Very basic operation implementation
|
83
|
+
class Operation
|
84
|
+
include ExtendableByTag
|
85
|
+
|
86
|
+
attr_reader :config, :context, :status
|
87
|
+
|
88
|
+
def initialize(config, context)
|
89
|
+
@config = config
|
90
|
+
@context = context
|
91
|
+
|
92
|
+
extend_by_tag
|
93
|
+
end
|
94
|
+
|
95
|
+
def tag
|
96
|
+
@config['tag']
|
97
|
+
end
|
98
|
+
|
99
|
+
def complete
|
100
|
+
perform if respond_to?(:perform)
|
101
|
+
@status = 'complete'
|
102
|
+
end
|
103
|
+
|
104
|
+
def ready?
|
105
|
+
status.nil?
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
# Manager is used to start and control processes
|
110
|
+
class Manager
|
111
|
+
def self.config
|
112
|
+
@config ||= begin
|
113
|
+
conf = Config.new
|
114
|
+
conf.load
|
115
|
+
conf
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
def self.start(tag, context, configuration = nil)
|
120
|
+
@config = configuration unless configuration.nil?
|
121
|
+
|
122
|
+
process_config = config.config[tag]
|
123
|
+
process = Process.new(process_config, context)
|
124
|
+
process.start
|
125
|
+
process
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
metadata
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: active_flow
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Maxim Madzhuga
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-06-18 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: A gem to build operations flows
|
14
|
+
email: maximmadzhuga@gmail.com
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/flow.rb
|
20
|
+
homepage: https://rubygems.org/gems/active_flow
|
21
|
+
licenses:
|
22
|
+
- MIT
|
23
|
+
metadata: {}
|
24
|
+
post_install_message:
|
25
|
+
rdoc_options: []
|
26
|
+
require_paths:
|
27
|
+
- lib
|
28
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
34
|
+
requirements:
|
35
|
+
- - ">="
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
requirements: []
|
39
|
+
rubyforge_project:
|
40
|
+
rubygems_version: 2.7.6
|
41
|
+
signing_key:
|
42
|
+
specification_version: 4
|
43
|
+
summary: ActiveFlow
|
44
|
+
test_files: []
|