Class: Evertils::Controller::Base
- Inherits:
-
Object
- Object
- Evertils::Controller::Base
- Defined in:
- lib/evertils/controller.rb
Constant Summary collapse
- OK =
Exit code to indicate everything is ok!
0
- QUIT =
Exit code to indicate a force quit (exit) call, meaning the program quit with an error
1
- QUIT_SOFT =
Exit code to indicate that the program exited with a non-zero exit code, but not one that resulted in a force quit
2
Instance Attribute Summary collapse
-
#config ⇒ Object
Access the configuration object instance externally.
-
#request ⇒ Object
Access the request object instance externally.
Instance Method Summary collapse
-
#can_exec?(command, config) ⇒ Boolean
- Determines if the command can execute Params:
command
- Symbol containing the command we want to execute
config
-
Configuration data.
- Symbol containing the command we want to execute
- Determines if the command can execute Params:
-
#exec ⇒ Object
Handle the request.
-
#initialize(config, request) ⇒ Base
constructor
- 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.
- Instance of Evertils::Cfg to enable access to config file
- Setup internal variables that will be used in subclasses Params:
-
#post_exec ⇒ Object
Perform post-run cleanup tasks, such as deleting old logs.
-
#pre_exec ⇒ Object
Perform pre-run tasks.
-
#sample ⇒ Object
Default method called by exec if no argument is passed.
Constructor Details
#initialize(config, request) ⇒ Base
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
25 26 27 28 |
# File 'lib/evertils/controller.rb', line 25 def initialize(config, request) @config = config @request = request end |
Instance Attribute Details
#config ⇒ Object
Access the configuration object instance externally
7 8 9 |
# File 'lib/evertils/controller.rb', line 7 def config @config end |
#request ⇒ Object
Access the request object instance externally
9 10 11 |
# File 'lib/evertils/controller.rb', line 9 def request @request end |
Instance Method Details
#can_exec?(command, config) ⇒ Boolean
Determines if the command can execute Params:
command
-
Symbol containing the command we want to execute
config
-
Configuration data
51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/evertils/controller.rb', line 51 def can_exec?(command, config) # 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 elsif is_a? Evertils::Controller::Render @method = :from_file else raise NoMethodError, "Invalid method: #{command}" end end |
#exec ⇒ Object
Handle the request
35 36 37 38 39 40 41 |
# File 'lib/evertils/controller.rb', line 35 def exec if @request.param.nil? send(@method.to_sym) else send(@method.to_sym, (@request.flags.first || @request.param)) end end |
#post_exec ⇒ Object
Perform post-run cleanup tasks, such as deleting old logs
44 45 |
# File 'lib/evertils/controller.rb', line 44 def post_exec end |
#pre_exec ⇒ Object
Perform pre-run tasks
31 32 |
# File 'lib/evertils/controller.rb', line 31 def pre_exec end |
#sample ⇒ Object
Default method called by exec if no argument is passed
66 67 68 |
# File 'lib/evertils/controller.rb', line 66 def sample Notify.warning("Method not implemented") end |