orchestrate_flow 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c98428620a6c142019c6b2380998d5e109dab19ec00f9be1834994fe878202b6
4
- data.tar.gz: b89e58482608fb95da472a459ae51a4ce4cb134892100975c5006c7f2f91a9d9
3
+ metadata.gz: 8e6805b3b41e73cd47820f9cb2bcfc27045c26b043615b3fef3531893b2591b7
4
+ data.tar.gz: 48baaf4ddee5bce3face34173297f3dba9c65ca200c887a29d4fa6c2524046a0
5
5
  SHA512:
6
- metadata.gz: fcdbc1acf7249b729d67ccb0561b2b1f4931a6fa2a27c202b7cdc690843cb79ec29bae307d3d13083f71b5c0ba65df775608df41ec756a1918ddf1e31b601243
7
- data.tar.gz: 7cec65f20eb9ca0b452ec5c9a007805be3d84914129e6b2a0098ddff0924d541e06bd7e37c7a01fefa58b58c66739cca1dbf5afe28896b473c16583a22e96c12
6
+ metadata.gz: ab0a2cebf92c3d6b5821776a068443068c7f5411cf2841d35ef522798c7b92b113a5c1674f6b333c6d7770067b8303fb07f86eb54985e154edd683c745cbbe66
7
+ data.tar.gz: 6423392a96dd5daef74f18095f49e989830bd2c4242cb4f3deaa0efca95f1dd71c0dad522786e051a998ac1b573f5f9caf8de1bb70e0189d1c1a33df18d6e520
data/Gemfile.lock ADDED
@@ -0,0 +1,59 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ orchestrate_flow (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ ast (2.4.2)
10
+ diff-lcs (1.5.1)
11
+ json (2.7.5)
12
+ language_server-protocol (3.17.0.3)
13
+ parallel (1.26.3)
14
+ parser (3.3.5.1)
15
+ ast (~> 2.4.1)
16
+ racc
17
+ racc (1.8.1)
18
+ rainbow (3.1.1)
19
+ rake (13.2.1)
20
+ regexp_parser (2.9.2)
21
+ rspec (3.13.0)
22
+ rspec-core (~> 3.13.0)
23
+ rspec-expectations (~> 3.13.0)
24
+ rspec-mocks (~> 3.13.0)
25
+ rspec-core (3.13.2)
26
+ rspec-support (~> 3.13.0)
27
+ rspec-expectations (3.13.3)
28
+ diff-lcs (>= 1.2.0, < 2.0)
29
+ rspec-support (~> 3.13.0)
30
+ rspec-mocks (3.13.2)
31
+ diff-lcs (>= 1.2.0, < 2.0)
32
+ rspec-support (~> 3.13.0)
33
+ rspec-support (3.13.1)
34
+ rubocop (1.68.0)
35
+ json (~> 2.3)
36
+ language_server-protocol (>= 3.17.0)
37
+ parallel (~> 1.10)
38
+ parser (>= 3.3.0.2)
39
+ rainbow (>= 2.2.2, < 4.0)
40
+ regexp_parser (>= 2.4, < 3.0)
41
+ rubocop-ast (>= 1.32.2, < 2.0)
42
+ ruby-progressbar (~> 1.7)
43
+ unicode-display_width (>= 2.4.0, < 3.0)
44
+ rubocop-ast (1.33.1)
45
+ parser (>= 3.3.1.0)
46
+ ruby-progressbar (1.13.0)
47
+ unicode-display_width (2.6.0)
48
+
49
+ PLATFORMS
50
+ arm64-darwin-21
51
+
52
+ DEPENDENCIES
53
+ orchestrate_flow!
54
+ rake (~> 13.0)
55
+ rspec (~> 3.0)
56
+ rubocop (~> 1.21)
57
+
58
+ BUNDLED WITH
59
+ 2.2.32
data/README.md CHANGED
@@ -27,7 +27,47 @@ Or install it yourself as:
27
27
 
28
28
  ## Usage
29
29
 
30
- TODO: Write usage instructions here
30
+ ### Defining a Workflow
31
+ You can define states, transitions, and event actions as follows
32
+
33
+ ```ruby
34
+ # Usage Example
35
+
36
+ # Define a custom workflow class
37
+ class MyWorkflow < OrchestrateFlow::Workflow
38
+ # Define possible states
39
+ state :pending
40
+ state :in_progress
41
+ state :completed
42
+ state :failed
43
+
44
+ # Define transitions between states
45
+ transition event: :start, from: :pending, to: :in_progress
46
+ transition event: :complete, from: :in_progress, to: :completed
47
+ transition event: :fail, from: :in_progress, to: :failed
48
+
49
+ # Define actions to trigger on specific events
50
+ on :start do
51
+ puts "Workflow started!"
52
+ end
53
+
54
+ on :complete do
55
+ puts "Workflow completed successfully!"
56
+ end
57
+
58
+ on :fail do
59
+ puts "Workflow failed. Please try again."
60
+ end
61
+ end
62
+
63
+ # Initialize the workflow and trigger events
64
+ workflow = MyWorkflow.new
65
+ puts workflow.state # => :pending
66
+ workflow.trigger(:start) # => Workflow started!
67
+ puts workflow.state # => :in_progress
68
+ workflow.trigger(:complete) # => Workflow completed successfully!
69
+ puts workflow.state # => :completed
70
+ ```
31
71
 
32
72
  ## Development
33
73
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module OrchestrateFlow
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.1"
5
5
  end
@@ -0,0 +1,75 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OrchestrateFlow
4
+ # The Workflow class represents a basic state machine for defining workflows
5
+ # with states, transitions, and event-driven actions. It allows developers
6
+ # to manage complex workflows using defined states and triggers.
7
+ class Workflow
8
+ attr_reader :state
9
+
10
+ def initialize
11
+ @state = :pending
12
+ @transitions = {}
13
+ @event_actions = {}
14
+ end
15
+
16
+ # Define a new state
17
+ def self.state(name)
18
+ @states ||= []
19
+ @states << name
20
+ define_method("#{name}?") { @state == name }
21
+ end
22
+
23
+ # Define a transition between states
24
+ def self.transition(event:, from:, to:)
25
+ @transitions ||= {}
26
+ @transitions[event] = { from: from, to: to }
27
+ end
28
+
29
+ # Define actions to trigger on events
30
+ def self.on(event, &action)
31
+ @event_actions ||= {}
32
+ @event_actions[event] = action
33
+ end
34
+
35
+ # Execute a transition event
36
+ def trigger(event)
37
+ unless valid_transition?(event)
38
+ raise InvalidTransitionError, "Cannot transition from #{@state} using event #{event}"
39
+ end
40
+
41
+ execute_event_action(event)
42
+ @state = self.class.transitions[event][:to]
43
+ end
44
+
45
+ # Accessors for states, transitions, and event actions
46
+ class << self
47
+ attr_reader :states
48
+ end
49
+
50
+ class << self
51
+ attr_reader :transitions
52
+ end
53
+
54
+ class << self
55
+ attr_reader :event_actions
56
+ end
57
+
58
+ private
59
+
60
+ # Validate if a transition is allowed
61
+ def valid_transition?(event)
62
+ transition = self.class.transitions[event]
63
+ transition && transition[:from] == @state
64
+ end
65
+
66
+ # Execute an event action if defined
67
+ def execute_event_action(event)
68
+ action = self.class.event_actions[event]
69
+ action&.call
70
+ end
71
+
72
+ # Custom error for invalid transitions
73
+ class InvalidTransitionError < StandardError; end
74
+ end
75
+ end
@@ -1,9 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative "orchestrate_flow/version"
4
+ require_relative "orchestrate_flow/workflow"
4
5
 
6
+ # OrchestrateFlow is a Ruby gem module for managing complex workflows and task orchestration.
7
+ # It provides tools for defining states, transitions, and event-driven actions.
5
8
  module OrchestrateFlow
6
- def self.hello
7
- "Hello, World from OrchestrateFlow!"
8
- end
9
9
  end
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/orchestrate_flow/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "orchestrate_flow"
7
+ spec.version = OrchestrateFlow::VERSION
8
+ spec.authors = ["Daniel Morales"]
9
+ spec.email = ["danielmorales1202@gmail.com"]
10
+
11
+ spec.summary = "Native orchestration in Ruby with advanced workflow capabilities"
12
+ spec.description = "Ruby gem for managing complex workflows and orchestrating tasks."
13
+ spec.homepage = "https://compensix.com"
14
+ spec.license = "MIT"
15
+ spec.required_ruby_version = ">= 2.6.0"
16
+
17
+ # spec.metadata["allowed_push_host"] = "TODO: Set to your gem server 'https://example.com'"
18
+
19
+ spec.metadata["homepage_uri"] = spec.homepage
20
+ spec.metadata["source_code_uri"] = "https://github.com/danielmoralesp/orchestrate_flow"
21
+ spec.metadata["changelog_uri"] = "https://github.com/danielmoralesp/orchestrate_flow/CHANGELOG.md"
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.glob("**/*").reject do |file|
26
+ file.match(%r{\A(?:test|spec|features)/}) ||
27
+ file.match(/\A\.(git|travis|circleci|appveyor)/) ||
28
+ file.match(/\.gem$/) # Exclude .gem files from the gem package
29
+ end
30
+
31
+ spec.bindir = "exe"
32
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
33
+ spec.require_paths = ["lib"]
34
+
35
+ # Uncomment to register a new dependency of your gem
36
+ # spec.add_dependency "example-gem", "~> 1.0"
37
+ spec.add_development_dependency "rspec", "~> 3.0"
38
+
39
+ # For more information and examples about making a new gem, checkout our
40
+ # guide at: https://bundler.io/guides/creating_gem.html
41
+ end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: orchestrate_flow
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
  - Daniel Morales
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-10-30 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2024-11-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.0'
13
27
  description: Ruby gem for managing complex workflows and orchestrating tasks.
14
28
  email:
15
29
  - danielmorales1202@gmail.com
@@ -17,11 +31,10 @@ executables: []
17
31
  extensions: []
18
32
  extra_rdoc_files: []
19
33
  files:
20
- - ".rspec"
21
- - ".rubocop.yml"
22
34
  - CHANGELOG.md
23
35
  - CODE_OF_CONDUCT.md
24
36
  - Gemfile
37
+ - Gemfile.lock
25
38
  - LICENSE.txt
26
39
  - README.md
27
40
  - Rakefile
@@ -29,6 +42,8 @@ files:
29
42
  - bin/setup
30
43
  - lib/orchestrate_flow.rb
31
44
  - lib/orchestrate_flow/version.rb
45
+ - lib/orchestrate_flow/workflow.rb
46
+ - orchestrate_flow.gemspec
32
47
  homepage: https://compensix.com
33
48
  licenses:
34
49
  - MIT
data/.rspec DELETED
@@ -1,3 +0,0 @@
1
- --format documentation
2
- --color
3
- --require spec_helper
data/.rubocop.yml DELETED
@@ -1,13 +0,0 @@
1
- AllCops:
2
- TargetRubyVersion: 2.6
3
-
4
- Style/StringLiterals:
5
- Enabled: true
6
- EnforcedStyle: double_quotes
7
-
8
- Style/StringLiteralsInInterpolation:
9
- Enabled: true
10
- EnforcedStyle: double_quotes
11
-
12
- Layout/LineLength:
13
- Max: 120