mirror of
https://github.com/ditkrg/workflower-1.git
synced 2026-01-22 13:56:51 +00:00
Formats code
This commit is contained in:
parent
09b3d2a616
commit
9b435cd079
@ -1,4 +1,31 @@
|
||||
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
|
||||
c
|
||||
attrs
|
||||
|
||||
@ -16,7 +16,8 @@ module Workflower
|
||||
# InstanceMethods
|
||||
module InstanceMethods
|
||||
# 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
|
||||
write_attribute self.class.workflower_state_column_name, workflower_initial_state
|
||||
@ -95,7 +96,9 @@ module Workflower
|
||||
roles_hash = {}
|
||||
|
||||
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
|
||||
|
||||
roles_hash
|
||||
|
||||
@ -1,20 +1,18 @@
|
||||
module Workflower
|
||||
class Error < StandardError; end
|
||||
|
||||
class TransitionHalted < Error
|
||||
|
||||
attr_reader :halted_because
|
||||
|
||||
def initialize(msg = nil)
|
||||
@halted_because = msg
|
||||
super msg
|
||||
end
|
||||
|
||||
class Error < StandardError; end
|
||||
|
||||
class TransitionHalted < Error
|
||||
attr_reader :halted_because
|
||||
|
||||
def initialize(msg = nil)
|
||||
@halted_because = msg
|
||||
super msg
|
||||
end
|
||||
|
||||
class NoTransitionAllowed < Error; end
|
||||
|
||||
class WorkflowerError < Error; end
|
||||
|
||||
class WorkflowDefinitionError < Error; end
|
||||
end
|
||||
end
|
||||
|
||||
class NoTransitionAllowed < Error; end
|
||||
|
||||
class WorkflowerError < Error; end
|
||||
|
||||
class WorkflowDefinitionError < Error; end
|
||||
end
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
module Workflower
|
||||
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
|
||||
def initialize(options)
|
||||
@ -21,7 +22,7 @@ module Workflower
|
||||
end
|
||||
|
||||
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
|
||||
|
||||
def call_before_transition(calling_model)
|
||||
@ -29,7 +30,7 @@ module Workflower
|
||||
end
|
||||
|
||||
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
|
||||
|
||||
def call_after_transition(calling_model)
|
||||
@ -44,10 +45,10 @@ module Workflower
|
||||
if @condition_type == "expression"
|
||||
|
||||
evaluation_phrase = @condition.split(" ").map do |item|
|
||||
if !["||", "&&", "(", ")"].include?(item)
|
||||
"calling_model.#{item}"
|
||||
else
|
||||
if ["||", "&&", "(", ")"].include?(item)
|
||||
item
|
||||
else
|
||||
"calling_model.#{item}"
|
||||
end
|
||||
end
|
||||
|
||||
@ -62,7 +63,7 @@ module Workflower
|
||||
end
|
||||
|
||||
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
|
||||
|
||||
@ -53,7 +53,8 @@ module Workflower
|
||||
false
|
||||
end
|
||||
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
|
||||
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Workflower
|
||||
VERSION = "0.1.0"
|
||||
VERSION = "0.1.1"
|
||||
end
|
||||
|
||||
@ -15,8 +15,7 @@ class DummyFeature
|
||||
@sequence = 1
|
||||
end
|
||||
|
||||
def self.before_create(method_name)
|
||||
end
|
||||
def self.before_create(method_name); end
|
||||
|
||||
def assign_attributes(attrs)
|
||||
@workflow_state = attrs["workflow_state"]
|
||||
@ -25,5 +24,5 @@ class DummyFeature
|
||||
|
||||
workflower source: WorkflowSource.new,
|
||||
workflower_state_column_name: "workflow_state",
|
||||
conditions: { name: "Test Workflow", workflow_model_name: "DummyEntity" }
|
||||
conditions: { workflow_model_name: "DummyEntity" }
|
||||
end
|
||||
|
||||
@ -7,7 +7,7 @@ RSpec.describe Workflower do
|
||||
expect(Workflower::VERSION).not_to be nil
|
||||
end
|
||||
|
||||
it "transitions from saved to submitted" do
|
||||
it "transitions from saved to submitted" do
|
||||
@test = DummyFeature.new
|
||||
@test.workflower_initializer
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user