Class: MySQLNoIo::Wraps::Blocks

Inherits:
Object
  • Object
show all
Defined in:
lib/mysqlnoio/wraps/blocks.rb

Overview

Just an example Wrap for testing and examples.

Instance Method Summary collapse

Instance Method Details

#after(&block) ⇒ Object

The after block will be run post execution.



11
12
13
# File 'lib/mysqlnoio/wraps/blocks.rb', line 11

def after &block
  @post = block
end

#before(&block) ⇒ Object

The before block will be run prior to the execution.



6
7
8
# File 'lib/mysqlnoio/wraps/blocks.rb', line 6

def before &block
  @prior = block
end

#execute(&block) ⇒ Object

Call the prior block, then execute, and then call the post-block.



16
17
18
19
20
21
# File 'lib/mysqlnoio/wraps/blocks.rb', line 16

def execute &block
  @prior.call if @prior.respond_to?(:call)
  block.call
ensure
  @post.call if @post.respond_to?(:call)
end