Class: Temill::SourceFile

Inherits:
Object
  • Object
show all
Defined in:
lib/temill/core.rb

Defined Under Namespace

Classes: InsertionPoint, InsertionPointSet

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(src, path, options) ⇒ SourceFile

Returns a new instance of SourceFile.



140
141
142
143
144
145
146
# File 'lib/temill/core.rb', line 140

def initialize(src, path, options)
  @path = path
  @lines = [nil] + src.lines
  @sexp = Ruby23Parser.new.parse(src, path).value
  @options = options
  @insertion_points = InsertionPointSet.new
end

Instance Attribute Details

#insertion_pointsObject (readonly)

Returns the value of attribute insertion_points.



138
139
140
# File 'lib/temill/core.rb', line 138

def insertion_points
  @insertion_points
end

#linesObject (readonly)

Returns the value of attribute lines.



137
138
139
# File 'lib/temill/core.rb', line 137

def lines
  @lines
end

#pathObject (readonly)

Returns the value of attribute path.



137
138
139
# File 'lib/temill/core.rb', line 137

def path
  @path
end

#sexpObject (readonly)

Returns the value of attribute sexp.



137
138
139
# File 'lib/temill/core.rb', line 137

def sexp
  @sexp
end

Class Method Details

.from_inline_source(src, virtual_path, options) ⇒ Object



148
149
150
# File 'lib/temill/core.rb', line 148

def self.from_inline_source(src, virtual_path, options)
  new(src, virtual_path, options)
end

.from_path(path, options) ⇒ Object



152
153
154
# File 'lib/temill/core.rb', line 152

def self.from_path(path, options)
  new(File.read(path), path, options)
end

Instance Method Details

#add_result(caller_loc, v, with_block) ⇒ Object

Parameters:

  • caller_loc (Thread::Backtrace::Location)
  • v (Object)

    value to show

  • with_block (bool)

    whether Temill#show is called with block



159
160
161
162
163
164
165
166
# File 'lib/temill/core.rb', line 159

def add_result(caller_loc, v, with_block)
  caller_lineno = caller_loc.lineno
  unless @insertion_points.at_caller_lineno(caller_lineno)
    @insertion_points.add(make_insertion_point(caller_loc, with_block))
  end
  @insertion_points.at_caller_lineno(caller_lineno) << v
  self
end

#each_source_line(&block) ⇒ Object



168
169
170
171
172
173
# File 'lib/temill/core.rb', line 168

def each_source_line(&block)
  return enum_for(__method__) unless block
  1.upto(@lines.size-1){| i |
    block.call(@lines[i], i)
  }
end