Class: Guard::Teaspoon

Inherits:
Plugin
  • Object
show all
Defined in:
lib/guard/teaspoon.rb,
lib/guard/teaspoon/runner.rb,
lib/guard/teaspoon/resolver.rb

Defined Under Namespace

Classes: Resolver, Runner

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Teaspoon

Returns a new instance of Teaspoon.



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/guard/teaspoon.rb', line 11

def initialize(options = {})
  super
  @options = {
    focus_on_failed:      false,
    all_after_pass:       true,
    all_on_start:         true,
    keep_failed:          true,
    formatters:           'clean',
    run_all:              {},
    run_on_modifications: {}
  }.merge(options)
end

Instance Attribute Details

#failed_pathsObject

Returns the value of attribute failed_paths.



9
10
11
# File 'lib/guard/teaspoon.rb', line 9

def failed_paths
  @failed_paths
end

#last_failedObject

Returns the value of attribute last_failed.



9
10
11
# File 'lib/guard/teaspoon.rb', line 9

def last_failed
  @last_failed
end

#resolverObject

Returns the value of attribute resolver.



9
10
11
# File 'lib/guard/teaspoon.rb', line 9

def resolver
  @resolver
end

#runnerObject

Returns the value of attribute runner.



9
10
11
# File 'lib/guard/teaspoon.rb', line 9

def runner
  @runner
end

Instance Method Details

#reloadObject



44
45
46
47
# File 'lib/guard/teaspoon.rb', line 44

def reload
  @last_failed = false
  @failed_paths = []
end

#run_allObject



32
33
34
35
36
37
38
39
40
41
42
# File 'lib/guard/teaspoon.rb', line 32

def run_all
  passed = @runner.run_all(@options[:run_all])

  if passed
    reload
    true
  else
    @last_failed = true
    throw :task_has_failed
  end
end

#run_on_modifications(original_paths) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/guard/teaspoon.rb', line 49

def run_on_modifications(original_paths)
  @resolver.resolve(original_paths)

  failed = false
  @resolver.suites.each do |suite, files|
    failed = true unless @runner.run(files, @options[:run_on_modifications].merge(suite: suite))
  end

  if failed
    @last_failed = true
    Notifier.notify("Failed", title: "Teaspoon Guard", image: :failed)
    throw :task_has_failed
  else
    Notifier.notify("Success", title: "Teaspoon Guard", image: :success)
    run_all if @last_failed
  end
end

#startObject



24
25
26
27
28
29
30
# File 'lib/guard/teaspoon.rb', line 24

def start
  reload
  @resolver = Resolver.new(@options)
  @runner = Runner.new(@options)
  UI.info "Guard::Teaspoon is running"
  run_all if @options[:all_on_start]
end