Class: RailsSpotlight::Middlewares::Handlers::BaseActionHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/rails_spotlight/middlewares/handlers/base_action_handler.rb

Constant Summary collapse

IncorrectResponseContentType =
Class.new(StandardError)
NotFound =
Class.new(StandardError)
UnprocessableEntity =
Class.new(StandardError)
Forbidden =
Class.new(StandardError)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(request_id, request, content_type) ⇒ BaseActionHandler

Returns a new instance of BaseActionHandler.



12
13
14
15
16
# File 'lib/rails_spotlight/middlewares/handlers/base_action_handler.rb', line 12

def initialize(request_id, request, content_type)
  @request_id = request_id
  @request = request
  @content_type = content_type
end

Instance Attribute Details

#content_typeObject (readonly)

Returns the value of attribute content_type.



18
19
20
# File 'lib/rails_spotlight/middlewares/handlers/base_action_handler.rb', line 18

def content_type
  @content_type
end

#requestObject (readonly)

Returns the value of attribute request.



18
19
20
# File 'lib/rails_spotlight/middlewares/handlers/base_action_handler.rb', line 18

def request
  @request
end

#request_idObject (readonly)

Returns the value of attribute request_id.



18
19
20
# File 'lib/rails_spotlight/middlewares/handlers/base_action_handler.rb', line 18

def request_id
  @request_id
end

Instance Method Details

#callObject



20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/rails_spotlight/middlewares/handlers/base_action_handler.rb', line 20

def call
  validate_project! unless skip_project_validation?
  execute
  response
rescue NotFound => e
  not_found_response(e.message)
rescue UnprocessableEntity => e
  unprocessed_response(e.message)
rescue Forbidden => e
  forbidden_response(e.message)
rescue => e # rubocop:disable Style/RescueStandardError
  internal_server_error_response(e.message)
end