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.
21 def method_missing m, *a
33 @__say_id = BufferManager.say s, @__say_id
34 BufferManager.draw_screen
38 Redwood::log "hook[#@__name]: #{s}"
42 BufferManager.ask_yes_or_no q
50 BufferManager.clear @__say_id if @__say_id
62 Dir.mkdir dir unless File.exists? dir
64 self.class.i_am_the_instance self
67 def run name, locals={}
68 hook = hook_for(name) or return
69 context = @contexts[hook] ||= HookContext.new(name)
70 context.__locals = locals
74 result = context.instance_eval @hooks[name], fn_for(name)
76 log "error running hook: #{e.message}"
77 log e.backtrace.join("\n")
78 BufferManager.flash "Error running hook: #{e.message}"
84 def register name, desc
88 def print_hooks f=$stdout
90 Have #{@descs.size} registered hooks:
94 @descs.sort.each do |name, desc|
107 unless @hooks.member? name
110 returning IO.readlines(fn_for(name)).join do
111 log "read '#{name}' from #{fn_for(name)}"
113 rescue SystemCallError => e
114 log "disabled hook for '#{name}': #{e.message}"
123 File.join @dir, "#{name}.rb"
127 Redwood::log("hook: " + m)