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 ## "fail-fast", we'll call it.
22 def method_missing m, *a
25 @__locals[m] = @__locals[m].call(*a) # only call the proc once
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 HookManager.tags[tag] = value
68 BufferManager.clear @__say_id if @__say_id
81 Dir.mkdir dir unless File.exists? dir
83 self.class.i_am_the_instance self
88 def run name, locals={}
89 hook = hook_for(name) or return
90 context = @contexts[hook] ||= HookContext.new(name)
91 context.__locals = locals
95 result = context.instance_eval @hooks[name], fn_for(name)
97 log "error running hook: #{e.message}"
98 log e.backtrace.join("\n")
99 @hooks[name] = nil # disable it
100 BufferManager.flash "Error running hook: #{e.message}" if BufferManager.instantiated?
106 def register name, desc
110 def print_hooks f=$stdout
112 Have #{@descs.size} registered hooks:
116 @descs.sort.each do |name, desc|
126 def enabled? name; !hook_for(name).nil? end
131 unless @hooks.member? name
134 returning IO.read(fn_for(name)) do
135 log "read '#{name}' from #{fn_for(name)}"
137 rescue SystemCallError => e
138 #log "disabled hook for '#{name}': #{e.message}"
147 File.join @dir, "#{name}.rb"
151 Redwood::log("hook: " + m)