Class: LcpRuby::Workflow::Approval::ApprovalDefinition

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

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_commentObject (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_delegationObject (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_whenObject (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_rolesObject (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_depthObject (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_rejectObject (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_commentObject (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

#resolutionObject (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_policyObject (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_circuitObject (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_nameObject (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

#stepsObject (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

#strategyObject (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

Returns:

  • (Boolean)


63
64
65
# File 'lib/lcp_ruby/workflow/approval/approval_definition.rb', line 63

def bypass?
  !@bypass_when.nil?
end

#parallel?Boolean

Returns:

  • (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

Returns:

  • (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

Returns:

  • (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_modeObject



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

Returns:

  • (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

Returns:

  • (Boolean)


55
56
57
# File 'lib/lcp_ruby/workflow/approval/approval_definition.rb', line 55

def sequential?
  @strategy == "sequential"
end