Class: LcpRuby::Workflow::TransitionDefinition
- Inherits:
-
Object
- Object
- LcpRuby::Workflow::TransitionDefinition
- Defined in:
- lib/lcp_ruby/workflow/transition_definition.rb
Instance Attribute Summary collapse
-
#confirm ⇒ Object
readonly
Returns the value of attribute confirm.
-
#confirm_message ⇒ Object
readonly
Returns the value of attribute confirm_message.
-
#events ⇒ Object
readonly
Returns the value of attribute events.
-
#from ⇒ Object
readonly
Returns the value of attribute from.
-
#guard ⇒ Object
readonly
Returns the value of attribute guard.
-
#icon ⇒ Object
readonly
Returns the value of attribute icon.
-
#label ⇒ Object
readonly
Returns the value of attribute label.
-
#label_source_loc ⇒ Object
readonly
Returns the value of attribute label_source_loc.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#require_comment ⇒ Object
readonly
Returns the value of attribute require_comment.
-
#roles ⇒ Object
readonly
Returns the value of attribute roles.
-
#set_fields ⇒ Object
readonly
Returns the value of attribute set_fields.
-
#source_loc ⇒ Object
readonly
Returns the value of attribute source_loc.
-
#style ⇒ Object
readonly
Returns the value of attribute style.
-
#to ⇒ Object
readonly
Returns the value of attribute to.
-
#trigger ⇒ Object
readonly
Returns the value of attribute trigger.
Class Method Summary collapse
Instance Method Summary collapse
- #available_from?(state) ⇒ Boolean
-
#initialize(attrs = {}) ⇒ TransitionDefinition
constructor
A new instance of TransitionDefinition.
- #programmatic? ⇒ Boolean
- #system_only? ⇒ Boolean
- #user_triggered? ⇒ Boolean
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
#confirm ⇒ Object (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_message ⇒ Object (readonly)
Returns the value of attribute confirm_message.
4 5 6 |
# File 'lib/lcp_ruby/workflow/transition_definition.rb', line 4 def @confirm_message end |
#events ⇒ Object (readonly)
Returns the value of attribute events.
4 5 6 |
# File 'lib/lcp_ruby/workflow/transition_definition.rb', line 4 def events @events end |
#from ⇒ Object (readonly)
Returns the value of attribute from.
4 5 6 |
# File 'lib/lcp_ruby/workflow/transition_definition.rb', line 4 def from @from end |
#guard ⇒ Object (readonly)
Returns the value of attribute guard.
4 5 6 |
# File 'lib/lcp_ruby/workflow/transition_definition.rb', line 4 def guard @guard end |
#icon ⇒ Object (readonly)
Returns the value of attribute icon.
4 5 6 |
# File 'lib/lcp_ruby/workflow/transition_definition.rb', line 4 def icon @icon end |
#label ⇒ Object (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_loc ⇒ Object (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 |
#name ⇒ Object (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_comment ⇒ Object (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 |
#roles ⇒ Object (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_fields ⇒ Object (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_loc ⇒ Object (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 |
#style ⇒ Object (readonly)
Returns the value of attribute style.
4 5 6 |
# File 'lib/lcp_ruby/workflow/transition_definition.rb', line 4 def style @style end |
#to ⇒ Object (readonly)
Returns the value of attribute to.
4 5 6 |
# File 'lib/lcp_ruby/workflow/transition_definition.rb', line 4 def to @to end |
#trigger ⇒ Object (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
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
61 62 63 |
# File 'lib/lcp_ruby/workflow/transition_definition.rb', line 61 def programmatic? @trigger == "system" || @trigger == "both" end |
#system_only? ⇒ Boolean
57 58 59 |
# File 'lib/lcp_ruby/workflow/transition_definition.rb', line 57 def system_only? @trigger == "system" end |
#user_triggered? ⇒ Boolean
53 54 55 |
# File 'lib/lcp_ruby/workflow/transition_definition.rb', line 53 def user_triggered? @trigger == "user" || @trigger == "both" end |