Sha256: 21dee9e01c5ae65f67a256a8896f29621f0b1e955f536b795463040fc754051a

Contents?: true

Size: 1.36 KB

Versions: 3

Compression:

Stored size: 1.36 KB

Contents

module Phare
  class Check
    attr_reader :status, :command, :tree

    def initialize(_directory, options = {})
      @tree = Git.new(@extensions, options)
    end

    def run
      if should_run?
        print_banner
        Phare.system(command)
        @status = Phare.last_exit_status

        if @status == 0
          print_success_message
        else
          print_error_message
        end

        Phare.puts ''
      else
        @status = 0
      end
    end

    def should_run?
      should_run = binary_exists?

      [:configuration_exists?, :arguments_exists?].each do |condition|
        should_run &&= send(condition) if respond_to?(condition, true)
      end

      if @options[:diff]
        # NOTE: If the tree hasn't changed or if there is no files
        #       to check (e.g. they are all in the exclude list),
        #       we skip the check.
        should_run &&= @tree.changed? && files_to_check.any?
      end

      should_run
    end

  protected

    def excluded_files
      @excluded_files ||= [Dir.glob(excluded_list || [])].flatten
    end

    def files_to_check
      @files_to_check ||= @tree.changes - excluded_files
    end

    def print_success_message
      Phare.puts('Everything looks good from here!')
    end

    def print_error_message
      Phare.puts("Something went wrong. Program exited with #{@status}.")
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
phare-1.0.0 lib/phare/check.rb
phare-0.7.1 lib/phare/check.rb
phare-0.7 lib/phare/check.rb