Sha256: 0507fbed2c828dae4fc44ba6e234e442d4c55d54d3f0d3119a53fc822d379631

Contents?: true

Size: 958 Bytes

Versions: 2

Compression:

Stored size: 958 Bytes

Contents

# encoding: utf-8

module Rubocop
  # ProcessedSource contains objects which are generated by Parser
  # and other information such as disabled lines for cops.
  # It also provides a convenient way to access source lines.
  class ProcessedSource
    attr_reader :buffer, :ast, :comments, :tokens, :diagnostics
    attr_accessor :disabled_lines_for_cops

    def initialize(buffer, ast, comments, tokens, diagnostics)
      @buffer = buffer
      @ast = ast
      @comments = comments
      @tokens = tokens
      @diagnostics = diagnostics
    end

    def lines
      if @lines
        @lines
      else
        init_lines
        @lines
      end
    end

    def raw_lines
      if @raw_lines
        @raw_lines
      else
        init_lines
        @raw_lines
      end
    end

    def [](*args)
      lines[*args]
    end

    private

    def init_lines
      @raw_lines = @buffer.source.lines
      @lines = @raw_lines.map(&:chomp)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rubocop-0.13.1 lib/rubocop/processed_source.rb
rubocop-0.13.0 lib/rubocop/processed_source.rb