Class: Evertils::Router
- Inherits:
-
Object
- Object
- Evertils::Router
- Defined in:
- lib/evertils/router.rb
Instance Method Summary collapse
-
#initialize(config_instance) ⇒ Router
constructor
- Create the router object Params:
config_instance
-
An instance of Evertils::Cfg.
- Create the router object Params:
-
#pre_exec ⇒ Object
Prepare for routing.
-
#route ⇒ Object
Perform command routing.
Constructor Details
#initialize(config_instance) ⇒ Router
Create the router object Params:
config_instance
-
An instance of Evertils::Cfg
6 7 8 |
# File 'lib/evertils/router.rb', line 6 def initialize(config_instance) @config = config_instance end |
Instance Method Details
#pre_exec ⇒ Object
Prepare for routing
11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/evertils/router.rb', line 11 def pre_exec @request = Request.new begin # include the controller require "evertils/controllers/#{@request.controller}" # include helpers require "evertils/helpers/#{@request.controller}" if File.exist? "evertils/helpers/#{@request.controller}" rescue LoadError Notify.error("Controller not found: #{@request.controller}") end end |
#route ⇒ Object
Perform command routing
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/evertils/router.rb', line 25 def route pre_exec # Create object context and pass it the required command line arguments begin unless @request.controller.nil? controller = Evertils::Controller.const_get @request.controller.capitalize # create an instance of the requested controller context = controller.new(@config, @request) if context.can_exec? @request.command # Set things up context.pre_exec # Run the requested action context.exec # Run cleanup commands context.post_exec end end rescue NoMethodError => e Notify.error("#{e}\n#{e.backtrace.join("\n")}", show_time: false) rescue RuntimeError => e Notify.error("#{e}\n#{e.backtrace.join("\n")}", show_time: false) rescue NameError => e Notify.error("#{e}\n#{e.backtrace.join("\n")}", show_time: false) end end |