Created
September 28, 2009 16:12
-
-
Save ashmoran/195533 to your computer and use it in GitHub Desktop.
Initial attempt at implementing BeforeFeature using a the new listener API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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