Class: Redwood::HookManager::HookContext
Instance Method Summary collapse
- #__run(__hook, __filename, __locals) ⇒ Object
- #ask_yes_or_no(q) ⇒ Object
- #flash(s) ⇒ Object
- #get(tag) ⇒ Object
-
#initialize(name) ⇒ HookContext
constructor
A new instance of HookContext.
- #log(s) ⇒ Object
- #say(s) ⇒ Object
- #set(tag, value) ⇒ Object
Constructor Details
#initialize(name) ⇒ HookContext
Returns a new instance of HookContext.
7 8 9 10 11 |
# File 'lib/sup/hook.rb', line 7 def initialize name @__say_id = nil @__name = name @__cache = {} end |
Instance Method Details
#__run(__hook, __filename, __locals) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/sup/hook.rb', line 51 def __run __hook, __filename, __locals __binding = binding __lprocs, __lvars = __locals.partition { |k, v| v.is_a?(Proc) } eval __lvars.map { |k, v| "#{k} = __locals[#{k.inspect}];" }.join, __binding ## we also support closures for delays evaluation. unfortunately ## we have to do this via method calls, so you don't get all the ## semantics of a regular variable. not ideal. __lprocs.each do |k, v| self.class.instance_eval do define_method k do @__cache[k] ||= v.call end end end ret = eval __hook, __binding, __filename BufferManager.clear @__say_id if @__say_id @__cache = {} ret end |
#ask_yes_or_no(q) ⇒ Object
34 35 36 37 38 39 40 41 |
# File 'lib/sup/hook.rb', line 34 def ask_yes_or_no q if BufferManager.instantiated? BufferManager.ask_yes_or_no q else print q gets.chomp.downcase == 'y' end end |
#flash(s) ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/sup/hook.rb', line 22 def flash s if BufferManager.instantiated? BufferManager.flash s else log s end end |
#get(tag) ⇒ Object
43 44 45 |
# File 'lib/sup/hook.rb', line 43 def get tag HookManager.[tag] end |
#log(s) ⇒ Object
30 31 32 |
# File 'lib/sup/hook.rb', line 30 def log s info "hook[#@__name]: #{s}" end |
#say(s) ⇒ Object
13 14 15 16 17 18 19 20 |
# File 'lib/sup/hook.rb', line 13 def say s if BufferManager.instantiated? @__say_id = BufferManager.say s, @__say_id BufferManager.draw_screen else log s end end |
#set(tag, value) ⇒ Object
47 48 49 |
# File 'lib/sup/hook.rb', line 47 def set tag, value HookManager.[tag] = value end |