Class: Charyf::Engine::Routing::Default

Inherits:
Base show all
Defined in:
lib/charyf/engine/routing/default.rb

Defined Under Namespace

Classes: InvalidRoute

Instance Method Summary collapse

Methods inherited from Base

#invalid, #unknown

Methods included from Strategy::BaseClass

included

Constructor Details

#initializeDefault

Returns a new instance of Default.



12
13
14
15
16
# File 'lib/charyf/engine/routing/default.rb', line 12

def initialize
  @routes = {
      Charyf::Engine::Intent.unknown.name => unknown
  }
end

Instance Method Details

#draw(&block) ⇒ Object



18
19
20
# File 'lib/charyf/engine/routing/default.rb', line 18

def draw(&block)
  instance_eval &block
end

#process(context) ⇒ Object

Context -> Controller



23
24
25
# File 'lib/charyf/engine/routing/default.rb', line 23

def process(context)
  @routes[context.intent.name.downcase] || invalid
end

#route(intent, to: nil) ⇒ Object

Raises:



27
28
29
30
31
# File 'lib/charyf/engine/routing/default.rb', line 27

def route(intent, to: nil)
  raise InvalidRoute.new("route '#{intent}' missing to definition") if to.nil?

  @routes[intent.downcase] = parse_target(to)
end