Sha256: 3874c4874177a5fe336c4857f81d436f1faedf5f43802ccff66816a4983da0a1

Contents?: true

Size: 1.26 KB

Versions: 1

Compression:

Stored size: 1.26 KB

Contents

module Phare
  class Check
    attr_reader :status, :command

    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 tree_changed?
      @options[:diff] && tree_changes && tree_changes.any?
    end

    def tree_changes
      @modified_files ||= Phare.system_output('git status -s').split("\n").reduce([]) do |memo, diff|
        filename = diff.split(' ').last

        memo << filename if @extensions.include?(File.extname(filename))
        memo
      end
    end

    def should_run?
      should_run = binary_exists?

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

      if @options[:diff]
        should_run = should_run && tree_changed?
      end

      should_run
    end

  protected

    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

1 entries across 1 versions & 1 rubygems

Version Path
phare-0.5 lib/phare/check.rb