Class: EurekaBot::Controller
- Inherits:
-
Object
- Object
- EurekaBot::Controller
- Extended by:
- ActiveSupport::Autoload
- Includes:
- ActiveSupport::Callbacks, Instrumentation
- Defined in:
- lib/eureka_bot/controller.rb
Defined Under Namespace
Classes: Response, UnknownAction
Instance Attribute Summary collapse
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#message ⇒ Object
readonly
Returns the value of attribute message.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
Class Method Summary collapse
Instance Method Summary collapse
- #answer(**params) ⇒ Object
- #execute(action) ⇒ Object
-
#initialize(params: {}, message: nil, response: nil, logger: EurekaBot.logger) ⇒ Controller
constructor
cattr_accessor :exception_handler.
- #redirect(controller, action) ⇒ Object
- #response_class ⇒ Object
- #trace_error(e, params = {}) ⇒ Object
Methods included from Instrumentation
Constructor Details
#initialize(params: {}, message: nil, response: nil, logger: EurekaBot.logger) ⇒ Controller
cattr_accessor :exception_handler
13 14 15 16 17 18 19 |
# File 'lib/eureka_bot/controller.rb', line 13 def initialize(params: {}, message: nil, response: nil, logger: EurekaBot.logger) @params = params @message = @logger = logger @response = response || response_class.new(logger: logger) @response.controller = self end |
Instance Attribute Details
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
10 11 12 |
# File 'lib/eureka_bot/controller.rb', line 10 def logger @logger end |
#message ⇒ Object (readonly)
Returns the value of attribute message.
10 11 12 |
# File 'lib/eureka_bot/controller.rb', line 10 def @message end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
10 11 12 |
# File 'lib/eureka_bot/controller.rb', line 10 def params @params end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
10 11 12 |
# File 'lib/eureka_bot/controller.rb', line 10 def response @response end |
Class Method Details
.has_action?(action) ⇒ Boolean
62 63 64 65 |
# File 'lib/eureka_bot/controller.rb', line 62 def self.has_action?(action) return false unless action.present? public_instance_methods(false).include?(action.to_sym) end |
Instance Method Details
#answer(**params) ⇒ Object
34 35 36 37 38 39 |
# File 'lib/eureka_bot/controller.rb', line 34 def answer(**params) instrument 'controller.answer', params do response << params nil end end |
#execute(action) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/eureka_bot/controller.rb', line 21 def execute(action) if respond_to?(action, include_all: false) instrument 'controller.execute' do run_callbacks :action do public_send(action) end end else raise UnknownAction.new("Action #{action} is not defined in #{self.class}") end self end |
#redirect(controller, action) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/eureka_bot/controller.rb', line 41 def redirect(controller, action) instance = controller.new( params: params, message: , response: response, logger: logger ) instrument 'controller.redirect', {from: self.class.to_s, to: {controller: controller.to_s, action: action}} do instance.public_send(action) end end |
#response_class ⇒ Object
53 54 55 |
# File 'lib/eureka_bot/controller.rb', line 53 def response_class EurekaBot::Controller::Response end |
#trace_error(e, params = {}) ⇒ Object
57 58 59 60 |
# File 'lib/eureka_bot/controller.rb', line 57 def trace_error(e, params={}) logger.error(e.http_body) if e.respond_to?(:http_body) EurekaBot.exception_handler(e, self.class, params) end |