workflower 0.2.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 18c999bb59c66918bd57ac930be03d55d79a5fc955e1a2972621aa83b2c7b654
4
+ data.tar.gz: 839e96f58e78d27bf91b7ee287545ba87ed370d5969e207a31b3027f7087af79
5
+ SHA512:
6
+ metadata.gz: aeb7a5d9bef2fd3f2bcfc4dfc597f71fdab5d71f2feb76be3d6dd0ece9297aaef584a24cb196f52bc65ef224a3a60bbf84ce7c237e3ffe8c51fdbbd3350fbca0
7
+ data.tar.gz: 9cb5be4608a30639683a45a94dfaead6ce2218551bc5399b31cee01daeb860df80a4cbb8428040c5364c971a72c7c714a7f3faecb54b24d4785074ae8f838629
data/.gitignore ADDED
@@ -0,0 +1,13 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
12
+
13
+ .byebug_history
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,12 @@
1
+ Style/StringLiterals:
2
+ Enabled: true
3
+ EnforcedStyle: double_quotes
4
+
5
+ Style/StringLiteralsInInterpolation:
6
+ Enabled: true
7
+ EnforcedStyle: double_quotes
8
+
9
+ Layout/LineLength:
10
+ Max: 120
11
+ AllCops:
12
+ NewCops: enable
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 3.0.0
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at broosk.edogawa@gmail.com. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in workflower.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "rspec", "~> 3.0"
11
+
12
+ gem "rubocop", "~> 0.80"
data/Gemfile.lock ADDED
@@ -0,0 +1,70 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ workflower (0.2.5)
5
+ activesupport (>= 6.0.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ activesupport (7.0.4.3)
11
+ concurrent-ruby (~> 1.0, >= 1.0.2)
12
+ i18n (>= 1.6, < 2)
13
+ minitest (>= 5.1)
14
+ tzinfo (~> 2.0)
15
+ ast (2.4.2)
16
+ byebug (11.1.3)
17
+ concurrent-ruby (1.2.2)
18
+ diff-lcs (1.4.4)
19
+ i18n (1.12.0)
20
+ concurrent-ruby (~> 1.0)
21
+ minitest (5.18.0)
22
+ parallel (1.20.1)
23
+ parser (3.0.0.0)
24
+ ast (~> 2.4.1)
25
+ rainbow (3.0.0)
26
+ rake (13.0.3)
27
+ regexp_parser (2.1.1)
28
+ rexml (3.2.5)
29
+ rspec (3.10.0)
30
+ rspec-core (~> 3.10.0)
31
+ rspec-expectations (~> 3.10.0)
32
+ rspec-mocks (~> 3.10.0)
33
+ rspec-core (3.10.1)
34
+ rspec-support (~> 3.10.0)
35
+ rspec-expectations (3.10.1)
36
+ diff-lcs (>= 1.2.0, < 2.0)
37
+ rspec-support (~> 3.10.0)
38
+ rspec-mocks (3.10.2)
39
+ diff-lcs (>= 1.2.0, < 2.0)
40
+ rspec-support (~> 3.10.0)
41
+ rspec-support (3.10.2)
42
+ rubocop (0.93.1)
43
+ parallel (~> 1.10)
44
+ parser (>= 2.7.1.5)
45
+ rainbow (>= 2.2.2, < 4.0)
46
+ regexp_parser (>= 1.8)
47
+ rexml
48
+ rubocop-ast (>= 0.6.0)
49
+ ruby-progressbar (~> 1.7)
50
+ unicode-display_width (>= 1.4.0, < 2.0)
51
+ rubocop-ast (1.4.1)
52
+ parser (>= 2.7.1.5)
53
+ ruby-progressbar (1.11.0)
54
+ tzinfo (2.0.6)
55
+ concurrent-ruby (~> 1.0)
56
+ unicode-display_width (1.7.0)
57
+
58
+ PLATFORMS
59
+ ruby
60
+ x86_64-linux
61
+
62
+ DEPENDENCIES
63
+ byebug
64
+ rake (~> 13.0)
65
+ rspec (~> 3.0)
66
+ rubocop (~> 0.80)
67
+ workflower!
68
+
69
+ BUNDLED WITH
70
+ 2.2.3
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021 Brusk Hamarash
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,43 @@
1
+ # Workflower
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/workflower`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'workflower'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install workflower
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/workflower. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/workflower/blob/master/CODE_OF_CONDUCT.md).
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
40
+
41
+ ## Code of Conduct
42
+
43
+ Everyone interacting in the Workflower project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/workflower/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require "rubocop/rake_task"
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[spec rubocop]
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 "workflower"
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
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,112 @@
1
+ require "active_support"
2
+
3
+ module Workflower
4
+ mattr_accessor :workflower_state_column_name, :default_workflow_id
5
+ module ActsAsWorkflower
6
+ extend ActiveSupport::Concern
7
+
8
+ module InstanceMethods
9
+ # mattr_accessor :workflower_base
10
+ attr_accessor :possible_events, :allowed_events, :allowed_transitions, :workflow_transition_event_name, :workflow_transition_flow
11
+
12
+ def set_initial_state
13
+ write_attribute self.class.workflower_state_column_name, workflower_initial_state
14
+ end
15
+
16
+ def workflower_initial_state
17
+ workflower_base.set_initial_state
18
+ end
19
+
20
+ def workflower_base
21
+ @workflower_base
22
+ end
23
+
24
+ def source_workflow
25
+ @source_workflow_instance ||= source.new(self)
26
+ @source_workflow_instance.get_workflows_for_workflow_id(workflow_id)
27
+ end
28
+
29
+ def workflower_initializer
30
+ @source_workflow_instance ||= source.new(self)
31
+
32
+ @workflower_base ||= Workflower::Manager.new(self, @source_workflow_instance)
33
+
34
+ @workflower_base.allowed_transitions.each do |flow|
35
+ define_singleton_method flow.trigger_action_name.to_s do
36
+ @workflow_transition_event_name = flow.event
37
+ @workflow_transition_flow = flow
38
+ @workflower_base.process_transition!(flow)
39
+ end
40
+
41
+ define_singleton_method flow.boolean_action_name.to_s do
42
+ @workflower_base.transition_possible?(flow)
43
+ end
44
+ end
45
+
46
+ @possible_events ||= @workflower_base.events
47
+ @allowed_events ||= @workflower_base.allowed_events
48
+ @allowed_transitions ||= @workflower_base.allowed_transitions
49
+ end
50
+
51
+ def workflower_uninitializer(reset_source_workflow_instance: false)
52
+ @workflower_base.uninitialize
53
+ @workflower_base = nil
54
+
55
+ @source_workflow_instance = nil if reset_source_workflow_instance
56
+ @possible_events = nil
57
+ @allowed_events = nil
58
+ @allowed_transitions = nil
59
+ end
60
+
61
+ def initialize(*)
62
+ super
63
+ write_attribute :workflow_id, default_workflow_id if workflow_id.blank?
64
+
65
+ workflower_initializer
66
+ end
67
+ end
68
+
69
+ module ClassMethods
70
+ def workflower(default_workflow_id:, source:, workflower_state_column_name: "workflow_state", skip_setting_initial_state: false)
71
+ raise Workflower::WorkflowerError, "Options can't be blank" if source.blank? || default_workflow_id.blank?
72
+
73
+ cattr_accessor :source, default: source
74
+ cattr_accessor :workflower_state_column_name, default: workflower_state_column_name
75
+ cattr_accessor :default_workflow_id, default: default_workflow_id
76
+
77
+ self.workflower_state_column_name = workflower_state_column_name
78
+ self.source = source
79
+ self.default_workflow_id = default_workflow_id
80
+
81
+ # self.validates "#{workflow_model.tableize.singularize}_id", presence: true
82
+ before_create :set_initial_state unless skip_setting_initial_state
83
+ end
84
+
85
+ def workflower_abilities(workflow_selector: nil)
86
+ # workflow_selector helps dynamic transition selection when we have multiple workflows that needs to change depending on the workflow_selector.
87
+ load = source.new(new).get_workflows.values.flatten.uniq unless workflow_selector.present?
88
+ load = source.new(workflow_selector.to_sym).get_workflows.values.flatten.uniq if workflow_selector.present?
89
+
90
+ unless load.blank?
91
+ # transitions = load.transitions.where("(metadata->>'roles') IS NOT NULL")
92
+ transitions = load.select { |item| item.try(:[], :metadata).try(:key?, :roles) }
93
+
94
+ roles = transitions.map { |item| item[:metadata][:roles] }.flatten.uniq
95
+
96
+ roles_hash = {}
97
+
98
+ roles.each do |role|
99
+ roles_hash[role] = transitions.select { |trans| trans[:metadata][:roles].to_a.include?(role) }.map { |item| item[:event] }.uniq
100
+ end
101
+
102
+ roles_hash
103
+ end
104
+ end
105
+ end
106
+
107
+ def self.included(base)
108
+ base.send :include, InstanceMethods
109
+ base.extend(ClassMethods)
110
+ end
111
+ end
112
+ end
@@ -0,0 +1,18 @@
1
+ module Workflower
2
+ class Error < StandardError; end
3
+
4
+ class TransitionHalted < Error
5
+ attr_reader :halted_because
6
+
7
+ def initialize(msg = nil)
8
+ @halted_because = msg
9
+ super msg
10
+ end
11
+ end
12
+
13
+ class NoTransitionAllowed < Error; end
14
+
15
+ class WorkflowerError < Error; end
16
+
17
+ class WorkflowDefinitionError < Error; end
18
+ end
@@ -0,0 +1,72 @@
1
+ module Workflower
2
+ class Flow
3
+ attr_accessor :state, :transition_into, :trigger_action_name, :boolean_action_name, :sequence,
4
+ :downgrade_sequence, :event, :condition, :condition_type, :before_transit, :after_transit, :metadata, :workflow_id, :deviation_id
5
+
6
+ # rubocop:disable Metrics/AbcSize
7
+ def initialize(options)
8
+ @state = options[:state]
9
+ @transition_into = options[:transition_into]
10
+ @event = options[:event]
11
+ @condition = options[:condition] if options[:condition]
12
+ @condition_type = options[:condition_type] if options[:condition_type]
13
+ @before_transition = options[:before_transition] if options[:before_transition]
14
+ @after_transition = options[:after_transition] if options[:after_transition]
15
+ @sequence = options[:sequence]
16
+ @downgrade_sequence = options[:downgrade_sequence] || -1
17
+ @workflow_id = options[:workflow_id]
18
+ @metadata = options[:metadata]
19
+ @deviation_id = options[:deviation_id] || @workflow_id
20
+ @trigger_action_name = "#{event}!"
21
+ @boolean_action_name = "can_#{event}?"
22
+ end
23
+
24
+ def before_transition_proc_name
25
+ @before_transition.blank? ? "before_workflow_#{event}".to_sym : @before_transition.to_sym
26
+ end
27
+
28
+ def call_before_transition(calling_model)
29
+ calling_model.send(before_transition_proc_name) if calling_model.respond_to? before_transition_proc_name
30
+ end
31
+
32
+ def after_transition_proc_name
33
+ @after_transition.blank? ? "after_workflow_#{event}".to_sym : @after_transition.to_sym
34
+ end
35
+
36
+ def call_after_transition(calling_model)
37
+ calling_model.send(after_transition_proc_name) if calling_model.respond_to? after_transition_proc_name
38
+ end
39
+
40
+ def condition_proc_name
41
+ @condition || nil
42
+ end
43
+
44
+ def condition_is_met?(calling_model)
45
+ if @condition_type == "expression"
46
+
47
+ evaluation_phrase = @condition.split(" ").map do |item|
48
+ if ["||", "&&", "(", ")", "=="].include?(item)
49
+ item
50
+ else
51
+ "calling_model.#{item}"
52
+ end
53
+ end
54
+
55
+ return eval(evaluation_phrase.join(" "))
56
+ end
57
+
58
+ if !condition_proc_name.blank? && calling_model.respond_to?(condition_proc_name)
59
+ return calling_model.send(condition_proc_name)
60
+ end
61
+
62
+ true
63
+ end
64
+
65
+ def updateable_attributes(calling_model)
66
+ attributes = { calling_model.workflower_state_column_name => @transition_into }
67
+ attributes[:sequence] = @downgrade_sequence.negative? ? @sequence : @downgrade_sequence
68
+
69
+ attributes
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,78 @@
1
+ require "workflower/errors"
2
+ require "workflower/flow"
3
+ module Workflower
4
+ class Manager
5
+ attr_reader :events, :flows_container, :allowed_events
6
+
7
+ def initialize(calling_model, source)
8
+ @transitions = source.get_workflows[calling_model.workflow_id.to_s.to_sym]
9
+ @current_state = calling_model.send(calling_model.workflower_state_column_name)
10
+ @current_sequence = calling_model.send(:sequence)
11
+ @calling_model = calling_model
12
+ @source = source
13
+
14
+ # Flows
15
+ @flows_container = buildup_flows
16
+ @events = @flows_container.map(&:event)
17
+ @allowed_events = allowed_transitions.map(&:event)
18
+ @validation_errors = []
19
+ end
20
+
21
+ def uninitialize
22
+ @transitions = []
23
+ @current_state = []
24
+ @current_sequence = []
25
+ @calling_model = []
26
+ @source = []
27
+
28
+ # Flows
29
+ @flows_container = []
30
+ @events = []
31
+ @allowed_events = []
32
+ @validation_errors = []
33
+ end
34
+
35
+ def buildup_flows
36
+ possible_transitions.map { |transition| Workflower::Flow.new(transition) }
37
+ end
38
+
39
+ def possible_transitions
40
+ # @transitions.where(state: @current_state).where("sequence = :seq OR sequence = :seq_plus", seq: @current_sequence, seq_plus: @current_sequence + 1).order("sequence ASC") || []
41
+ @transitions.select do |item|
42
+ item[:state] == @current_state && (item[:sequence] == @current_sequence || item[:sequence] == @current_sequence + 1)
43
+ end
44
+ .sort_by do |item|
45
+ item[:sequence]
46
+ end
47
+ end
48
+
49
+ def allowed_transitions
50
+ buildup_flows.select { |flow| transition_possible?(flow) }
51
+ end
52
+
53
+ def set_initial_state
54
+ "saved"
55
+ end
56
+
57
+ def process_transition!(flow)
58
+ if flow.condition_is_met?(@calling_model)
59
+ begin
60
+ flow.call_before_transition(@calling_model)
61
+ @calling_model.assign_attributes flow.updateable_attributes(@calling_model)
62
+ flow.call_after_transition(@calling_model)
63
+ true
64
+ rescue Exception
65
+ @calling_model.errors.add(@calling_model.workflower_state_column_name, :transition_faild)
66
+ false
67
+ end
68
+ else
69
+ @calling_model.errors.add(@calling_model.workflower_state_column_name,
70
+ :precondition_not_met_to_process_transition)
71
+ end
72
+ end
73
+
74
+ def transition_possible?(flow)
75
+ @calling_model.send(@calling_model.workflower_state_column_name) != flow.transition_into && flow.condition_is_met?(@calling_model)
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Workflower
4
+ VERSION = "0.2.5"
5
+ end
data/lib/workflower.rb ADDED
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "workflower/version"
4
+ require "workflower/manager"
5
+ require "workflower/acts_as_workflower"
6
+ module Workflower
7
+ class Error < StandardError; end
8
+ # Your code goes here...
9
+ end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/workflower/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "workflower"
7
+ spec.version = Workflower::VERSION
8
+ spec.authors = ["Brusk Awat"]
9
+ spec.email = ["broosk.edogawa@gmail.com"]
10
+
11
+ spec.summary = "A state-machine library that handles state management"
12
+ spec.description = "Using a finite state machine algorith, this gem allows to handle state of an entity with ease."
13
+ spec.homepage = "https://github.com/ditkrg/workflower"
14
+ spec.license = "MIT"
15
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.5.0")
16
+
17
+ spec.metadata['allowed_push_host'] = 'https://rubygems.org'
18
+
19
+ spec.metadata["homepage_uri"] = spec.homepage
20
+ spec.metadata["source_code_uri"] = "https://github.com/broosk1993/workflower"
21
+ spec.metadata["changelog_uri"] = "https://github.com/broosk1993/workflower/blob/main/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.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 "activesupport", ">= 6.0.0"
34
+ # spec.add_development_dependency "active_support", ">= 6.0.0"
35
+ spec.add_development_dependency "byebug"
36
+
37
+ # For more information and examples about making a new gem, checkout our
38
+ # guide at: https://bundler.io/guides/creating_gem.html
39
+ end
metadata ADDED
@@ -0,0 +1,95 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: workflower
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.5
5
+ platform: ruby
6
+ authors:
7
+ - Brusk Awat
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2023-04-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 6.0.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 6.0.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: byebug
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: Using a finite state machine algorith, this gem allows to handle state
42
+ of an entity with ease.
43
+ email:
44
+ - broosk.edogawa@gmail.com
45
+ executables: []
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - ".gitignore"
50
+ - ".rspec"
51
+ - ".rubocop.yml"
52
+ - ".ruby-version"
53
+ - CODE_OF_CONDUCT.md
54
+ - Gemfile
55
+ - Gemfile.lock
56
+ - LICENSE.txt
57
+ - README.md
58
+ - Rakefile
59
+ - bin/console
60
+ - bin/setup
61
+ - lib/workflower.rb
62
+ - lib/workflower/acts_as_workflower.rb
63
+ - lib/workflower/errors.rb
64
+ - lib/workflower/flow.rb
65
+ - lib/workflower/manager.rb
66
+ - lib/workflower/version.rb
67
+ - workflower.gemspec
68
+ homepage: https://github.com/ditkrg/workflower
69
+ licenses:
70
+ - MIT
71
+ metadata:
72
+ allowed_push_host: https://rubygems.org
73
+ homepage_uri: https://github.com/ditkrg/workflower
74
+ source_code_uri: https://github.com/broosk1993/workflower
75
+ changelog_uri: https://github.com/broosk1993/workflower/blob/main/CHANGELOG.md
76
+ post_install_message:
77
+ rdoc_options: []
78
+ require_paths:
79
+ - lib
80
+ required_ruby_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: 2.5.0
85
+ required_rubygems_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ requirements: []
91
+ rubygems_version: 3.3.7
92
+ signing_key:
93
+ specification_version: 4
94
+ summary: A state-machine library that handles state management
95
+ test_files: []