Before After Around hooks for Ruby classes - still in ALPHA
Ruby
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
lib
spec
.gitignore
.rubocop.yml
Gemfile
Gemfile.lock
LICENSE
README.md
Rakefile
baa.gemspec
test

README.md

baa

Before After Around hooks for Ruby classes

  gem install baa
require 'baa'

class Foo
  extend Hooks

  def bar
    puts 'bar'
  end

  def baz
    puts 'baz'
  end

  def blat
    puts 'blat'
  end

  before :bar do
    puts 'before bar'
  end

  def pre
    puts 'before baz'
  end

  around :baz, :pre do
    puts 'after baz'
  end

  after :blat do
    puts 'after blat'
  end

  begin
    before :baz do
      puts "this should error"
    end
  rescue StandardError => e
    puts e.message
  end
end

Foo.new.bar
Foo.new.baz
Foo.new.blat

outputs

  Method (:baz) already has hooks applied
  {:before=>[:bar], :after=>[:blat], :around=>[:baz]}
  before bar
  bar
  before baz
  baz
  after baz
  blat
  after blat