Class: Paradeiser::Router

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRouter

Returns a new instance of Router.



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

def initialize
  @status = 0
end

Instance Attribute Details

#statusObject (readonly)

Returns the value of attribute status.



5
6
7
# File 'lib/paradeiser/router.rb', line 5

def status
  @status
end

Instance Method Details

#dispatch(command) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/paradeiser/router.rb', line 11

def dispatch(command)
  Proc.new do |args, options|
    parts = command.name.split
    resource = parts.shift
    controller_name = "#{resource.pluralize.capitalize}Controller".to_sym

    if Paradeiser.const_defined?(controller_name)
      verb = parts.join
      controller_class = Paradeiser.const_get(controller_name)
    else
      verb = resource
      controller_class = ParadeiserController
    end

    controller = controller_class.new(verb)
    controller.call(args, options)

    @status = controller.exitstatus
  end
end