Class: LcpRuby::Workflow::TransitionDefinition

Inherits:
Object
  • Object
show all
Defined in:
lib/lcp_ruby/workflow/transition_definition.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attrs = {}) ⇒ TransitionDefinition

Returns a new instance of TransitionDefinition.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/lcp_ruby/workflow/transition_definition.rb', line 9

def initialize(attrs = {})
  @name = attrs[:name].to_s
  @from = Array(attrs[:from]).map(&:to_s)
  @to = attrs[:to].to_s
  @label = attrs[:label]&.to_s
  @icon = attrs[:icon]&.to_s
  @style = attrs[:style]&.to_s
  @roles = Array(attrs[:roles]).map(&:to_s)
  @guard = attrs[:guard]
  @set_fields = attrs[:set_fields] || {}
  @events = Array(attrs[:events]).map(&:to_s)
  @require_comment = attrs[:require_comment] == true
  @confirm = attrs[:confirm]
  @confirm_message = attrs[:confirm_message]&.to_s
  @trigger = (attrs[:trigger] || "user").to_s
  # i18n_check Phase 3a — populated by WorkflowBuilder#transition.
  # `source_loc` points at the transition declaration; `label_source_loc`
  # at the same line (label is captured from the same `transition(...)` call).
  @source_loc = attrs[:source_loc]
  @label_source_loc = attrs[:label_source_loc]
end

Instance Attribute Details

#confirmObject (readonly)

Returns the value of attribute confirm.



4
5
6
# File 'lib/lcp_ruby/workflow/transition_definition.rb', line 4

def confirm
  @confirm
end

#confirm_messageObject (readonly)

Returns the value of attribute confirm_message.



4
5
6
# File 'lib/lcp_ruby/workflow/transition_definition.rb', line 4

def confirm_message
  @confirm_message
end

#eventsObject (readonly)

Returns the value of attribute events.



4
5
6
# File 'lib/lcp_ruby/workflow/transition_definition.rb', line 4

def events
  @events
end

#fromObject (readonly)

Returns the value of attribute from.



4
5
6
# File 'lib/lcp_ruby/workflow/transition_definition.rb', line 4

def from
  @from
end

#guardObject (readonly)

Returns the value of attribute guard.



4
5
6
# File 'lib/lcp_ruby/workflow/transition_definition.rb', line 4

def guard
  @guard
end

#iconObject (readonly)

Returns the value of attribute icon.



4
5
6
# File 'lib/lcp_ruby/workflow/transition_definition.rb', line 4

def icon
  @icon
end

#labelObject (readonly)

Returns the value of attribute label.



4
5
6
# File 'lib/lcp_ruby/workflow/transition_definition.rb', line 4

def label
  @label
end

#label_source_locObject (readonly)

Returns the value of attribute label_source_loc.



4
5
6
# File 'lib/lcp_ruby/workflow/transition_definition.rb', line 4

def label_source_loc
  @label_source_loc
end

#nameObject (readonly)

Returns the value of attribute name.



4
5
6
# File 'lib/lcp_ruby/workflow/transition_definition.rb', line 4

def name
  @name
end

#require_commentObject (readonly)

Returns the value of attribute require_comment.



4
5
6
# File 'lib/lcp_ruby/workflow/transition_definition.rb', line 4

def require_comment
  @require_comment
end

#rolesObject (readonly)

Returns the value of attribute roles.



4
5
6
# File 'lib/lcp_ruby/workflow/transition_definition.rb', line 4

def roles
  @roles
end

#set_fieldsObject (readonly)

Returns the value of attribute set_fields.



4
5
6
# File 'lib/lcp_ruby/workflow/transition_definition.rb', line 4

def set_fields
  @set_fields
end

#source_locObject (readonly)

Returns the value of attribute source_loc.



4
5
6
# File 'lib/lcp_ruby/workflow/transition_definition.rb', line 4

def source_loc
  @source_loc
end

#styleObject (readonly)

Returns the value of attribute style.



4
5
6
# File 'lib/lcp_ruby/workflow/transition_definition.rb', line 4

def style
  @style
end

#toObject (readonly)

Returns the value of attribute to.



4
5
6
# File 'lib/lcp_ruby/workflow/transition_definition.rb', line 4

def to
  @to
end

#triggerObject (readonly)

Returns the value of attribute trigger.



4
5
6
# File 'lib/lcp_ruby/workflow/transition_definition.rb', line 4

def trigger
  @trigger
end

Class Method Details

.from_hash(name, hash) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/lcp_ruby/workflow/transition_definition.rb', line 31

def self.from_hash(name, hash)
  hash = (hash || {}).transform_keys(&:to_s)
  new(
    name: name,
    from: hash["from"],
    to: hash["to"],
    label: hash["label"],
    icon: hash["icon"],
    style: hash["style"],
    roles: hash["roles"],
    guard: hash["guard"],
    set_fields: hash["set_fields"],
    events: hash["events"],
    require_comment: hash["require_comment"],
    confirm: hash["confirm"],
    confirm_message: hash["confirm_message"],
    trigger: hash["trigger"],
    source_loc: hash["_source_loc"],
    label_source_loc: hash["_label_source_loc"]
  )
end

Instance Method Details

#available_from?(state) ⇒ Boolean

Returns:

  • (Boolean)


65
66
67
# File 'lib/lcp_ruby/workflow/transition_definition.rb', line 65

def available_from?(state)
  @from.include?(state.to_s)
end

#programmatic?Boolean

Returns:

  • (Boolean)


61
62
63
# File 'lib/lcp_ruby/workflow/transition_definition.rb', line 61

def programmatic?
  @trigger == "system" || @trigger == "both"
end

#system_only?Boolean

Returns:

  • (Boolean)


57
58
59
# File 'lib/lcp_ruby/workflow/transition_definition.rb', line 57

def system_only?
  @trigger == "system"
end

#user_triggered?Boolean

Returns:

  • (Boolean)


53
54
55
# File 'lib/lcp_ruby/workflow/transition_definition.rb', line 53

def user_triggered?
  @trigger == "user" || @trigger == "both"
end