Sha256: a53a07df146775c9c5ceb142330114bf23e6c63a925dc5a313a5f98b7fc4b235
Contents?: true
Size: 1.59 KB
Versions: 21
Compression:
Stored size: 1.59 KB
Contents
module Evertils class Router # Create the router object # Params: # +config_instance+:: An instance of Evertils::Cfg def initialize(config_instance) @config = config_instance end # Prepare for routing 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 # Perform command routing 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 end end
Version data entries
21 entries across 21 versions & 1 rubygems