Class: RailsSpotlight::Middlewares::Handlers::FileActionHandler

Inherits:
BaseActionHandler show all
Defined in:
lib/rails_spotlight/middlewares/handlers/file_action_handler.rb

Constant Summary

Constants inherited from BaseActionHandler

BaseActionHandler::BaseError, BaseActionHandler::Forbidden, BaseActionHandler::NotFound, BaseActionHandler::UnprocessableEntity, BaseActionHandler::UnsupportedMediaType

Instance Attribute Summary

Attributes inherited from BaseActionHandler

#content_type, #request, #request_id

Instance Method Summary collapse

Methods inherited from BaseActionHandler

#call, #initialize

Constructor Details

This class inherits a constructor from RailsSpotlight::Middlewares::Handlers::BaseActionHandler

Instance Method Details

#executeObject

Raises:



7
8
9
10
11
12
13
14
15
16
# File 'lib/rails_spotlight/middlewares/handlers/file_action_handler.rb', line 7

def execute
  raise Forbidden.new('File manager is disabled', code: :disabled_file_manager_settings) unless enabled?
  raise NotFound.new('File not found', code: :file_not_found) unless path_valid?

  begin
    write_mode? ? try_to_update_file : File.read(file_path)
  rescue => e # rubocop:disable Style/RescueStandardError
    raise UnprocessableEntity.new(e.message, code: write_mode? ? :file_update_error : :file_read_error)
  end
end