Class: Alx::Controller

Inherits:
Object
  • Object
show all
Defined in:
lib/alx/controller.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(configuration) ⇒ Controller

Returns a new instance of Controller.



12
13
14
15
16
# File 'lib/alx/controller.rb', line 12

def initialize( configuration )
  @conf = configuration
  @handlers = {}
  register_handlers
end

Instance Attribute Details

#handlersObject (readonly)

Returns the value of attribute handlers.



10
11
12
# File 'lib/alx/controller.rb', line 10

def handlers
  @handlers
end

Instance Method Details

#runObject



18
19
20
21
22
23
24
25
26
# File 'lib/alx/controller.rb', line 18

def run
  command = @conf[ :command ]
  if @handlers[ command ]
    @handlers[ command ].handle
  else
    @handlers[ 'help' ].handle
    raise "I don't understand command: #{command}"
  end
end