Class | Core::Controller |
In: |
core/controller.rb
|
Parent: | Object |
Context is the provided implementation of the Controller interface.
See Interfaces::Controller#initialize
# File core/controller.rb, line 109 def initialize(params) # init the View # verify that the parameter exists and is not nil if ( !params.key?(:view) || params.fetch(:view,nil).nil? ) raise ArgumentError.new('You need to define a :view') end @view = params[:view] # verify the view implements the Core::Interfaces::View interface if (!@view.class.included_modules.include?(Interfaces::View)) raise ArgumentError.new('The :view must implement Core::Interfaces::View') end @view.setup(self) sp_path = params.fetch(:service_providers, './core/serviceproviders' ) init_providers( sp_path ) end
See Interfaces::Controller#exec
# File core/controller.rb, line 128 def exec() # TODO: maybe this can be converted into a request_service(:view_exec) if # the view implemented the ServiceProvider interface. @view.run end
See Interfaces::Controller#request_service
# File core/controller.rb, line 135 def request_service(key, *args) $logger.debug( "Service request: #{key}." ) if !@services.key?(key) signal_event :exception, "The service [:#{key}] is not recognised." $logger.error { "The service [:#{key}] is not recognised." } return false end begin $logger.debug( "Service provider for #{key} is: #{@services[key].class}." ) return @services[key].request_service(key, *args) rescue Errno::ECONNREFUSED signal_event :exception, 'Error while connecting. Is the server running?', $! $logger.error{$!} rescue DradisQuitApp # user requested end of session through 'quit' command # TODO: replace this for an event signal/notify pattern $logger.info{ 'User requested shutdown.' } @view.teardown return '~'*60+"/dradis - #{VERSION::STRING}" rescue # if there is an exception requesting a service, signal it signal_event :exception, "[error] #{$!}", $! $logger.error { $! } $logger.debug {$@.join("\n\t")} end # upon failure, return false return false end