Sha256: 3a63340930a9878c125facfb3c040689db9754188a2d005d45275e8fe09b7f95

Contents?: true

Size: 1.36 KB

Versions: 1

Compression:

Stored size: 1.36 KB

Contents

# frozen_string_literal: true

require_relative '../../rails_command_executor'
module RailsSpotlight
  module Middlewares
    module Handlers
      class ConsoleActionHandler < BaseActionHandler
        def execute
          validate_project!

          RailsSpotlight.config.logger && RailsSpotlight.config.logger.info("Executing command: #{command}") # rubocop:disable Style/SafeNavigation
          executor.execute(command)
        end

        private

        def validate_project!
          return if for_project.blank?
          return if for_project.include?(::RailsSpotlight.config.project_name)

          raise UnprocessableEntity, "Check your connection settings the current command is not allowed to be executed on the #{::RailsSpotlight.config.project_name} project"
        end

        def executor
          @executor ||= ::RailsSpotlight::RailsCommandExecutor.new
        end

        def inspect_types
          @inspect_types ||= json_request_body.fetch('inspect_types')
        end

        def command
          @command ||= json_request_body.fetch('command')
        end

        def for_project
          @for_project ||= json_request_body['project']
        end

        def json_response_body
          executor.result_as_json(inspect_types: inspect_types)
                  .merge(project: ::RailsSpotlight.config.project_name)
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rails_spotlight-0.2.2 lib/rails_spotlight/middlewares/handlers/console_action_handler.rb