Class: NYNY::Router

Inherits:
Object
  • Object
show all
Defined in:
lib/nyny/router.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Router

Returns a new instance of Router.



8
9
10
11
12
13
14
15
# File 'lib/nyny/router.rb', line 8

def initialize options
  @scope_class    = options[:scope_class]
  @before_hooks   = options[:before_hooks]
  @after_hooks    = options[:after_hooks]
  @fallback       = options[:fallback]

  prepare_for_journey(options[:route_defs])
end

Instance Attribute Details

#after_hooksObject (readonly)

Returns the value of attribute after_hooks.



7
8
9
# File 'lib/nyny/router.rb', line 7

def after_hooks
  @after_hooks
end

#before_hooksObject (readonly)

Returns the value of attribute before_hooks.



7
8
9
# File 'lib/nyny/router.rb', line 7

def before_hooks
  @before_hooks
end

#fallbackObject (readonly)

Returns the value of attribute fallback.



7
8
9
# File 'lib/nyny/router.rb', line 7

def fallback
  @fallback
end

#journeyObject (readonly)

Returns the value of attribute journey.



7
8
9
# File 'lib/nyny/router.rb', line 7

def journey
  @journey
end

#scope_classObject (readonly)

Returns the value of attribute scope_class.



7
8
9
# File 'lib/nyny/router.rb', line 7

def scope_class
  @scope_class
end

Instance Method Details

#call(env) ⇒ Object



17
18
19
20
21
22
23
24
25
# File 'lib/nyny/router.rb', line 17

def call env
  response = journey.call(env)

  if response[0] == 404 and fallback
    fallback.call(env)
  else
    response
  end
end