Formats code

This commit is contained in:
Brusk Hamarash 2021-10-02 04:11:11 +03:00
parent 09b3d2a616
commit 9b435cd079
No known key found for this signature in database
GPG Key ID: 509F705341F6504F
8 changed files with 62 additions and 33 deletions

View File

@ -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

View File

@ -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

View File

@ -2,14 +2,12 @@ module Workflower
class Error < StandardError; end
class TransitionHalted < Error
attr_reader :halted_because
def initialize(msg = nil)
@halted_because = msg
super msg
end
end
class NoTransitionAllowed < Error; end
@ -17,4 +15,4 @@ module Workflower
class WorkflowerError < Error; end
class WorkflowDefinitionError < Error; end
end
end

View File

@ -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

View File

@ -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

View File

@ -1,5 +1,5 @@
# frozen_string_literal: true
module Workflower
VERSION = "0.1.0"
VERSION = "0.1.1"
end

View File

@ -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