Class: LcpRuby::Workflow::Approval::ApprovalDefinition
- Inherits:
-
Object
- Object
- LcpRuby::Workflow::Approval::ApprovalDefinition
- Defined in:
- lib/lcp_ruby/workflow/approval/approval_definition.rb
Constant Summary collapse
- VALID_STRATEGIES =
%w[sequential parallel].freeze
- VALID_ON_REJECT =
%w[any all].freeze
- VALID_OUTCOMES =
%w[approved rejected returned].freeze
- VALID_REWORK_RESETS =
%w[all pending_only none].freeze
Instance Attribute Summary collapse
-
#allow_approve_with_comment ⇒ Object
readonly
Returns the value of attribute allow_approve_with_comment.
-
#allow_delegation ⇒ Object
readonly
Returns the value of attribute allow_delegation.
-
#bypass_when ⇒ Object
readonly
Returns the value of attribute bypass_when.
-
#delegation_roles ⇒ Object
readonly
Returns the value of attribute delegation_roles.
-
#max_delegation_depth ⇒ Object
readonly
Returns the value of attribute max_delegation_depth.
-
#on_reject ⇒ Object
readonly
Returns the value of attribute on_reject.
-
#require_reject_comment ⇒ Object
readonly
Returns the value of attribute require_reject_comment.
-
#resolution ⇒ Object
readonly
Returns the value of attribute resolution.
-
#rework_policy ⇒ Object
readonly
Returns the value of attribute rework_policy.
-
#short_circuit ⇒ Object
readonly
Returns the value of attribute short_circuit.
-
#state_name ⇒ Object
readonly
Returns the value of attribute state_name.
-
#steps ⇒ Object
readonly
Returns the value of attribute steps.
-
#strategy ⇒ Object
readonly
Returns the value of attribute strategy.
Class Method Summary collapse
Instance Method Summary collapse
- #bypass? ⇒ Boolean
-
#initialize(attrs = {}) ⇒ ApprovalDefinition
constructor
A new instance of ApprovalDefinition.
- #parallel? ⇒ Boolean
- #resolution_transition(outcome) ⇒ Object
- #rework_reset? ⇒ Boolean
- #rework_reset_all? ⇒ Boolean
- #rework_reset_mode ⇒ Object
- #rework_reset_pending_only? ⇒ Boolean
- #sequential? ⇒ Boolean
Constructor Details
#initialize(attrs = {}) ⇒ ApprovalDefinition
Returns a new instance of ApprovalDefinition.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/lcp_ruby/workflow/approval/approval_definition.rb', line 15 def initialize(attrs = {}) @state_name = attrs[:state_name].to_s @strategy = (attrs[:strategy] || "sequential").to_s @bypass_when = attrs[:bypass_when] @resolution = (attrs[:resolution] || {}).transform_keys(&:to_s) @on_reject = (attrs[:on_reject] || "any").to_s @short_circuit = attrs[:short_circuit] != false @rework_policy = (attrs[:rework_policy] || {}).transform_keys(&:to_s) @steps = attrs[:steps] || [] @allow_delegation = attrs[:allow_delegation] == true @delegation_roles = Array(attrs[:delegation_roles]).map(&:to_s) @max_delegation_depth = (attrs[:max_delegation_depth] || 1).to_i @require_reject_comment = attrs[:require_reject_comment] == true @allow_approve_with_comment = attrs[:allow_approve_with_comment] != false validate! end |
Instance Attribute Details
#allow_approve_with_comment ⇒ Object (readonly)
Returns the value of attribute allow_approve_with_comment.
5 6 7 |
# File 'lib/lcp_ruby/workflow/approval/approval_definition.rb', line 5 def allow_approve_with_comment @allow_approve_with_comment end |
#allow_delegation ⇒ Object (readonly)
Returns the value of attribute allow_delegation.
5 6 7 |
# File 'lib/lcp_ruby/workflow/approval/approval_definition.rb', line 5 def allow_delegation @allow_delegation end |
#bypass_when ⇒ Object (readonly)
Returns the value of attribute bypass_when.
5 6 7 |
# File 'lib/lcp_ruby/workflow/approval/approval_definition.rb', line 5 def bypass_when @bypass_when end |
#delegation_roles ⇒ Object (readonly)
Returns the value of attribute delegation_roles.
5 6 7 |
# File 'lib/lcp_ruby/workflow/approval/approval_definition.rb', line 5 def delegation_roles @delegation_roles end |
#max_delegation_depth ⇒ Object (readonly)
Returns the value of attribute max_delegation_depth.
5 6 7 |
# File 'lib/lcp_ruby/workflow/approval/approval_definition.rb', line 5 def max_delegation_depth @max_delegation_depth end |
#on_reject ⇒ Object (readonly)
Returns the value of attribute on_reject.
5 6 7 |
# File 'lib/lcp_ruby/workflow/approval/approval_definition.rb', line 5 def on_reject @on_reject end |
#require_reject_comment ⇒ Object (readonly)
Returns the value of attribute require_reject_comment.
5 6 7 |
# File 'lib/lcp_ruby/workflow/approval/approval_definition.rb', line 5 def require_reject_comment @require_reject_comment end |
#resolution ⇒ Object (readonly)
Returns the value of attribute resolution.
5 6 7 |
# File 'lib/lcp_ruby/workflow/approval/approval_definition.rb', line 5 def resolution @resolution end |
#rework_policy ⇒ Object (readonly)
Returns the value of attribute rework_policy.
5 6 7 |
# File 'lib/lcp_ruby/workflow/approval/approval_definition.rb', line 5 def rework_policy @rework_policy end |
#short_circuit ⇒ Object (readonly)
Returns the value of attribute short_circuit.
5 6 7 |
# File 'lib/lcp_ruby/workflow/approval/approval_definition.rb', line 5 def short_circuit @short_circuit end |
#state_name ⇒ Object (readonly)
Returns the value of attribute state_name.
5 6 7 |
# File 'lib/lcp_ruby/workflow/approval/approval_definition.rb', line 5 def state_name @state_name end |
#steps ⇒ Object (readonly)
Returns the value of attribute steps.
5 6 7 |
# File 'lib/lcp_ruby/workflow/approval/approval_definition.rb', line 5 def steps @steps end |
#strategy ⇒ Object (readonly)
Returns the value of attribute strategy.
5 6 7 |
# File 'lib/lcp_ruby/workflow/approval/approval_definition.rb', line 5 def strategy @strategy end |
Class Method Details
.from_hash(state_name, hash) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/lcp_ruby/workflow/approval/approval_definition.rb', line 33 def self.from_hash(state_name, hash) hash = (hash || {}).transform_keys(&:to_s) steps = Array(hash["steps"]).map { |s| StepDefinition.from_hash(s) } new( state_name: state_name, strategy: hash["strategy"], bypass_when: hash["bypass_when"], resolution: hash["resolution"], on_reject: hash["on_reject"], short_circuit: hash["short_circuit"], rework_policy: hash["rework_policy"], steps: steps, allow_delegation: hash["allow_delegation"], delegation_roles: hash["delegation_roles"], max_delegation_depth: hash["max_delegation_depth"], require_reject_comment: hash["require_reject_comment"], allow_approve_with_comment: hash["allow_approve_with_comment"] ) end |
Instance Method Details
#bypass? ⇒ Boolean
63 64 65 |
# File 'lib/lcp_ruby/workflow/approval/approval_definition.rb', line 63 def bypass? !@bypass_when.nil? end |
#parallel? ⇒ Boolean
59 60 61 |
# File 'lib/lcp_ruby/workflow/approval/approval_definition.rb', line 59 def parallel? @strategy == "parallel" end |
#resolution_transition(outcome) ⇒ Object
93 94 95 |
# File 'lib/lcp_ruby/workflow/approval/approval_definition.rb', line 93 def resolution_transition(outcome) @resolution[outcome.to_s] end |
#rework_reset? ⇒ Boolean
67 68 69 |
# File 'lib/lcp_ruby/workflow/approval/approval_definition.rb', line 67 def rework_reset? rework_reset_mode != "none" end |
#rework_reset_all? ⇒ Boolean
85 86 87 |
# File 'lib/lcp_ruby/workflow/approval/approval_definition.rb', line 85 def rework_reset_all? rework_reset_mode == "all" end |
#rework_reset_mode ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/lcp_ruby/workflow/approval/approval_definition.rb', line 71 def rework_reset_mode value = @rework_policy["reset"] case value when true, "all" "all" when "pending_only" "pending_only" when false, "none", nil "none" else "all" end end |
#rework_reset_pending_only? ⇒ Boolean
89 90 91 |
# File 'lib/lcp_ruby/workflow/approval/approval_definition.rb', line 89 def rework_reset_pending_only? rework_reset_mode == "pending_only" end |
#sequential? ⇒ Boolean
55 56 57 |
# File 'lib/lcp_ruby/workflow/approval/approval_definition.rb', line 55 def sequential? @strategy == "sequential" end |