Class: Ruote::Exp::FlowExpression::HandlerEntry

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

Instance Method Summary collapse

Constructor Details

#initialize(on_error_entry) ⇒ HandlerEntry

Returns a new instance of HandlerEntry


117
118
119
120
121
122
123
124
125
# File 'lib/ruote/exp/ro_on_x.rb', line 117

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

#actionObject (readonly)

Returns the value of attribute action


115
116
117
# File 'lib/ruote/exp/ro_on_x.rb', line 115

def action
  @action
end

#child_idObject (readonly)

Returns the value of attribute child_id


115
116
117
# File 'lib/ruote/exp/ro_on_x.rb', line 115

def child_id
  @child_id
end

#patternObject (readonly)

Returns the value of attribute pattern


115
116
117
# File 'lib/ruote/exp/ro_on_x.rb', line 115

def pattern
  @pattern
end

Instance Method Details

#match(regex_or_err) ⇒ Object


132
133
134
135
136
137
138
139
140
# File 'lib/ruote/exp/ro_on_x.rb', line 132

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

#narrowObject


142
143
144
145
# File 'lib/ruote/exp/ro_on_x.rb', line 142

def narrow

  @action.is_a?(Array) ? @action : self
end

#split(pat) ⇒ Object


127
128
129
130
# File 'lib/ruote/exp/ro_on_x.rb', line 127

def split(pat)

  @action.split(pat)
end

#update_tree(tree, retries) ⇒ Object


147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
# File 'lib/ruote/exp/ro_on_x.rb', line 147

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