class PipeOperator::ProxyResolver
Constants
- AUTOLOAD
- FROZEN
- REBIND
Public Class Methods
new(object, resolved = ::Set.new)
click to toggle source
# File lib/pipe_operator/proxy_resolver.rb 7 def initialize(object, resolved = ::Set.new) 8 @object = object 9 @resolved = resolved 10 @singleton = ::PipeOperator.singleton(object) 11 end
Public Instance Methods
proxy()
click to toggle source
# File lib/pipe_operator/proxy_resolver.rb 13 def proxy 14 proxy = find_existing_proxy 15 return proxy if proxy && !REBIND 16 proxy ||= create_proxy 17 rebind_nested_constants 18 proxy 19 end
Private Instance Methods
create_proxy()
click to toggle source
# File lib/pipe_operator/proxy_resolver.rb 30 def create_proxy 31 Proxy.new(@object, @singleton).tap do |proxy| 32 @resolved.add(proxy) 33 34 if !@singleton.frozen? 35 @singleton.prepend(Observer).prepend(proxy) 36 elsif FROZEN 37 id = @singleton.__id__ * 2 38 unfreeze = ~(1 << 3) 39 ::Fiddle::Pointer.new(id)[1] &= unfreeze 40 @singleton.prepend(Observer).prepend(proxy) 41 @singleton.freeze 42 end 43 end 44 end
find_existing_proxy()
click to toggle source
# File lib/pipe_operator/proxy_resolver.rb 23 def find_existing_proxy 24 @singleton.ancestors.each do |existing| 25 break if @singleton == existing 26 return existing if Proxy === existing 27 end 28 end
rebind_nested_constants()
click to toggle source
# File lib/pipe_operator/proxy_resolver.rb 46 def rebind_nested_constants 47 context = ::Module === @object ? @object : @singleton 48 49 context.constants.map do |constant| 50 next unless context.const_defined?(constant, AUTOLOAD) 51 52 constant = silence_deprecations do 53 context.const_get(constant, false) rescue next 54 end 55 56 next if constant.eql?(@object) # recursion 57 next unless @resolved.add?(constant) 58 59 self.class.new(constant, @resolved).proxy 60 end 61 end
silence_deprecations() { || ... }
click to toggle source
# File lib/pipe_operator/proxy_resolver.rb 63 def silence_deprecations 64 stderr = $stderr 65 $stderr = ::StringIO.new 66 yield 67 ensure 68 $stderr = stderr 69 end