Class: Walle::Robot::Router::Route

Inherits:
Object
  • Object
show all
Defined in:
lib/walle/robot/router/route.rb

Defined Under Namespace

Classes: Direct, Mutator, Prefix

Constant Summary collapse

MUTATORS =
[Direct, Prefix]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(controller:, regexp: nil, **options) ⇒ Route

Returns a new instance of Route.



51
52
53
54
55
# File 'lib/walle/robot/router/route.rb', line 51

def initialize(controller:, regexp: nil, **options)
  @controller = controller
  @options = options
  @regexp = regexp
end

Instance Attribute Details

#controllerObject (readonly) Also known as: cntrl

Returns the value of attribute controller.



6
7
8
# File 'lib/walle/robot/router/route.rb', line 6

def controller
  @controller
end

#optionsObject (readonly)

Returns the value of attribute options.



6
7
8
# File 'lib/walle/robot/router/route.rb', line 6

def options
  @options
end

#regexpObject (readonly)

Returns the value of attribute regexp.



6
7
8
# File 'lib/walle/robot/router/route.rb', line 6

def regexp
  @regexp
end

Instance Method Details

#call(env) ⇒ Object



62
63
64
65
66
# File 'lib/walle/robot/router/route.rb', line 62

def call(env)
  expr = final_regexp(env)
  env.matches = expr.match(env.data.text) if expr
  cntrl.respond_to?(:call) ? cntrl.call(env) : cntrl.new(env).call
end

#match?(env) ⇒ Boolean

Returns:

  • (Boolean)


57
58
59
60
# File 'lib/walle/robot/router/route.rb', line 57

def match?(env)
  expr = final_regexp(env)
  !!expr.match(env.data.text)
end