mirror of
https://github.com/ditkrg/workflower-1.git
synced 2026-01-22 22:06:48 +00:00
Formats code
This commit is contained in:
parent
09b3d2a616
commit
9b435cd079
@ -1,4 +1,31 @@
|
|||||||
c
|
c
|
||||||
|
nil.blank?
|
||||||
|
q
|
||||||
|
options&.[](:conditions).empty?
|
||||||
|
options&.[](:conditions).blank?
|
||||||
|
options&.[](:conditions)
|
||||||
|
options&.[](:conditions).nil?
|
||||||
|
c
|
||||||
|
options[:source].nil?
|
||||||
|
options[:source]
|
||||||
|
options
|
||||||
|
options[:source]
|
||||||
|
options[:source].methods
|
||||||
|
options[:source].blank?
|
||||||
|
options[:source].empty?
|
||||||
|
options[:source]
|
||||||
|
q
|
||||||
|
options.empty?
|
||||||
|
options.methods
|
||||||
|
options.to_h.blank?
|
||||||
|
options.to_h
|
||||||
|
options.methods
|
||||||
|
options
|
||||||
|
{}.blank?
|
||||||
|
options.present?
|
||||||
|
options.blank?
|
||||||
|
options
|
||||||
|
c
|
||||||
attrs
|
attrs
|
||||||
c
|
c
|
||||||
attrs
|
attrs
|
||||||
|
|||||||
@ -16,7 +16,8 @@ module Workflower
|
|||||||
# InstanceMethods
|
# InstanceMethods
|
||||||
module InstanceMethods
|
module InstanceMethods
|
||||||
# mattr_accessor :workflower_base
|
# mattr_accessor :workflower_base
|
||||||
attr_accessor :possible_events, :allowed_events, :allowed_transitions, :workflow_transition_event_name, :workflow_transition_flow
|
attr_accessor :possible_events, :allowed_events, :allowed_transitions, :workflow_transition_event_name,
|
||||||
|
:workflow_transition_flow
|
||||||
|
|
||||||
def set_intial_state
|
def set_intial_state
|
||||||
write_attribute self.class.workflower_state_column_name, workflower_initial_state
|
write_attribute self.class.workflower_state_column_name, workflower_initial_state
|
||||||
@ -95,7 +96,9 @@ module Workflower
|
|||||||
roles_hash = {}
|
roles_hash = {}
|
||||||
|
|
||||||
roles.each do |role|
|
roles.each do |role|
|
||||||
roles_hash[role] = transitions.select { |trans| trans[:metadata][:roles].to_a.include?(role) }.map { |item| item[:event] }.uniq
|
roles_hash[role] = transitions.select do |trans|
|
||||||
|
trans[:metadata][:roles].to_a.include?(role)
|
||||||
|
end.map { |item| item[:event] }.uniq
|
||||||
end
|
end
|
||||||
|
|
||||||
roles_hash
|
roles_hash
|
||||||
|
|||||||
@ -1,20 +1,18 @@
|
|||||||
module Workflower
|
module Workflower
|
||||||
class Error < StandardError; end
|
class Error < StandardError; end
|
||||||
|
|
||||||
class TransitionHalted < Error
|
class TransitionHalted < Error
|
||||||
|
attr_reader :halted_because
|
||||||
attr_reader :halted_because
|
|
||||||
|
def initialize(msg = nil)
|
||||||
def initialize(msg = nil)
|
@halted_because = msg
|
||||||
@halted_because = msg
|
super msg
|
||||||
super msg
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
end
|
||||||
class NoTransitionAllowed < Error; end
|
|
||||||
|
class NoTransitionAllowed < Error; end
|
||||||
class WorkflowerError < Error; end
|
|
||||||
|
class WorkflowerError < Error; end
|
||||||
class WorkflowDefinitionError < Error; end
|
|
||||||
end
|
class WorkflowDefinitionError < Error; end
|
||||||
|
end
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
module Workflower
|
module Workflower
|
||||||
class Flow
|
class Flow
|
||||||
attr_accessor :state, :transition_into, :trigger_action_name, :boolean_action_name, :sequence, :downgrade_sequence, :event, :condition, :condition_type, :before_transit, :after_transit, :metadata, :workflow_id, :deviation_id
|
attr_accessor :state, :transition_into, :trigger_action_name, :boolean_action_name, :sequence,
|
||||||
|
:downgrade_sequence, :event, :condition, :condition_type, :before_transit, :after_transit, :metadata, :workflow_id, :deviation_id
|
||||||
|
|
||||||
# rubocop:disable Metrics/AbcSize
|
# rubocop:disable Metrics/AbcSize
|
||||||
def initialize(options)
|
def initialize(options)
|
||||||
@ -21,7 +22,7 @@ module Workflower
|
|||||||
end
|
end
|
||||||
|
|
||||||
def before_transition_proc_name
|
def before_transition_proc_name
|
||||||
!@before_transition.blank? ? @before_transition.to_sym : "before_workflow_#{event}".to_sym
|
@before_transition.blank? ? "before_workflow_#{event}".to_sym : @before_transition.to_sym
|
||||||
end
|
end
|
||||||
|
|
||||||
def call_before_transition(calling_model)
|
def call_before_transition(calling_model)
|
||||||
@ -29,7 +30,7 @@ module Workflower
|
|||||||
end
|
end
|
||||||
|
|
||||||
def after_transition_proc_name
|
def after_transition_proc_name
|
||||||
!@after_transition.blank? ? @after_transition.to_sym : "after_workflow_#{event}".to_sym
|
@after_transition.blank? ? "after_workflow_#{event}".to_sym : @after_transition.to_sym
|
||||||
end
|
end
|
||||||
|
|
||||||
def call_after_transition(calling_model)
|
def call_after_transition(calling_model)
|
||||||
@ -44,10 +45,10 @@ module Workflower
|
|||||||
if @condition_type == "expression"
|
if @condition_type == "expression"
|
||||||
|
|
||||||
evaluation_phrase = @condition.split(" ").map do |item|
|
evaluation_phrase = @condition.split(" ").map do |item|
|
||||||
if !["||", "&&", "(", ")"].include?(item)
|
if ["||", "&&", "(", ")"].include?(item)
|
||||||
"calling_model.#{item}"
|
|
||||||
else
|
|
||||||
item
|
item
|
||||||
|
else
|
||||||
|
"calling_model.#{item}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -62,7 +63,7 @@ module Workflower
|
|||||||
end
|
end
|
||||||
|
|
||||||
def updateable_attributes(calling_model)
|
def updateable_attributes(calling_model)
|
||||||
attributes = Hash[calling_model.workflower_state_column_name, @transition_into]
|
attributes = { calling_model.workflower_state_column_name => @transition_into }
|
||||||
attributes[:sequence] = @downgrade_sequence.negative? ? @sequence : @downgrade_sequence
|
attributes[:sequence] = @downgrade_sequence.negative? ? @sequence : @downgrade_sequence
|
||||||
|
|
||||||
attributes
|
attributes
|
||||||
|
|||||||
@ -53,7 +53,8 @@ module Workflower
|
|||||||
false
|
false
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
@calling_model.errors.add(@calling_model.workflower_state_column_name, :precondition_not_met_to_process_transition)
|
@calling_model.errors.add(@calling_model.workflower_state_column_name,
|
||||||
|
:precondition_not_met_to_process_transition)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
module Workflower
|
module Workflower
|
||||||
VERSION = "0.1.0"
|
VERSION = "0.1.1"
|
||||||
end
|
end
|
||||||
|
|||||||
@ -15,8 +15,7 @@ class DummyFeature
|
|||||||
@sequence = 1
|
@sequence = 1
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.before_create(method_name)
|
def self.before_create(method_name); end
|
||||||
end
|
|
||||||
|
|
||||||
def assign_attributes(attrs)
|
def assign_attributes(attrs)
|
||||||
@workflow_state = attrs["workflow_state"]
|
@workflow_state = attrs["workflow_state"]
|
||||||
@ -25,5 +24,5 @@ class DummyFeature
|
|||||||
|
|
||||||
workflower source: WorkflowSource.new,
|
workflower source: WorkflowSource.new,
|
||||||
workflower_state_column_name: "workflow_state",
|
workflower_state_column_name: "workflow_state",
|
||||||
conditions: { name: "Test Workflow", workflow_model_name: "DummyEntity" }
|
conditions: { workflow_model_name: "DummyEntity" }
|
||||||
end
|
end
|
||||||
|
|||||||
@ -7,7 +7,7 @@ RSpec.describe Workflower do
|
|||||||
expect(Workflower::VERSION).not_to be nil
|
expect(Workflower::VERSION).not_to be nil
|
||||||
end
|
end
|
||||||
|
|
||||||
it "transitions from saved to submitted" do
|
it "transitions from saved to submitted" do
|
||||||
@test = DummyFeature.new
|
@test = DummyFeature.new
|
||||||
@test.workflower_initializer
|
@test.workflower_initializer
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user