class Safrano::Transition

represents a state transition when navigating/parsing the url path from left to right

Constants

EMPTYSTR
RESULT_BAD_REQ_ERR
RESULT_END
RESULT_NOT_FOUND_ERR
RESULT_SERVER_TR_ERR
SLASH

Attributes

match_result[RW]
remain_idx[R]
rgx[RW]
trans[RW]

Public Class Methods

new(arg, trans: nil, remain_idx: 2) click to toggle source
# File lib/odata/transition.rb, line 23
def initialize(arg, trans: nil, remain_idx: 2)
  @rgx = if arg.respond_to? :each_char
           Regexp.new(arg)
         else
           arg
         end
  @trans = trans
  @remain_idx = remain_idx
end

Public Instance Methods

do_match(str) click to toggle source
# File lib/odata/transition.rb, line 33
def do_match(str)
  @match_result = @rgx.match(str)
end
do_transition(ctx) click to toggle source
# File lib/odata/transition.rb, line 51
def do_transition(ctx)
  ctx.method(@trans).call(@match_result)
end
path_done() click to toggle source
# File lib/odata/transition.rb, line 43
def path_done
  if @match_result
    @match_result[1] || EMPTYSTR
  else
    EMPTYSTR
  end
end
path_remain() click to toggle source

remain_idx is the index of the last match-data. ususally its 2 but can be overidden

# File lib/odata/transition.rb, line 39
def path_remain
  @match_result[@remain_idx] if @match_result && @match_result[@remain_idx]
end