Sha256: bbbcefd43f34e99c5b6f8b4591a94706ced4ca67cf8fe1ef9e54b01affadfb64

Contents?: true

Size: 822 Bytes

Versions: 3

Compression:

Stored size: 822 Bytes

Contents

# frozen_string_literal: true

# Scope Rails
module R2OAS
  module TaskLogging
    def task(*args, &block)
      Rake::Task.define_task(*args) do |task|
        if block_given?
          debug_log task, "[#{task.name}] started"
          begin
            block.call(task)
            debug_log task, "[#{task.name}] finished"
          rescue StandardError => e
            debug_log task, "[#{task.name}] failed"
            raise e
          end
        end
      end
    end

    private

    def logger
      R2OAS.logger
    end

    def set_info_level
      R2OAS.logger.level = StdoutLogger::INFO
    end

    def set_debug_level
      R2OAS.logger.level = StdoutLogger::DEBUG
    end

    def debug_log(task, message)
      R2OAS.logger.debug message.to_s unless task.name == 'routes:oas:debug'
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
r2-oas-0.1.3 lib/r2-oas/task_logging.rb
r2-oas-0.1.2 lib/r2-oas/task_logging.rb
r2-oas-0.1.0 lib/r2-oas/task_logging.rb