Skip to content

Instantly share code, notes, and snippets.

@ashmoran
Created September 28, 2009 16:12
Show Gist options
  • Save ashmoran/195533 to your computer and use it in GitHub Desktop.
Save ashmoran/195533 to your computer and use it in GitHub Desktop.
Initial attempt at implementing BeforeFeature using a the new listener API
class BeforeFeatureHooks
def initialize
@hooks = []
end
def register_hook(proc)
@hooks << proc
end
def run
@hooks.each do |hook|
hook.call
end
end
end
class BeforeFeatureVisitor
def initialize(step_mother, io, options)
@step_mother, @io, @options = step_mother, io, options
end
def before_feature(feature)
$before_feature_hooks.run
end
end
$before_feature_hooks = BeforeFeatureHooks.new
def BeforeFeature(&proc)
$before_feature_hooks.register_hook(proc)
end
AfterConfiguration do |configuration|
configuration.options[:formats] << ["BeforeFeatureVisitor", nil]
end
BeforeFeature do
puts "moo"
end
require 'pp'
class BeforeFeatureHooks
def initialize
@hooks = []
end
def register_hook(proc)
@hooks << proc
end
def run
@hooks.each do |hook|
hook.call
end
end
end
class BeforeFeatureVisitor
def initialize(step_mother, io, options)
@step_mother, @io, @options = step_mother, io, options
end
def before_feature(feature)
$before_feature_hooks.run
end
end
$before_feature_hooks = BeforeFeatureHooks.new
def BeforeFeature(&proc)
$before_feature_hooks.register_hook(proc)
end
AfterConfiguration do |configuration|
configuration.options[:formats] << ["BeforeFeatureVisitor", nil]
end
BeforeFeature do
puts "It"
end
BeforeFeature do
puts "works"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment