Class: J1::Utils::GracefulQuit

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/j1/utils.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeGracefulQuit

Returns a new instance of GracefulQuit.



17
18
19
# File 'lib/j1/utils.rb', line 17

def initialize
  self.breaker = false
end

Instance Attribute Details

#breakerObject

Returns the value of attribute breaker.



15
16
17
# File 'lib/j1/utils.rb', line 15

def breaker
  @breaker
end

Class Method Details

.check(message = "quitting") ⇒ Object



28
29
30
31
32
33
34
# File 'lib/j1/utils.rb', line 28

def self.check(message = "quitting")
  if self.instance.breaker
    yield if block_given?
    puts message
    exit
  end
end

.enableObject



21
22
23
24
25
26
# File 'lib/j1/utils.rb', line 21

def self.enable
  trap('INT') {
    yield if block_given?
    self.instance.breaker = true
  }
end