Class: SafeBlock
- Inherits:
-
Object
- Object
- SafeBlock
- Defined in:
- lib/safeblock/version.rb,
lib/safeblock/safeblock.rb
Defined Under Namespace
Classes: Configuration
Constant Summary collapse
- VERSION =
"0.0.1"
Class Method Summary collapse
Class Method Details
.configuration ⇒ Object
29 30 31 |
# File 'lib/safeblock/safeblock.rb', line 29 def self.configuration @configuration end |
.setup(&block) ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/safeblock/safeblock.rb', line 33 def self.setup(&block) @configuration = SafeBlock::Configuration.new block.call(@configuration) @configuration = @configuration.to_hash end |
.start(options = {}, &block) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/safeblock/safeblock.rb', line 4 def self.start( = {}, &block) setup{} if @configuration.nil? = @configuration.merge() proc = Proc.new do || Timeout::timeout([:timeout]) do begin block.call rescue Exception => e raise e if [:ignore_exception] [:rescue_block].call(e) if [:rescue_block].is_a? Proc end end end if [:threaded] Thread.new{ proc.call() } else proc.call() end end |