class CodeRay::TokensProxy
The result of a scan operation is a TokensProxy
, but should act like Tokens
.
This proxy makes it possible to use the classic CodeRay.scan
.encode API while still providing the benefits of direct streaming.
Attributes
Public Class Methods
Source
# File lib/coderay/tokens_proxy.rb, line 12 def initialize input, lang, options = {}, block = nil @input = input @lang = lang @options = options @block = block end
Create a new TokensProxy
with the arguments of CodeRay.scan
.
Public Instance Methods
Source
# File lib/coderay/tokens_proxy.rb, line 48 def each *args, &blk tokens.each(*args, &blk) self end
Overwrite Struct#each.
Source
# File lib/coderay/tokens_proxy.rb, line 21 def encode encoder, options = {} if encoder.respond_to? :to_sym CodeRay.encode(input, lang, encoder, options) else encoder.encode_tokens tokens, options end end
Call CodeRay.encode
if encoder
is a Symbol; otherwise, convert the receiver to tokens and call encoder.encode_tokens.
Source
# File lib/coderay/tokens_proxy.rb, line 31 def method_missing method, *args, &blk encode method.to_sym, *args rescue PluginHost::PluginNotFound tokens.send(method, *args, &blk) end
Tries to call encode; delegates to tokens otherwise.
Source
# File lib/coderay/tokens_proxy.rb, line 43 def scanner @scanner ||= CodeRay.scanner(lang, options, &block) end
A (cached) scanner instance to use for the scan task.