Class: MarkdownLoggingProxy::Proxy
- Inherits:
-
Object
- Object
- MarkdownLoggingProxy::Proxy
- Defined in:
- lib/markdown_logging_proxy/proxy.rb
Constant Summary collapse
- DO_NOT_OVERWRITE =
%i[__binding__ __id__ __send__ class extend]
- DEFAULT_OVERWRITES =
Object.new.methods - DO_NOT_OVERWRITE
Instance Method Summary collapse
-
#initialize(to_proxy = nil, target: nil, location: STDOUT, backtrace: true, inspect_method: :pretty_inspect, ignore: [], proxy_response: [], overwrite: DEFAULT_OVERWRITES) ⇒ Proxy
constructor
A new instance of Proxy.
- #method_missing(meth, *args, &blk) ⇒ Object
Constructor Details
#initialize(to_proxy = nil, target: nil, location: STDOUT, backtrace: true, inspect_method: :pretty_inspect, ignore: [], proxy_response: [], overwrite: DEFAULT_OVERWRITES) ⇒ Proxy
Returns a new instance of Proxy.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/markdown_logging_proxy/proxy.rb', line 6 def initialize( to_proxy = nil, target: nil, location: STDOUT, backtrace: true, # regex/true/false backtrace control inspect_method: :pretty_inspect, ignore: [], # methods we shouldn't log/proxy proxy_response: [], # methods we should return a proxy for overwrite: DEFAULT_OVERWRITES ) @target = to_proxy || target @logger = MarkdownLogger.build(location, backtrace: backtrace) @tracer = Tracer.new( target: @target, proxy: self, logger: @logger, inspect_method: inspect_method, ignore: ignore, proxy_response: proxy_response, proxy_options: { overwrite: overwrite, backtrace: backtrace, } ) overwrite.each do |meth| self.class.define_method(meth) do |*args, &blk| @tracer.trace(meth, args, &blk) end end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args, &blk) ⇒ Object
37 38 39 |
# File 'lib/markdown_logging_proxy/proxy.rb', line 37 def method_missing(meth, *args, &blk) @tracer.trace(meth, args, &blk) end |