Module: MailGrabber::Web::ApplicationRouter

Included in:
Application
Defined in:
lib/mail_grabber/web/application_router.rb

Defined Under Namespace

Classes: Route

Constant Summary collapse

NAMED_SEGMENTS_PATTERN =
%r{/([^/]*):([^.:$/]+)}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#routesObject (readonly)

Returns the value of attribute routes.



8
9
10
# File 'lib/mail_grabber/web/application_router.rb', line 8

def routes
  @routes
end

Instance Method Details

#route(method, pattern, &block) ⇒ Object

Store routes with the request method, the provided pattern and the given block.

Parameters:

  • method (String)

    e.g. GET, POST etc.

  • pattern (String)

    the path what we are looking for

  • block (Proc)

    what we will run



62
63
64
65
66
67
# File 'lib/mail_grabber/web/application_router.rb', line 62

def route(method, pattern, &block)
  @routes ||= {}

  set_route('HEAD', pattern, &block) if method == 'GET'
  set_route(method, pattern, &block)
end

#set_route(method, pattern, &block) ⇒ Object

Set routes Hash with the Route object.

Parameters:

  • method (String)

    e.g. GET, POST etc.

  • pattern (String)

    the path what we are looking for

  • block (Proc)

    what we will run



74
75
76
# File 'lib/mail_grabber/web/application_router.rb', line 74

def set_route(method, pattern, &block)
  (@routes[method] ||= []) << Route.new(pattern, block)
end