Class: CacheBuster::Pi

Inherits:
Object
  • Object
show all
Defined in:
lib/cache-buster/pi.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializePi

Returns a new instance of Pi.



4
5
6
# File 'lib/cache-buster/pi.rb', line 4

def initialize
  watch_buttons
end

Class Method Details

.hardObject



20
21
22
# File 'lib/cache-buster/pi.rb', line 20

def self.hard
  run Proc.new { Rackspace.new.clear }
end

.run(proc) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/cache-buster/pi.rb', line 28

def self.run(proc)
  red = PiPiper::Pin.new(pin: ENV['RED_PIN'].to_i, direction: :out)
  green = PiPiper::Pin.new(pin: ENV['GREEN_PIN'].to_i, direction: :out)
  red.on
  proc.call
  red.off
  green.on
  sleep 5
  green.off
  red.release
  green.release
  exit if ENV['TEST']
end

.softObject



24
25
26
# File 'lib/cache-buster/pi.rb', line 24

def self.soft
  run Proc.new { Cloudflare.new.clear }
end

Instance Method Details

#watch_buttonsObject



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/cache-buster/pi.rb', line 8

def watch_buttons
  PiPiper.watch pin: ENV['SOFT_BUTTON'].to_i do
    CacheBuster::Pi.soft
  end

  PiPiper.watch pin: ENV['HARD_BUTTON'].to_i do
    CacheBuster::Pi.hard
  end

  PiPiper.wait
end