Sha256: ef9154fbc7a4c91999fafbab50ea5263c9a61df47f335e5dd516dff7f2146509
Contents?: true
Size: 994 Bytes
Versions: 2
Compression:
Stored size: 994 Bytes
Contents
# frozen_string_literal: true module RailsSpotlight module Middlewares module Handlers class FileActionHandler < BaseActionHandler def execute raise NotFound, 'File not found' unless path_valid? File.write(file_path, json_request_body.fetch('content')) if write_mode? rescue => e # rubocop:disable Style/RescueStandardError raise UnprocessableEntity, e.message end private def text_response_body File.read(file_path) end def json_response_body { source: text_response_body } end def write_mode? request_mode == 'write' end def request_mode @request_mode ||= json_request_body.fetch('mode', 'read') end def path_valid? File.exist?(file_path) end def file_path @file_path ||= Rails.root.join(json_request_body.fetch('file')) end end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
rails_spotlight-0.1.5 | lib/rails_spotlight/middlewares/handlers/file_action_handler.rb |
rails_spotlight-0.1.4 | lib/rails_spotlight/middlewares/handlers/file_action_handler.rb |