Class CodeRay::TokensProxy
In: lib/coderay/tokens_proxy.rb
Parent: Object

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.

Methods

each   encode   method_missing   new   scanner   tokens  

Attributes

block  [RW] 
input  [RW] 
lang  [RW] 
options  [RW] 

Public Class methods

Create a new TokensProxy with the arguments of CodeRay.scan.

[Source]

    # File lib/coderay/tokens_proxy.rb, line 12
12:     def initialize input, lang, options = {}, block = nil
13:       @input   = input
14:       @lang    = lang
15:       @options = options
16:       @block   = block
17:     end

Public Instance methods

Overwrite Struct#each.

[Source]

    # File lib/coderay/tokens_proxy.rb, line 48
48:     def each *args, &blk
49:       tokens.each(*args, &blk)
50:       self
51:     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 21
21:     def encode encoder, options = {}
22:       if encoder.respond_to? :to_sym
23:         CodeRay.encode(input, lang, encoder, options)
24:       else
25:         encoder.encode_tokens tokens, options
26:       end
27:     end

Tries to call encode; delegates to tokens otherwise.

[Source]

    # File lib/coderay/tokens_proxy.rb, line 31
31:     def method_missing method, *args, &blk
32:       encode method.to_sym, *args
33:     rescue PluginHost::PluginNotFound
34:       tokens.send(method, *args, &blk)
35:     end

A (cached) scanner instance to use for the scan task.

[Source]

    # File lib/coderay/tokens_proxy.rb, line 43
43:     def scanner
44:       @scanner ||= CodeRay.scanner(lang, options, &block)
45:     end

The (cached) result of the tokenized input; a Tokens instance.

[Source]

    # File lib/coderay/tokens_proxy.rb, line 38
38:     def tokens
39:       @tokens ||= scanner.tokenize(input)
40:     end

[Validate]