riverbed 0.1.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 +7 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.rubocop.yml +19 -0
- data/CHANGELOG.md +5 -0
- data/Gemfile +12 -0
- data/Gemfile.lock +55 -0
- data/LICENSE.txt +21 -0
- data/README.md +90 -0
- data/Rakefile +12 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/lib/riverbed.rb +14 -0
- data/lib/riverbed/data.rb +52 -0
- data/lib/riverbed/flow.rb +68 -0
- data/lib/riverbed/step.rb +34 -0
- data/lib/riverbed/version.rb +5 -0
- data/riverbed.gemspec +37 -0
- metadata +63 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 5c5d4978c088d800b517175a266ff9f025c1566b17f4820d64d9a60cc563e968
|
|
4
|
+
data.tar.gz: 803fce7525da68cf7f039e21d4e872de9cf7b421cf58f895da5fca208f52be8b
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: ea44732a062ed725d831d6abdd4c15c69ff9df667b26b30ed9014c8e86af51bd385168c3b0c669521ae1ca9efd0bf08e94a5551329a694430058f80c491e9e76
|
|
7
|
+
data.tar.gz: 4fd7136f509059fab6d0525f7125f9aaa6be070868e824e7dfa27e83422a537377a33ca47ea035f5c271defcbd183da2db50277ba011423ce17fda43fa390fd8
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
AllCops:
|
|
2
|
+
TargetRubyVersion: 2.5
|
|
3
|
+
|
|
4
|
+
Style/StringLiterals:
|
|
5
|
+
Enabled: true
|
|
6
|
+
EnforcedStyle: double_quotes
|
|
7
|
+
|
|
8
|
+
Style/StringLiteralsInInterpolation:
|
|
9
|
+
Enabled: true
|
|
10
|
+
EnforcedStyle: double_quotes
|
|
11
|
+
|
|
12
|
+
Style/Documentation:
|
|
13
|
+
Enabled: false
|
|
14
|
+
|
|
15
|
+
Gemspec/RequiredRubyVersion:
|
|
16
|
+
Enabled: false
|
|
17
|
+
|
|
18
|
+
Layout/LineLength:
|
|
19
|
+
Max: 120
|
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
PATH
|
|
2
|
+
remote: .
|
|
3
|
+
specs:
|
|
4
|
+
riverbed (0.1.0)
|
|
5
|
+
|
|
6
|
+
GEM
|
|
7
|
+
remote: https://rubygems.org/
|
|
8
|
+
specs:
|
|
9
|
+
ast (2.4.2)
|
|
10
|
+
diff-lcs (1.4.4)
|
|
11
|
+
parallel (1.20.1)
|
|
12
|
+
parser (3.0.1.1)
|
|
13
|
+
ast (~> 2.4.1)
|
|
14
|
+
rainbow (3.0.0)
|
|
15
|
+
rake (13.0.3)
|
|
16
|
+
regexp_parser (2.1.1)
|
|
17
|
+
rexml (3.2.5)
|
|
18
|
+
rspec (3.10.0)
|
|
19
|
+
rspec-core (~> 3.10.0)
|
|
20
|
+
rspec-expectations (~> 3.10.0)
|
|
21
|
+
rspec-mocks (~> 3.10.0)
|
|
22
|
+
rspec-core (3.10.1)
|
|
23
|
+
rspec-support (~> 3.10.0)
|
|
24
|
+
rspec-expectations (3.10.1)
|
|
25
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
26
|
+
rspec-support (~> 3.10.0)
|
|
27
|
+
rspec-mocks (3.10.2)
|
|
28
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
29
|
+
rspec-support (~> 3.10.0)
|
|
30
|
+
rspec-support (3.10.2)
|
|
31
|
+
rubocop (1.17.0)
|
|
32
|
+
parallel (~> 1.10)
|
|
33
|
+
parser (>= 3.0.0.0)
|
|
34
|
+
rainbow (>= 2.2.2, < 4.0)
|
|
35
|
+
regexp_parser (>= 1.8, < 3.0)
|
|
36
|
+
rexml
|
|
37
|
+
rubocop-ast (>= 1.7.0, < 2.0)
|
|
38
|
+
ruby-progressbar (~> 1.7)
|
|
39
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
|
40
|
+
rubocop-ast (1.7.0)
|
|
41
|
+
parser (>= 3.0.1.1)
|
|
42
|
+
ruby-progressbar (1.11.0)
|
|
43
|
+
unicode-display_width (2.0.0)
|
|
44
|
+
|
|
45
|
+
PLATFORMS
|
|
46
|
+
x86_64-linux
|
|
47
|
+
|
|
48
|
+
DEPENDENCIES
|
|
49
|
+
rake (~> 13.0)
|
|
50
|
+
riverbed!
|
|
51
|
+
rspec (~> 3.0)
|
|
52
|
+
rubocop (~> 1.7)
|
|
53
|
+
|
|
54
|
+
BUNDLED WITH
|
|
55
|
+
2.2.17
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021 Bnq
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
# Riverbed
|
|
2
|
+
|
|
3
|
+
A business logic ruby gem, initial release, WIP.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Add this line to your application's Gemfile:
|
|
8
|
+
|
|
9
|
+
```ruby
|
|
10
|
+
gem 'riverbed'
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
And then execute:
|
|
14
|
+
|
|
15
|
+
$ bundle install
|
|
16
|
+
|
|
17
|
+
Or install it yourself as:
|
|
18
|
+
|
|
19
|
+
$ gem install riverbed
|
|
20
|
+
|
|
21
|
+
## Usage
|
|
22
|
+
|
|
23
|
+
### Min example:
|
|
24
|
+
```ruby
|
|
25
|
+
require "riverbed"
|
|
26
|
+
|
|
27
|
+
class Step1 < Riverbed::Step
|
|
28
|
+
def execute; end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
class Flow1 < Riverbed::Flow
|
|
32
|
+
def steps
|
|
33
|
+
[
|
|
34
|
+
Step1
|
|
35
|
+
]
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
Flow1.run
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### Usage example:
|
|
43
|
+
|
|
44
|
+
```ruby
|
|
45
|
+
require "riverbed"
|
|
46
|
+
|
|
47
|
+
class Step2 < Riverbed::Step
|
|
48
|
+
def execute
|
|
49
|
+
puts flow_data.input + " world" # flow ipnut
|
|
50
|
+
|
|
51
|
+
flow_data.add(:abc, 123) # sets key :abc in flow data container
|
|
52
|
+
|
|
53
|
+
10
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
# gets result of previous step (or input if no previous steps exist)
|
|
58
|
+
# and adds to value of key abc
|
|
59
|
+
# `flow_data.get(:a)` will return nil if key not present, `flow_data.get!(:a)` will raise error if key not preset
|
|
60
|
+
class Step3 < Riverbed::Step
|
|
61
|
+
def execute
|
|
62
|
+
flow_data.last_result + flow_data.get(:abc)
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
class Flow2 < Riverbed::Flow
|
|
67
|
+
def steps
|
|
68
|
+
[
|
|
69
|
+
Step2,
|
|
70
|
+
Step3
|
|
71
|
+
]
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
input = "Hello"
|
|
76
|
+
result = Flow2.run(input, options: {}) # can set `options: { logger: nil }` to skip step execution time logging
|
|
77
|
+
|
|
78
|
+
puts "Final result: #{result}"
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
Check tests for more examples
|
|
82
|
+
|
|
83
|
+
## Contributing
|
|
84
|
+
|
|
85
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/softcapybara/riverbed.
|
|
86
|
+
|
|
87
|
+
## License
|
|
88
|
+
|
|
89
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
|
90
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require "bundler/setup"
|
|
5
|
+
require "riverbed"
|
|
6
|
+
|
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
|
9
|
+
|
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
|
11
|
+
# require "pry"
|
|
12
|
+
# Pry.start
|
|
13
|
+
|
|
14
|
+
require "irb"
|
|
15
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/lib/riverbed.rb
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "logger"
|
|
4
|
+
require "securerandom"
|
|
5
|
+
|
|
6
|
+
require_relative "riverbed/version"
|
|
7
|
+
require_relative "riverbed/data"
|
|
8
|
+
require_relative "riverbed/step"
|
|
9
|
+
require_relative "riverbed/flow"
|
|
10
|
+
|
|
11
|
+
module Riverbed
|
|
12
|
+
class Error < StandardError; end
|
|
13
|
+
# Your code goes here...
|
|
14
|
+
end
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Riverbed
|
|
4
|
+
class Data
|
|
5
|
+
attr_reader :input
|
|
6
|
+
|
|
7
|
+
def initialize(input)
|
|
8
|
+
@input = input
|
|
9
|
+
@results = []
|
|
10
|
+
@executed_steps = []
|
|
11
|
+
@registered = {}
|
|
12
|
+
@errors ||= []
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def add_result(step_name, result)
|
|
16
|
+
executed_steps << step_name
|
|
17
|
+
results << result
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def last_result
|
|
21
|
+
if results.empty?
|
|
22
|
+
@input
|
|
23
|
+
else
|
|
24
|
+
results.last
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def add(name, value)
|
|
29
|
+
registered[name] = value
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def get(name)
|
|
33
|
+
registered[name]
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def get!(name)
|
|
37
|
+
registered.fetch(name)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def add_error(err)
|
|
41
|
+
@errors << err
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def last_error
|
|
45
|
+
@errors.last
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
private
|
|
49
|
+
|
|
50
|
+
attr_accessor :results, :registered, :executed_steps, :errors
|
|
51
|
+
end
|
|
52
|
+
end
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Riverbed
|
|
4
|
+
class Flow
|
|
5
|
+
def initialize(input, options)
|
|
6
|
+
@logger = options.fetch(:logger, Logger.new($stdout))
|
|
7
|
+
|
|
8
|
+
@data = options.fetch(:data_object, Riverbed::Data.new(input))
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def self.run(input = nil, options: {})
|
|
12
|
+
new(input, options).run
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def steps
|
|
16
|
+
raise NotImplementedError
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def always
|
|
20
|
+
[]
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def run
|
|
24
|
+
begin
|
|
25
|
+
run_steps(steps)
|
|
26
|
+
rescue StandardError => e
|
|
27
|
+
on_error(e)
|
|
28
|
+
data.add_error(e)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
run_steps(always)
|
|
32
|
+
|
|
33
|
+
data.last_result
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
private
|
|
37
|
+
|
|
38
|
+
attr_accessor :logger, :data
|
|
39
|
+
|
|
40
|
+
def run_steps(steps)
|
|
41
|
+
steps.each do |step_class|
|
|
42
|
+
step = step_class.new(data, logger)
|
|
43
|
+
next if step.skip?
|
|
44
|
+
|
|
45
|
+
log_execution(step.name) do
|
|
46
|
+
data.add_result(step.name, step.execute)
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
break if step.break_flow?
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def log_execution(step_name)
|
|
54
|
+
start_time = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
|
55
|
+
yield
|
|
56
|
+
end_time = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
|
57
|
+
logger&.info("#{log_id} Step #{step_name} executed in #{((end_time - start_time) * 1000).round(2)} ms")
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def log_id
|
|
61
|
+
@log_id ||= SecureRandom.urlsafe_base64(8)
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def on_error(error)
|
|
65
|
+
logger&.error(error)
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
end
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Riverbed
|
|
4
|
+
class Step
|
|
5
|
+
def initialize(flow_data, logger)
|
|
6
|
+
@flow_data = flow_data
|
|
7
|
+
@logger = logger
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def skip?
|
|
11
|
+
false
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def break_flow?
|
|
15
|
+
false
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def execute
|
|
19
|
+
raise NotImplementedError
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def name
|
|
23
|
+
self.class.name
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def log_error(err)
|
|
27
|
+
@error = err
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
private
|
|
31
|
+
|
|
32
|
+
attr_accessor :flow_data, :logger, :error
|
|
33
|
+
end
|
|
34
|
+
end
|
data/riverbed.gemspec
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "lib/riverbed/version"
|
|
4
|
+
|
|
5
|
+
Gem::Specification.new do |spec|
|
|
6
|
+
spec.name = "riverbed"
|
|
7
|
+
spec.version = Riverbed::VERSION
|
|
8
|
+
spec.authors = ["BMaczka"]
|
|
9
|
+
spec.email = ["bmaczka@hey.com"]
|
|
10
|
+
|
|
11
|
+
spec.summary = "Ruby business logic gem"
|
|
12
|
+
spec.description = "Ruby business logic gem"
|
|
13
|
+
spec.homepage = "https://github.com/softcapybara/riverbed"
|
|
14
|
+
spec.license = "MIT"
|
|
15
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.4.0")
|
|
16
|
+
|
|
17
|
+
# spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
|
|
18
|
+
|
|
19
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
|
20
|
+
spec.metadata["source_code_uri"] = "https://github.com/softcapybara/riverbed"
|
|
21
|
+
spec.metadata["changelog_uri"] = "https://github.com/softcapybara/riverbed"
|
|
22
|
+
|
|
23
|
+
# Specify which files should be added to the gem when it is released.
|
|
24
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
|
25
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
|
26
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
|
|
27
|
+
end
|
|
28
|
+
spec.bindir = "exe"
|
|
29
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
|
30
|
+
spec.require_paths = ["lib"]
|
|
31
|
+
|
|
32
|
+
# Uncomment to register a new dependency of your gem
|
|
33
|
+
# spec.add_dependency "example-gem", "~> 1.0"
|
|
34
|
+
|
|
35
|
+
# For more information and examples about making a new gem, checkout our
|
|
36
|
+
# guide at: https://bundler.io/guides/creating_gem.html
|
|
37
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: riverbed
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- BMaczka
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: exe
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2021-06-26 00:00:00.000000000 Z
|
|
12
|
+
dependencies: []
|
|
13
|
+
description: Ruby business logic gem
|
|
14
|
+
email:
|
|
15
|
+
- bmaczka@hey.com
|
|
16
|
+
executables: []
|
|
17
|
+
extensions: []
|
|
18
|
+
extra_rdoc_files: []
|
|
19
|
+
files:
|
|
20
|
+
- ".gitignore"
|
|
21
|
+
- ".rspec"
|
|
22
|
+
- ".rubocop.yml"
|
|
23
|
+
- CHANGELOG.md
|
|
24
|
+
- Gemfile
|
|
25
|
+
- Gemfile.lock
|
|
26
|
+
- LICENSE.txt
|
|
27
|
+
- README.md
|
|
28
|
+
- Rakefile
|
|
29
|
+
- bin/console
|
|
30
|
+
- bin/setup
|
|
31
|
+
- lib/riverbed.rb
|
|
32
|
+
- lib/riverbed/data.rb
|
|
33
|
+
- lib/riverbed/flow.rb
|
|
34
|
+
- lib/riverbed/step.rb
|
|
35
|
+
- lib/riverbed/version.rb
|
|
36
|
+
- riverbed.gemspec
|
|
37
|
+
homepage: https://github.com/softcapybara/riverbed
|
|
38
|
+
licenses:
|
|
39
|
+
- MIT
|
|
40
|
+
metadata:
|
|
41
|
+
homepage_uri: https://github.com/softcapybara/riverbed
|
|
42
|
+
source_code_uri: https://github.com/softcapybara/riverbed
|
|
43
|
+
changelog_uri: https://github.com/softcapybara/riverbed
|
|
44
|
+
post_install_message:
|
|
45
|
+
rdoc_options: []
|
|
46
|
+
require_paths:
|
|
47
|
+
- lib
|
|
48
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
49
|
+
requirements:
|
|
50
|
+
- - ">="
|
|
51
|
+
- !ruby/object:Gem::Version
|
|
52
|
+
version: 2.4.0
|
|
53
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
54
|
+
requirements:
|
|
55
|
+
- - ">="
|
|
56
|
+
- !ruby/object:Gem::Version
|
|
57
|
+
version: '0'
|
|
58
|
+
requirements: []
|
|
59
|
+
rubygems_version: 3.1.4
|
|
60
|
+
signing_key:
|
|
61
|
+
specification_version: 4
|
|
62
|
+
summary: Ruby business logic gem
|
|
63
|
+
test_files: []
|