5 ## there's probably a better way to do this, but to evaluate a hook
6 ## with a bunch of pre-set "local variables" i define a function
7 ## per variable and then instance_evaluate the code.
9 ## i don't bother providing setters, since i'm pretty sure the
10 ## charade will fall apart pretty quickly with respect to scoping.
11 ## this is basically fail-fast.
13 def initialize name, hash
16 self.class.instance_eval { define_method(k) { v } }
21 @__say_id = BufferManager.say s, @__say_id
25 Redwood::log "hook[#@__name]: #{s}"
33 BufferManager.clear @__say_id if @__say_id
43 Dir.mkdir dir unless File.exists? dir
45 self.class.i_am_the_instance self
48 def run name, locals={}
49 hook = hook_for(name) or return
50 context = HookContext.new name, locals
53 result = eval @hooks[name], context.__binding, fn_for(name)
54 if result.is_a? String
55 log "got return value: #{result.inspect}"
56 BufferManager.flash result
59 log "error running hook: #{e.message}"
60 BufferManager.flash "Error running hook: #{e.message}"
65 def register name, desc
69 def print_hooks f=$stdout
71 Have #{@descs.size} registered hooks:
75 @descs.sort.each do |name, desc|
88 unless @hooks.member? name
91 returning IO.readlines(fn_for(name)).join do
92 log "read '#{name}' from #{fn_for(name)}"
94 rescue SystemCallError => e
103 File.join @dir, "#{name}.rb"
107 Redwood::log("hook: " + m)