Module: Flare::Util::Interruption
- Included in:
- Tools::Cli::SubCommand
- Defined in:
- lib/flare/util/interruption.rb
Constant Summary collapse
- InterruptionTargets =
[]
Class Method Summary collapse
Instance Method Summary collapse
- #initialize_interruption ⇒ Object
- #interrupt ⇒ Object
- #interrupt_ ⇒ Object
- #interrupted? ⇒ Boolean
- #interruptible(&block) ⇒ Object
- #interruptible? ⇒ Boolean
Class Method Details
.included(klass) ⇒ Object
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/flare/util/interruption.rb', line 11 def self.included(klass) klass.class_eval { alias_method :initialize_before_interruption, :initialize def initialize(*args) super initialize_before_interruption(*args) initialize_interruption end } end |
.interrupt_all ⇒ Object
22 23 24 25 26 |
# File 'lib/flare/util/interruption.rb', line 22 def self.interrupt_all InterruptionTargets.each do |x| x.interrupt_ end end |
Instance Method Details
#initialize_interruption ⇒ Object
28 29 30 31 32 |
# File 'lib/flare/util/interruption.rb', line 28 def initialize_interruption InterruptionTargets.push self @__interruptible__ = false @__interrupted__ = false end |
#interrupt ⇒ Object
56 57 58 59 60 61 |
# File 'lib/flare/util/interruption.rb', line 56 def interrupt if interruptible? info "INTERRUPTED" exit 1 end end |
#interrupt_ ⇒ Object
51 52 53 54 |
# File 'lib/flare/util/interruption.rb', line 51 def interrupt_ @__interrupted__ = true interrupt end |
#interrupted? ⇒ Boolean
45 46 47 48 49 |
# File 'lib/flare/util/interruption.rb', line 45 def interrupted? @__interrupted__ ensure @__interrupted__ = false end |
#interruptible(&block) ⇒ Object
34 35 36 37 38 39 |
# File 'lib/flare/util/interruption.rb', line 34 def interruptible(&block) @__interruptible__ = true block.call ensure @__interruptible__ = false end |
#interruptible? ⇒ Boolean
41 42 43 |
# File 'lib/flare/util/interruption.rb', line 41 def interruptible? @__interruptible__ end |