Class: StartingBlocks::Extensions::BlinkyLighting

Inherits:
Object
  • Object
show all
Defined in:
lib/starting_blocks-blinky.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeBlinkyLighting

Returns a new instance of BlinkyLighting.



22
23
24
# File 'lib/starting_blocks-blinky.rb', line 22

def initialize
  @light = Blinky.new.light
end

Class Method Details

.turn_off!Object



26
27
28
# File 'lib/starting_blocks-blinky.rb', line 26

def self.turn_off!
  Blinky.new.light.off!
end

Instance Method Details

#change_color_to(color) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
# File 'lib/starting_blocks-blinky.rb', line 59

def change_color_to(color)
  case color
  when :green
    @light.success!
  when :red
    @light.failure!
  when :yellow
    @light.building!
  end
rescue
end

#receive_files_to_run(files) ⇒ Object



30
31
32
33
34
# File 'lib/starting_blocks-blinky.rb', line 30

def receive_files_to_run files
  @spec_count = files.count
  return if files.count == 0
  change_color_to :yellow
end

#receive_results(results) ⇒ Object



36
37
38
39
40
41
42
43
# File 'lib/starting_blocks-blinky.rb', line 36

def receive_results results
  return if @spec_count.to_i == 0
  if results[:color]
    change_color_to results[:color]
  else
    run_the_old_logic_with results
  end
end

#run_the_old_logic_with(results) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/starting_blocks-blinky.rb', line 45

def run_the_old_logic_with results
  if (results[:tests] || 0) == 0
    change_color_to :red
  elsif (results[:errors] || 0) > 0
    change_color_to :red
  elsif (results[:failures] || 0) > 0
    change_color_to :red
  elsif (results[:skips] || 0) > 0
    change_color_to :yellow
  else
    change_color_to :green
  end
end