Class: Phare::Check

Inherits:
Object
  • Object
show all
Defined in:
lib/phare/check.rb,
lib/phare/check/jscs.rb,
lib/phare/check/jshint.rb,
lib/phare/check/rubocop.rb,
lib/phare/check/scss_lint.rb

Direct Known Subclasses

JSCS, JSHint, Rubocop, ScssLint

Defined Under Namespace

Classes: JSCS, JSHint, Rubocop, ScssLint

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(_directory, options = {}) ⇒ Check

Returns a new instance of Check.



5
6
7
# File 'lib/phare/check.rb', line 5

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

Instance Attribute Details

#commandObject (readonly)

Returns the value of attribute command.



3
4
5
# File 'lib/phare/check.rb', line 3

def command
  @command
end

#statusObject (readonly)

Returns the value of attribute status.



3
4
5
# File 'lib/phare/check.rb', line 3

def status
  @status
end

#treeObject (readonly)

Returns the value of attribute tree.



3
4
5
# File 'lib/phare/check.rb', line 3

def tree
  @tree
end

Instance Method Details

#runObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/phare/check.rb', line 9

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

#should_run?Boolean

Returns:

  • (Boolean)


27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/phare/check.rb', line 27

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