Class: Guard::Cane

Inherits:
Plugin
  • Object
show all
Defined in:
lib/guard/cane.rb

Overview

Defines the guard, which is automatically seen by Guard

Constant Summary collapse

DEFAULTS =
{
  run_all_on_start: true
}
SUCCESS =
["Passed", { title: "Cane", image: :success }]
FAILED =
["Failed", { title: "Cane", image: :failed }]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Cane

Returns a new instance of Cane.



15
16
17
18
19
# File 'lib/guard/cane.rb', line 15

def initialize(options = {})
  super options

  @options = DEFAULTS.merge(options)
end

Instance Attribute Details

#last_resultObject (readonly)

Returns the value of attribute last_result.



13
14
15
# File 'lib/guard/cane.rb', line 13

def last_result
  @last_result
end

#optionsObject (readonly)

Returns the value of attribute options.



13
14
15
# File 'lib/guard/cane.rb', line 13

def options
  @options
end

Instance Method Details

#build_command(paths) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/guard/cane.rb', line 54

def build_command(paths)
  command = []

  command << (options[:command] || "cane")

  if paths.any?
    joined_paths = paths.join(',')
    command << "--all '{#{joined_paths}}'"
  end

  command << options[:cli]

  command.compact.join(" ")
end

#cane(paths = []) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/guard/cane.rb', line 36

def cane(paths = [])
  command = build_command(paths)

  Compat::UI.info "Running Cane: #{command}"

  result = system command

  if result
    Compat::UI.notify(*SUCCESS) if last_result == false
  else
    Compat::UI.notify(*FAILED)
  end

  @last_result = result

  result
end

#run_allObject



27
28
29
# File 'lib/guard/cane.rb', line 27

def run_all
  cane
end

#run_on_modifications(paths) ⇒ Object



31
32
33
34
# File 'lib/guard/cane.rb', line 31

def run_on_modifications(paths)
  passed = cane paths
  run_all if options[:all_after_pass] && passed
end

#startObject



21
22
23
24
25
# File 'lib/guard/cane.rb', line 21

def start
  Compat::UI.info "Guard::Cane is running"

  run_all if options[:run_all_on_start]
end