Class: Ruote::Exp::FlowExpression::HandlerEntry
- Inherits:
-
Object
- Object
- Ruote::Exp::FlowExpression::HandlerEntry
- Defined in:
- lib/ruote/exp/ro_on_x.rb
Overview
Used by on_error when patterns are involved. Gathers much of the pattern logic…
Instance Attribute Summary collapse
-
#action ⇒ Object
readonly
Returns the value of attribute action.
-
#child_id ⇒ Object
readonly
Returns the value of attribute child_id.
-
#pattern ⇒ Object
readonly
Returns the value of attribute pattern.
Instance Method Summary collapse
-
#initialize(on_error_entry) ⇒ HandlerEntry
constructor
A new instance of HandlerEntry.
- #match(regex_or_err) ⇒ Object
- #narrow ⇒ Object
- #split(pat) ⇒ Object
- #update_tree(tree, retries) ⇒ Object
Constructor Details
#initialize(on_error_entry) ⇒ HandlerEntry
Returns a new instance of HandlerEntry.
113 114 115 116 117 118 119 120 121 |
# File 'lib/ruote/exp/ro_on_x.rb', line 113 def initialize(on_error_entry) if on_error_entry.is_a?(Hash) on_error_entry = on_error_entry.to_a.flatten end @pattern, @action, @child_id = on_error_entry @pat = Ruote.regex_or_s(@pattern) || // end |
Instance Attribute Details
#action ⇒ Object (readonly)
Returns the value of attribute action.
111 112 113 |
# File 'lib/ruote/exp/ro_on_x.rb', line 111 def action @action end |
#child_id ⇒ Object (readonly)
Returns the value of attribute child_id.
111 112 113 |
# File 'lib/ruote/exp/ro_on_x.rb', line 111 def child_id @child_id end |
#pattern ⇒ Object (readonly)
Returns the value of attribute pattern.
111 112 113 |
# File 'lib/ruote/exp/ro_on_x.rb', line 111 def pattern @pattern end |
Instance Method Details
#match(regex_or_err) ⇒ Object
128 129 130 131 132 133 134 135 136 |
# File 'lib/ruote/exp/ro_on_x.rb', line 128 def match(regex_or_err) if regex_or_err.is_a?(Regexp) @action.match(regex_or_err) else @pat.match(regex_or_err['message']) || @pat.match(regex_or_err['class']) end end |
#narrow ⇒ Object
138 139 140 141 |
# File 'lib/ruote/exp/ro_on_x.rb', line 138 def narrow @action.is_a?(Array) ? @action : self end |
#split(pat) ⇒ Object
123 124 125 126 |
# File 'lib/ruote/exp/ro_on_x.rb', line 123 def split(pat) @action.split(pat) end |
#update_tree(tree, retries) ⇒ Object
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
# File 'lib/ruote/exp/ro_on_x.rb', line 143 def update_tree(tree, retries) child = tree[2][@child_id] if @pattern if retries.empty? child[1].delete(@pattern) else child[1][@pattern] = retries.join(', ') end else key, _ = child[1].find { |k, v| v.nil? } child[1].delete(key) child[1][retries.join(', ')] = nil if retries.any? end end |