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 info "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
86 def run name, locals={}
87 hook = hook_for(name) or return
88 context = @contexts[hook] ||= HookContext.new(name)
89 context.__locals = locals
93 result = context.instance_eval @hooks[name], fn_for(name)
95 log "error running hook: #{e.message}"
96 log e.backtrace.join("\n")
97 @hooks[name] = nil # disable it
98 BufferManager.flash "Error running hook: #{e.message}" if BufferManager.instantiated?
104 def register name, desc
108 def print_hooks f=$stdout
110 Have #{@descs.size} registered hooks:
114 @descs.sort.each do |name, desc|
124 def enabled? name; !hook_for(name).nil? end
129 unless @hooks.member? name
132 returning IO.read(fn_for(name)) do
133 debug "read '#{name}' from #{fn_for(name)}"
135 rescue SystemCallError => e
136 #log "disabled hook for '#{name}': #{e.message}"
145 File.join @dir, "#{name}.rb"