4 ## there's probably a better way to do this, but to evaluate a hook
5 ## with a bunch of pre-set "local variables" i define a function
6 ## per variable and then instance_evaluate the code.
8 ## how does rails do it, when you pass :locals into a partial?
10 ## i don't bother providing setters, since i'm pretty sure the
11 ## charade will fall apart pretty quickly with respect to scoping.
12 ## this is basically fail-fast.
22 def method_missing m, *a
34 if BufferManager.instantiated?
35 @__say_id = BufferManager.say s, @__say_id
36 BufferManager.draw_screen
43 Redwood::log "hook[#@__name]: #{s}"
47 if BufferManager.instantiated?
48 BufferManager.ask_yes_or_no q
51 gets.chomp.downcase == 'y'
60 BufferManager.clear @__say_id if @__say_id
72 Dir.mkdir dir unless File.exists? dir
74 self.class.i_am_the_instance self
77 def run name, locals={}
78 hook = hook_for(name) or return
79 context = @contexts[hook] ||= HookContext.new(name)
80 context.__locals = locals
84 result = context.instance_eval @hooks[name], fn_for(name)
86 log "error running hook: #{e.message}"
87 log e.backtrace.join("\n")
88 BufferManager.flash "Error running hook: #{e.message}"
89 @hooks[name] = nil # disable it
95 def register name, desc
99 def print_hooks f=$stdout
101 Have #{@descs.size} registered hooks:
105 @descs.sort.each do |name, desc|
118 unless @hooks.member? name
121 returning IO.readlines(fn_for(name)).join do
122 log "read '#{name}' from #{fn_for(name)}"
124 rescue SystemCallError => e
125 #log "disabled hook for '#{name}': #{e.message}"
134 File.join @dir, "#{name}.rb"
138 Redwood::log("hook: " + m)