Sha256: f3d4068c17a447e78746b6cf7ace5188eb318528b2a3d9470fadf6d5e1e23233

Contents?: true

Size: 1.07 KB

Versions: 2

Compression:

Stored size: 1.07 KB

Contents

# coding: utf-8

module Guard
  class Reek
    # This class runs `rubocop` command, retrieves result and notifies.
    # An instance of this class is intended to invoke `rubocop` only once in its lifetime.
    class Runner
      attr_reader :notifier, :ui, :result

      def initialize(options)
        @options = options
        @notifier = options[:notifier] || Notifier
        @ui = options[:ui] || UI
      end

      def run(paths = [])
        paths = [] if paths.include?('.reek')
        ui_message(paths)

        command = ['reek'].concat(paths)
        @result = system(*command)

        notify_about_result
      end

      private

      def ui_message(paths)
        if paths.empty?
          ui.info('Guard::Reek running on all')
        else
          ui.info("Guard::Reek is running on #{paths}")
        end
      end

      def notify_about_result
        if result
          notifier.notify('Reek Results', title: 'Passed', image: :success)
        else
          notifier.notify('Reek Results', title: 'Failed', image: :failed)
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
guard-reek-1.0.2 lib/guard/reek/runner.rb
guard-reek-1.0.1 lib/guard/reek/runner.rb