Class: Alx::Controller
- Inherits:
-
Object
- Object
- Alx::Controller
- Defined in:
- lib/alx/controller.rb
Instance Attribute Summary collapse
-
#handlers ⇒ Object
readonly
Returns the value of attribute handlers.
Instance Method Summary collapse
-
#initialize(configuration) ⇒ Controller
constructor
A new instance of Controller.
- #run ⇒ Object
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
#handlers ⇒ Object (readonly)
Returns the value of attribute handlers.
10 11 12 |
# File 'lib/alx/controller.rb', line 10 def handlers @handlers end |
Instance Method Details
#run ⇒ Object
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 |