riverbed 0.1.0 → 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5c5d4978c088d800b517175a266ff9f025c1566b17f4820d64d9a60cc563e968
4
- data.tar.gz: 803fce7525da68cf7f039e21d4e872de9cf7b421cf58f895da5fca208f52be8b
3
+ metadata.gz: b70bef824c3c371e0b0511299f23855b02f64330bb767694b1594111a64c43da
4
+ data.tar.gz: cd22f4267059c7c959eba2e32fedd708f5b904b8170302aea84be28edb0bdf67
5
5
  SHA512:
6
- metadata.gz: ea44732a062ed725d831d6abdd4c15c69ff9df667b26b30ed9014c8e86af51bd385168c3b0c669521ae1ca9efd0bf08e94a5551329a694430058f80c491e9e76
7
- data.tar.gz: 4fd7136f509059fab6d0525f7125f9aaa6be070868e824e7dfa27e83422a537377a33ca47ea035f5c271defcbd183da2db50277ba011423ce17fda43fa390fd8
6
+ metadata.gz: 8f2f00bd0d73d7ea9eb42532dfc2a5bbba96bac58802e7661ce3514caa1eeca71c89617c9c8e69239d6197ff0ff2efcd8d9a93895ca5f9f32c6e256aaae96e04
7
+ data.tar.gz: e033f70f409f9454c0b2d478cb5330ca337f47dc643e46d0fc123ff40201fb99cc0db2fbaebdbea9b4bebadb03db3a5dc834d169af6c4bc7232ece762f02b1b4
data/CHANGELOG.md CHANGED
@@ -1,5 +1,27 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.2.0] - 2021-09-24
4
+ - Add log_id option to flow
5
+ ```ruby
6
+ Flow.run(nil, { log_id: "abc_my_session_id" })
7
+ ```
8
+
9
+ - Change the way in which flow accepts parameters. Now flow options are second parameter.
10
+ Old way, no longer accepted:
11
+ ```ruby
12
+ Flow.run(options: { logger: nil })
13
+ Flow.run({}, options: { logger: nil })
14
+ # Flow.run({}) ## This would raise error
15
+ ```
16
+
17
+ New way:
18
+ ```ruby
19
+ Flow.run(nil, { logger: nil })
20
+ Flow.run({}, { logger: nil })
21
+ # Flow.run(options: { logger: nil }) ## This would land in input instead of options
22
+ # Flow.run({}, options: { logger: nil }) ## This would cause code to ignore options
23
+ ```
24
+
3
25
  ## [0.1.0] - 2021-06-26
4
26
 
5
27
  - Initial release
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- riverbed (0.1.0)
4
+ riverbed (0.2.1)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -20,7 +20,7 @@ Or install it yourself as:
20
20
 
21
21
  ## Usage
22
22
 
23
- ### Min example:
23
+ ### Min working example:
24
24
  ```ruby
25
25
  require "riverbed"
26
26
 
@@ -44,9 +44,12 @@ Flow1.run
44
44
  ```ruby
45
45
  require "riverbed"
46
46
 
47
+ # uses flow input to print "Hello world"
48
+ # stores data in flow_data - object available in all steps for storing and retreiving data
49
+ # returns 10, which can be accessed in next step through `last_result` method called on flow_data
47
50
  class Step2 < Riverbed::Step
48
51
  def execute
49
- puts flow_data.input + " world" # flow ipnut
52
+ puts flow_data.input + " world"
50
53
 
51
54
  flow_data.add(:abc, 123) # sets key :abc in flow data container
52
55
 
@@ -54,6 +57,8 @@ class Step2 < Riverbed::Step
54
57
  end
55
58
  end
56
59
 
60
+
61
+
57
62
  # gets result of previous step (or input if no previous steps exist)
58
63
  # and adds to value of key abc
59
64
  # `flow_data.get(:a)` will return nil if key not present, `flow_data.get!(:a)` will raise error if key not preset
@@ -73,10 +78,33 @@ class Flow2 < Riverbed::Flow
73
78
  end
74
79
 
75
80
  input = "Hello"
76
- result = Flow2.run(input, options: {}) # can set `options: { logger: nil }` to skip step execution time logging
81
+ result = Flow2.run(input)
82
+ # Flow2.run(input, { logger: nil }) - second parameter is for options
83
+ # available options:
84
+ # `logger: nil` to skip step execution time logging
85
+ # `log_id: "abc"` sets log_id displayed when logging flow progress
86
+ # `data_object: Riverbed::Data.new(my: :data)` if you want to use existing data object, eg. from previous flow
77
87
 
78
88
  puts "Final result: #{result}"
79
89
  ```
90
+ ### Options
91
+ To run example flow with options:
92
+ `Flow2.run(input, { logger: nil })` - second parameter is for options
93
+ Available options:
94
+ - `logger: nil` to skip logging
95
+ - `log_id: "abc"` sets log_id displayed when logging flow progress
96
+ - `data_object: Riverbed::Data.new(my: :data)` if you want to use existing data object, eg. from previous flow.
97
+
98
+ ### Available Flow Data methods
99
+ #### Add to data container:
100
+ `flow_data.add(:abc, 123)`
101
+ #### Get value from data container:
102
+ `flow_data.get(:abc)`
103
+ `flow_data.get!(:abc)` # raises error if value is not set
104
+ #### Get flow input value from data container:
105
+ `flow_data.input`
106
+ #### Get result of last step from data container:
107
+ `flow_data.last_result`
80
108
 
81
109
  Check tests for more examples
82
110
 
data/lib/riverbed/flow.rb CHANGED
@@ -4,11 +4,12 @@ module Riverbed
4
4
  class Flow
5
5
  def initialize(input, options)
6
6
  @logger = options.fetch(:logger, Logger.new($stdout))
7
+ @log_id = options.fetch(:log_id, generate_log_id)
7
8
 
8
9
  @data = options.fetch(:data_object, Riverbed::Data.new(input))
9
10
  end
10
11
 
11
- def self.run(input = nil, options: {})
12
+ def self.run(input = nil, options = {})
12
13
  new(input, options).run
13
14
  end
14
15
 
@@ -21,6 +22,8 @@ module Riverbed
21
22
  end
22
23
 
23
24
  def run
25
+ log_flow_start
26
+
24
27
  begin
25
28
  run_steps(steps)
26
29
  rescue StandardError => e
@@ -29,13 +32,14 @@ module Riverbed
29
32
  end
30
33
 
31
34
  run_steps(always)
35
+ log_flow_end
32
36
 
33
37
  data.last_result
34
38
  end
35
39
 
36
40
  private
37
41
 
38
- attr_accessor :logger, :data
42
+ attr_accessor :logger, :data, :log_id
39
43
 
40
44
  def run_steps(steps)
41
45
  steps.each do |step_class|
@@ -57,8 +61,16 @@ module Riverbed
57
61
  logger&.info("#{log_id} Step #{step_name} executed in #{((end_time - start_time) * 1000).round(2)} ms")
58
62
  end
59
63
 
60
- def log_id
61
- @log_id ||= SecureRandom.urlsafe_base64(8)
64
+ def generate_log_id
65
+ SecureRandom.urlsafe_base64(8)
66
+ end
67
+
68
+ def log_flow_start
69
+ logger&.info("#{log_id} Starting flow #{self.class}")
70
+ end
71
+
72
+ def log_flow_end
73
+ logger&.info("#{log_id} Ending flow #{self.class}")
62
74
  end
63
75
 
64
76
  def on_error(error)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Riverbed
4
- VERSION = "0.1.0"
4
+ VERSION = "0.2.1"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: riverbed
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - BMaczka
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-06-26 00:00:00.000000000 Z
11
+ date: 2021-09-24 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Ruby business logic gem
14
14
  email: