class Woah::Route

A Woah! routes

Attributes

match[RW]

Public Class Methods

new(path, method, &action) click to toggle source
# File lib/woah/route.rb, line 8
def initialize(path, method, &action)
  unless [String, Regexp].include? path.class
    raise ArgumentError, 'only strings and regexps are valid paths'
  end

  @path = path
  @method = method
  @action = action
  @match = nil
end

Public Instance Methods

execute() click to toggle source

Execute this route's actions. @return [Hash] the route's response

# File lib/woah/route.rb, line 35
def execute
  status = 200
  headers = { 'Content-Type' => 'text/html; charset=utf-8' }
  body = @action.call
  { status: status, headers: headers, body: body }
end
matches?(method, path) click to toggle source

Checks if a given route is the same as this one @param path [String, Regexp] the path to redirect to @param method [String] the HTTP method to use @return [Boolean] true if given method and path match this route

# File lib/woah/route.rb, line 23
def matches?(method, path)
  case @path
  when String
    @method == method && @path == path
  when Regexp
    @match = @path.match path
    @method == method && @match
  end
end