Class: Console::Resolver
- Inherits:
-
Object
- Object
- Console::Resolver
- Defined in:
- lib/console/resolver.rb
Instance Method Summary collapse
- #bind(names, &block) ⇒ Object
-
#initialize ⇒ Resolver
constructor
A new instance of Resolver.
- #resolve(trace_point) ⇒ Object
- #waiting? ⇒ Boolean
Constructor Details
#initialize ⇒ Resolver
Returns a new instance of Resolver.
25 26 27 28 29 |
# File 'lib/console/resolver.rb', line 25 def initialize @names = {} @trace_point = TracePoint.new(:class, &self.method(:resolve)) end |
Instance Method Details
#bind(names, &block) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/console/resolver.rb', line 31 def bind(names, &block) names.each do |name| if klass = Object.const_get(name) rescue nil yield klass else @names[name] = block end end if @names.any? @trace_point.enable else @trace_point.disable end end |
#resolve(trace_point) ⇒ Object
51 52 53 54 55 56 57 58 59 |
# File 'lib/console/resolver.rb', line 51 def resolve(trace_point) if block = @names.delete(trace_point.self.to_s) block.call(trace_point.self) end if @names.empty? @trace_point.disable end end |
#waiting? ⇒ Boolean
47 48 49 |
# File 'lib/console/resolver.rb', line 47 def waiting? @trace_point.enabled? end |