Sha256: 12ed132e4b06f062ff92eaffeef1c04e9dc1f40209ca16c2bfb11988811534b7
Contents?: true
Size: 1.98 KB
Versions: 11
Compression:
Stored size: 1.98 KB
Contents
module Evertils module Controller class Base # Access the configuration object instance externally attr_accessor :config # Access the request object instance externally attr_accessor :request # Exit code to indicate everything is ok! OK = 0 # Exit code to indicate a force quit (exit) call, meaning the program # quit with an error QUIT = 1 # Exit code to indicate that the program exited with a non-zero exit code, # but not one that resulted in a force quit QUIT_SOFT = 2 # Setup internal variables that will be used in subclasses # Params: # +config+:: Instance of Evertils::Cfg to enable access to config file # +request+:: Instance of Evertils::Request, enables access to request # parameters def initialize(config, request) @config = config @request = request pre_exec end # Perform pre-run tasks def pre_exec @format = Evertils::Helper.load('Formatting') end # Handle the request def exec if @request.param.nil? send(@method.to_sym) else send(@method.to_sym, @request.flags.first) end end # Perform post-run cleanup tasks, such as deleting old logs def post_exec end # Determines if the command can execute # Params: # +command+:: Symbol containing the command we want to execute def can_exec?(command) # no command was passed, check if controller has a default method if command.nil? && respond_to?(:default) @method = :default elsif respond_to? command # check the controller for the requested method @method = command else raise NoMethodError, "Invalid method: #{command}" end end # Default method called by exec if no argument is passed def sample Notify.warning("Method not implemented") end end end end
Version data entries
11 entries across 11 versions & 1 rubygems