linecache-tf 0.44 → 0.45
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/ChangeLog +39 -0
- data/NEWS +6 -0
- data/Rakefile +55 -106
- data/lib/linecache.rb +135 -42
- data/test/test-linecache.rb +17 -1
- metadata +15 -18
- data/VERSION +0 -1
data/ChangeLog
CHANGED
@@ -1,3 +1,42 @@
|
|
1
|
+
2010-11-26 04:27 Rocky Bernstein
|
2
|
+
|
3
|
+
* .gemspec: Don't use lib/version.rb any more. Also rvm lists Ruby
|
4
|
+
as 1.9.2-nframe no just 1.9.2.
|
5
|
+
|
6
|
+
2010-11-26 02:23 Rocky Bernstein
|
7
|
+
|
8
|
+
* lib/linecache.rb: Work more on iseq caching.
|
9
|
+
|
10
|
+
2010-11-26 02:01 Rocky Bernstein
|
11
|
+
|
12
|
+
* Rakefile, lib/linecache.rb, lib/version.rb,
|
13
|
+
test/test-linecache.rb: Pick up version from LineCache module.
|
14
|
+
Include "\n" in sha1 calculation. Start work on iseq caching.
|
15
|
+
|
16
|
+
2010-09-22 17:00 Rocky Bernstein
|
17
|
+
|
18
|
+
* Rakefile: Correct suspicious test task so it doesn't modify
|
19
|
+
itself.
|
20
|
+
|
21
|
+
2010-09-21 21:12 Rocky Bernstein
|
22
|
+
|
23
|
+
* .gemspec, Rakefile: Title on RDOC referred to wrong package
|
24
|
+
|
25
|
+
2010-09-21 04:13 Rocky Bernstein
|
26
|
+
|
27
|
+
* .gemspec: Testing for wrong constant.
|
28
|
+
|
29
|
+
2010-09-21 00:47 Rocky Bernstein
|
30
|
+
|
31
|
+
* Rakefile: Small tweaks to Rakefile building on previous stuff
|
32
|
+
|
33
|
+
2010-09-20 23:13 Rocky Bernstein
|
34
|
+
|
35
|
+
* .gemspec, ChangeLog, Makefile, Rakefile, VERSION, lib/Makefile,
|
36
|
+
lib/linecache.rb, lib/version.rb: Administrivia: Add gemspec
|
37
|
+
file, simplify Rakefile. Add Makefile for compatibility for us
|
38
|
+
old farts.
|
39
|
+
|
1
40
|
2010-09-13 14:49 Rocky Bernstein
|
2
41
|
|
3
42
|
* ChangeLog, NEWS, Rakefile, VERSION: Update description for
|
data/NEWS
CHANGED
data/Rakefile
CHANGED
@@ -4,135 +4,84 @@ require 'rubygems'
|
|
4
4
|
require 'rake/gempackagetask'
|
5
5
|
require 'rake/rdoctask'
|
6
6
|
require 'rake/testtask'
|
7
|
+
require 'fileutils'
|
7
8
|
|
8
|
-
|
9
|
-
|
10
|
-
|
9
|
+
ROOT_DIR = File.dirname(__FILE__)
|
10
|
+
require File.join %W(#{ROOT_DIR} lib linecache)
|
11
|
+
|
12
|
+
def gemspec
|
13
|
+
@gemspec ||= eval(File.read('.gemspec'), binding, '.gemspec')
|
11
14
|
end
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
'ChangeLog',
|
21
|
-
'NEWS',
|
22
|
-
'README',
|
23
|
-
'Rakefile',
|
24
|
-
'VERSION',
|
25
|
-
'lib/*.rb',
|
26
|
-
'test/*.rb',
|
27
|
-
'test/data/*.rb',
|
28
|
-
'test/short-file'
|
29
|
-
]
|
30
|
-
|
31
|
-
desc "Test everything."
|
32
|
-
test_task = task :test => :lib do
|
33
|
-
Rake::TestTask.new(:test) do |t|
|
34
|
-
t.pattern = 'test/test-*.rb'
|
35
|
-
t.verbose = true
|
15
|
+
|
16
|
+
desc "Build the gem"
|
17
|
+
task :package=>:gem
|
18
|
+
task :gem=>:gemspec do
|
19
|
+
Dir.chdir(ROOT_DIR) do
|
20
|
+
sh "gem build .gemspec"
|
21
|
+
FileUtils.mkdir_p 'pkg'
|
22
|
+
FileUtils.mv "#{gemspec.name}-#{gemspec.version}.gem", 'pkg'
|
36
23
|
end
|
37
24
|
end
|
38
25
|
|
39
|
-
desc "
|
40
|
-
task :
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
system("svn2cl svn+ssh://rockyb@rubyforge.org/var/svn/rocky-hacks/linecache/branches/ruby-1.9 --authors=svn2cl_usermap")
|
26
|
+
desc "Install the gem locally"
|
27
|
+
task :install => :gem do
|
28
|
+
Dir.chdir(ROOT_DIR) do
|
29
|
+
sh %{gem install --local pkg/#{gemspec.name}-#{gemspec.version}}
|
30
|
+
end
|
45
31
|
end
|
46
32
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
spec.summary = "Read file with caching"
|
53
|
-
spec.description = <<-EOF
|
54
|
-
LineCache is a module for reading and caching lines. This may be useful for
|
55
|
-
example in a debugger where the same lines are shown many times.
|
56
|
-
|
57
|
-
This version works only with a patched version of Ruby 1.9.2 and rb-threadframe.
|
58
|
-
EOF
|
59
|
-
|
60
|
-
spec.version = "#{PKG_VERSION}"
|
61
|
-
|
62
|
-
spec.author = "R. Bernstein"
|
63
|
-
spec.email = "rockyb@rubyforge.net"
|
64
|
-
spec.platform = Gem::Platform::RUBY
|
65
|
-
spec.require_path = "lib"
|
66
|
-
spec.files = FILES.to_a
|
67
|
-
|
68
|
-
spec.required_ruby_version = '>= 1.9.2'
|
69
|
-
spec.date = Time.now
|
70
|
-
spec.add_dependency('rb-threadframe', '>= 0.32')
|
71
|
-
spec.rubyforge_project = 'rocky-hacks'
|
72
|
-
|
73
|
-
# rdoc
|
74
|
-
spec.has_rdoc = true
|
75
|
-
spec.extra_rdoc_files = %w(README lib/linecache.rb lib/tracelines.rb)
|
76
|
-
|
77
|
-
spec.test_files = FileList['test/*.rb']
|
33
|
+
desc "Test everything"
|
34
|
+
Rake::TestTask.new(:test) do |t|
|
35
|
+
t.libs << './lib'
|
36
|
+
t.pattern = 'test/test-*.rb'
|
37
|
+
t.verbose = true
|
78
38
|
end
|
39
|
+
task :test => :lib
|
40
|
+
|
41
|
+
desc "same as test"
|
42
|
+
task :check => :test
|
79
43
|
|
80
|
-
|
81
|
-
|
82
|
-
|
44
|
+
desc "Create a GNU-style ChangeLog via svn2cl"
|
45
|
+
task :ChangeLog do
|
46
|
+
system("svn2cl --authors=svn2cl_usermap")
|
83
47
|
end
|
84
48
|
|
85
49
|
task :default => [:test]
|
86
50
|
|
87
|
-
# desc "Publish linecache to RubyForge."
|
88
|
-
# task :publish do
|
89
|
-
# require 'rake/contrib/sshpublisher'
|
90
|
-
|
91
|
-
# # Get ruby-debug path.
|
92
|
-
# ruby_debug_path = File.expand_path(File.dirname(__FILE__))
|
93
|
-
|
94
|
-
# publisher = Rake::SshDirPublisher.new("rockyb@rubyforge.org",
|
95
|
-
# "/var/www/gforge-projects/rocky-hacks/linecache", ruby_debug_path)
|
96
|
-
# end
|
97
|
-
|
98
51
|
desc "Remove built files"
|
99
52
|
task :clean => [:clobber_package, :clobber_rdoc]
|
100
53
|
|
54
|
+
desc "Generate the gemspec"
|
55
|
+
task :generate do
|
56
|
+
puts gemspec.to_ruby
|
57
|
+
end
|
58
|
+
|
59
|
+
desc "Validate the gemspec"
|
60
|
+
task :gemspec do
|
61
|
+
gemspec.validate
|
62
|
+
end
|
63
|
+
|
101
64
|
# --------- RDoc Documentation ------
|
102
65
|
desc "Generate rdoc documentation"
|
103
66
|
Rake::RDocTask.new("rdoc") do |rdoc|
|
104
67
|
rdoc.rdoc_dir = 'doc'
|
105
|
-
rdoc.title = "
|
68
|
+
rdoc.title = "LineCache #{LineCache::VERSION} Documentation"
|
69
|
+
|
106
70
|
# Show source inline with line numbers
|
107
|
-
rdoc.options
|
108
|
-
|
109
|
-
|
110
|
-
rdoc.
|
111
|
-
end
|
71
|
+
rdoc.options += %w(--inline-source --line-numbers)
|
72
|
+
|
73
|
+
# Make the README file the start page for the generated html
|
74
|
+
rdoc.options += %w(--main README)
|
112
75
|
|
113
|
-
|
114
|
-
# task :rubyforge_upload do
|
115
|
-
# `rubyforge login`
|
116
|
-
# release_command = "rubyforge add_release #{PKG_NAME} #{PKG_NAME} '#{PKG_NAME}-#{PKG_VERSION}' pkg/#{PKG_NAME}-#{PKG_VERSION}.gem"
|
117
|
-
# puts release_command
|
118
|
-
# system(release_command)
|
119
|
-
# end
|
120
|
-
|
121
|
-
def install(spec, *opts)
|
122
|
-
args = ['gem', 'install', "pkg/#{spec.name}-#{spec.version}.gem"] + opts
|
123
|
-
system(*args)
|
76
|
+
rdoc.rdoc_files.include('lib/*.rb', 'README', 'COPYING')
|
124
77
|
end
|
78
|
+
desc "Same as rdoc"
|
79
|
+
task :doc => :rdoc
|
125
80
|
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
# ri and rdoc take lots of time
|
130
|
-
install(default_spec, '--no-ri', '--no-rdoc')
|
131
|
-
end
|
132
|
-
end
|
81
|
+
task :clobber_package do
|
82
|
+
FileUtils.rm_rf File.join(ROOT_DIR, 'pkg')
|
83
|
+
end
|
133
84
|
|
134
|
-
task :
|
135
|
-
|
136
|
-
install(default_spec)
|
137
|
-
end
|
85
|
+
task :clobber_rdoc do
|
86
|
+
FileUtils.rm_rf File.join(ROOT_DIR, 'doc')
|
138
87
|
end
|
data/lib/linecache.rb
CHANGED
@@ -1,7 +1,5 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
#
|
3
|
-
#
|
4
|
-
# Copyright (C) 2007, 2008, 2009 Rocky Bernstein <rockyb@rubyforge.net>
|
2
|
+
# Copyright (C) 2007, 2008, 2009, 2010 Rocky Bernstein <rockyb@rubyforge.net>
|
5
3
|
#
|
6
4
|
# This program is free software; you can redistribute it and/or modify
|
7
5
|
# it under the terms of the GNU General Public License as published by
|
@@ -23,8 +21,6 @@
|
|
23
21
|
#
|
24
22
|
# = linecache
|
25
23
|
# A module to read and cache lines of a Ruby program.
|
26
|
-
# == Version
|
27
|
-
# :include:VERSION
|
28
24
|
|
29
25
|
# == SYNOPSIS
|
30
26
|
#
|
@@ -62,21 +58,22 @@
|
|
62
58
|
# and never destroys SCRIPT_LINES__
|
63
59
|
SCRIPT_LINES__ = {} unless defined? SCRIPT_LINES__
|
64
60
|
|
61
|
+
require 'tempfile'
|
65
62
|
require 'digest/sha1'
|
66
63
|
require 'set'
|
67
64
|
require_relative 'tracelines'
|
68
65
|
|
69
|
-
# require 'ruby-debug' ; Debugger.start
|
70
|
-
|
71
66
|
# = module LineCache
|
72
67
|
# A module to read and cache lines of a Ruby program.
|
73
68
|
module LineCache
|
69
|
+
VERSION = '0.45'
|
74
70
|
LineCacheInfo = Struct.new(:stat, :line_numbers, :lines, :path, :sha1) unless
|
75
71
|
defined?(LineCacheInfo)
|
76
72
|
|
77
73
|
# The file cache. The key is a name as would be given by Ruby for
|
78
74
|
# __FILE__. The value is a LineCacheInfo object.
|
79
75
|
@@file_cache = {}
|
76
|
+
@@iseq_cache = {}
|
80
77
|
|
81
78
|
# Maps a string filename (a String) to a key in @@file_cache (a
|
82
79
|
# String).
|
@@ -92,6 +89,17 @@ module LineCache
|
|
92
89
|
# ranges. Will probably use this for that, but I'm not sure.
|
93
90
|
@@file2file_remap = {}
|
94
91
|
@@file2file_remap_lines = {}
|
92
|
+
|
93
|
+
@@iseq2file = {}
|
94
|
+
|
95
|
+
def remove_iseq_temps
|
96
|
+
@@iseq2file.values.each do |filename|
|
97
|
+
File.unlink(filename)
|
98
|
+
end
|
99
|
+
end
|
100
|
+
module_function :remove_iseq_temps
|
101
|
+
at_exit { remove_iseq_temps }
|
102
|
+
|
95
103
|
|
96
104
|
# Clear the file cache entirely.
|
97
105
|
def clear_file_cache()
|
@@ -101,6 +109,12 @@ module LineCache
|
|
101
109
|
end
|
102
110
|
module_function :clear_file_cache
|
103
111
|
|
112
|
+
# Clear the iseq cache entirely.
|
113
|
+
def clear_iseq_cache()
|
114
|
+
@@iseq_cache = {}
|
115
|
+
end
|
116
|
+
module_function :clear_file_cache
|
117
|
+
|
104
118
|
# Return an array of cached file names
|
105
119
|
def cached_files()
|
106
120
|
@@file_cache.keys
|
@@ -146,10 +160,31 @@ module LineCache
|
|
146
160
|
end
|
147
161
|
module_function :checkcache
|
148
162
|
|
163
|
+
# Cache iseq if it's not already cached.
|
164
|
+
def cache_iseq(iseq, string=nil, sha1=nil)
|
165
|
+
if !@@iseq_cache.member?(iseq)
|
166
|
+
update_iseq_cache(iseq, string, sha1)
|
167
|
+
end
|
168
|
+
iseq
|
169
|
+
end
|
170
|
+
module_function :cache_iseq
|
171
|
+
|
172
|
+
# Cache file name or iseq object if it's not already cached.
|
173
|
+
# Return the expanded filename for it in the cache if a filename,
|
174
|
+
# or the iseq, or nil if we can't find the file.
|
175
|
+
def cache(file_or_iseq, reload_on_change=false)
|
176
|
+
if file_or_iseq.kind_of?(String)
|
177
|
+
cache_file(file_or_iseq, reload_on_change)
|
178
|
+
else
|
179
|
+
cache_iseq(file_or_iseq)
|
180
|
+
end
|
181
|
+
end
|
182
|
+
module_function :cache
|
183
|
+
|
149
184
|
# Cache filename if it's not already cached.
|
150
185
|
# Return the expanded filename for it in the cache
|
151
186
|
# or nil if we can't find the file.
|
152
|
-
def
|
187
|
+
def cache_file(filename, reload_on_change=false)
|
153
188
|
if @@file_cache.member?(filename)
|
154
189
|
checkcache(filename) if reload_on_change
|
155
190
|
else
|
@@ -161,11 +196,15 @@ module LineCache
|
|
161
196
|
nil
|
162
197
|
end
|
163
198
|
end
|
164
|
-
module_function :
|
199
|
+
module_function :cache_file
|
165
200
|
|
166
|
-
# Return true if
|
167
|
-
def cached?(
|
168
|
-
|
201
|
+
# Return true if file_or_iseq is cached
|
202
|
+
def cached?(file_or_iseq)
|
203
|
+
if file_or_iseq.kind_of?(String)
|
204
|
+
@@file_cache.member?(map_file(file_or_iseq))
|
205
|
+
else
|
206
|
+
cached_iseq?(file_or_iseq)
|
207
|
+
end
|
169
208
|
end
|
170
209
|
module_function :cached?
|
171
210
|
|
@@ -191,10 +230,15 @@ module LineCache
|
|
191
230
|
# $: << '/tmp'
|
192
231
|
# lines = LineCache.getlines('myfile.rb')
|
193
232
|
#
|
194
|
-
def getline(
|
195
|
-
|
196
|
-
|
197
|
-
|
233
|
+
def getline(file_or_iseq, line_number, reload_on_change=true)
|
234
|
+
lines =
|
235
|
+
if file_or_iseq.kind_of?(String)
|
236
|
+
filename = map_file(file_or_iseq)
|
237
|
+
filename, line_number = map_file_line(filename, line_number)
|
238
|
+
getlines(filename, reload_on_change)
|
239
|
+
else
|
240
|
+
iseq_getlines(file_or_iseq)
|
241
|
+
end
|
198
242
|
if lines and (1..lines.size) === line_number
|
199
243
|
return lines[line_number-1]
|
200
244
|
else
|
@@ -203,6 +247,23 @@ module LineCache
|
|
203
247
|
end
|
204
248
|
module_function :getline
|
205
249
|
|
250
|
+
# Read lines of +iseq+ and cache the results. However +iseq+ was
|
251
|
+
# previously cached use the results from the cache. Return nil
|
252
|
+
# if we can't get lines
|
253
|
+
def iseq_getlines(iseq)
|
254
|
+
if @@iseq_cache.member?(iseq)
|
255
|
+
return @@iseq_cache[iseq].lines
|
256
|
+
else
|
257
|
+
update_iseq_cache(iseq)
|
258
|
+
if @@iseq_cache.member?(iseq)
|
259
|
+
return @@iseq_cache[iseq].lines
|
260
|
+
else
|
261
|
+
return nil
|
262
|
+
end
|
263
|
+
end
|
264
|
+
end
|
265
|
+
module_function :iseq_getlines
|
266
|
+
|
206
267
|
# Read lines of +filename+ and cache the results. However +filename+ was
|
207
268
|
# previously cached use the results from the cache. Return nil
|
208
269
|
# if we can't get lines
|
@@ -213,13 +274,18 @@ module LineCache
|
|
213
274
|
return @@file_cache[filename].lines
|
214
275
|
else
|
215
276
|
update_cache(filename, true)
|
216
|
-
|
277
|
+
if @@file_cache.member?(filename)
|
278
|
+
return @@file_cache[filename].lines
|
279
|
+
else
|
280
|
+
return nil
|
281
|
+
end
|
217
282
|
end
|
218
283
|
end
|
219
284
|
module_function :getlines
|
220
285
|
|
221
286
|
# Return full filename path for filename
|
222
287
|
def path(filename)
|
288
|
+
return unless filename.kind_of?(String)
|
223
289
|
filename = map_file(filename)
|
224
290
|
return nil unless @@file_cache.member?(filename)
|
225
291
|
@@file_cache[filename].path
|
@@ -232,7 +298,7 @@ module LineCache
|
|
232
298
|
module_function :remap_file
|
233
299
|
|
234
300
|
def remap_file_lines(from_file, to_file, range, start)
|
235
|
-
range = (range..range) if range.
|
301
|
+
range = (range..range) if range.kind_of?(Fixnum)
|
236
302
|
to_file = from_file unless to_file
|
237
303
|
if @@file2file_remap_lines[to_file]
|
238
304
|
# FIXME: need to check for overwriting ranges: whether
|
@@ -252,7 +318,7 @@ module LineCache
|
|
252
318
|
@@file_cache[filename].sha1
|
253
319
|
sha1 = Digest::SHA1.new
|
254
320
|
@@file_cache[filename].lines.each do |line|
|
255
|
-
sha1 << line
|
321
|
+
sha1 << line + "\n"
|
256
322
|
end
|
257
323
|
@@file_cache[filename].sha1 = sha1
|
258
324
|
sha1.hexdigest
|
@@ -260,10 +326,16 @@ module LineCache
|
|
260
326
|
module_function :sha1
|
261
327
|
|
262
328
|
# Return the number of lines in filename
|
263
|
-
def size(
|
264
|
-
|
265
|
-
|
266
|
-
|
329
|
+
def size(file_or_iseq)
|
330
|
+
cache(file_or_iseq)
|
331
|
+
if file_or_iseq.kind_of?(String)
|
332
|
+
file_or_iseq = map_file(file_or_iseq)
|
333
|
+
return nil unless @@file_cache.member?(file_or_iseq)
|
334
|
+
@@file_cache[file_or_iseq].lines.length
|
335
|
+
else
|
336
|
+
return nil unless @@iseq_cache.member?(file_or_iseq)
|
337
|
+
@@iseq_cache[file_or_iseq].lines.length
|
338
|
+
end
|
267
339
|
end
|
268
340
|
module_function :size
|
269
341
|
|
@@ -296,6 +368,25 @@ module LineCache
|
|
296
368
|
end
|
297
369
|
module_function :map_file
|
298
370
|
|
371
|
+
def map_iseq(iseq)
|
372
|
+
if @@iseq2file[iseq]
|
373
|
+
@@iseq2file[iseq]
|
374
|
+
else
|
375
|
+
# Doc says there's new takes an optional string parameter
|
376
|
+
# But it doesn't work for me
|
377
|
+
sha1 = Digest::SHA1.new
|
378
|
+
string = iseq.source
|
379
|
+
sha1 << iseq.source
|
380
|
+
tempfile = Tempfile.new(["eval-#{sha1.hexdigest[0...7]}-", '.rb'])
|
381
|
+
tempfile.open.puts(string)
|
382
|
+
tempfile.close
|
383
|
+
# cache_iseq(iseq, string, sha1.hexdigest)
|
384
|
+
@@iseq2file[iseq] = tempfile.path
|
385
|
+
tempfile.path
|
386
|
+
end
|
387
|
+
end
|
388
|
+
module_function :map_iseq
|
389
|
+
|
299
390
|
def map_file_line(file, line)
|
300
391
|
if @@file2file_remap_lines[file]
|
301
392
|
@@file2file_remap_lines[file].each do |from_file, range, start|
|
@@ -309,6 +400,22 @@ module LineCache
|
|
309
400
|
end
|
310
401
|
module_function :map_file_line
|
311
402
|
|
403
|
+
def iseq_is_eval?(iseq)
|
404
|
+
!!iseq.source
|
405
|
+
end
|
406
|
+
module_function :iseq_is_eval?
|
407
|
+
|
408
|
+
# Update a cache entry. If something is wrong, return nil. Return
|
409
|
+
# true if the cache was updated and false if not.
|
410
|
+
def update_iseq_cache(iseq, string=nil, sha1=nil)
|
411
|
+
return false unless iseq_is_eval?(iseq)
|
412
|
+
string = iseq.source unless string
|
413
|
+
@@iseq_cache[iseq] =
|
414
|
+
LineCacheInfo.new(nil, nil, string.split(/\n/), nil, sha1)
|
415
|
+
return true
|
416
|
+
end
|
417
|
+
module_function :update_iseq_cache
|
418
|
+
|
312
419
|
# Update a cache entry. If something's
|
313
420
|
# wrong, return nil. Return true if the cache was updated and false
|
314
421
|
# if not. If use_script_lines is true, use that as the source for the
|
@@ -320,24 +427,6 @@ module LineCache
|
|
320
427
|
@@file_cache.delete(filename)
|
321
428
|
path = File.expand_path(filename)
|
322
429
|
|
323
|
-
if use_script_lines
|
324
|
-
list = [filename]
|
325
|
-
list << @@file2file_remap[path] if @@file2file_remap[path]
|
326
|
-
list.each do |name|
|
327
|
-
if !SCRIPT_LINES__[name].nil? && SCRIPT_LINES__[name] != true
|
328
|
-
begin
|
329
|
-
stat = File.stat(name)
|
330
|
-
rescue
|
331
|
-
stat = nil
|
332
|
-
end
|
333
|
-
lines = SCRIPT_LINES__[name]
|
334
|
-
@@file_cache[filename] = LineCacheInfo.new(stat, nil, lines, path, nil)
|
335
|
-
@@file2file_remap[path] = filename
|
336
|
-
return true
|
337
|
-
end
|
338
|
-
end
|
339
|
-
end
|
340
|
-
|
341
430
|
if File.exist?(path)
|
342
431
|
stat = File.stat(path)
|
343
432
|
elsif File.basename(filename) == filename
|
@@ -367,7 +456,6 @@ module LineCache
|
|
367
456
|
end
|
368
457
|
|
369
458
|
module_function :update_cache
|
370
|
-
|
371
459
|
end
|
372
460
|
|
373
461
|
# example usage
|
@@ -404,4 +492,9 @@ if __FILE__ == $0
|
|
404
492
|
LineCache::remap_file_lines(__FILE__, 'test2', (10..20), 6)
|
405
493
|
puts LineCache::getline('test2', 10)
|
406
494
|
puts "Remapped 10th line of test2 is\n#{line}"
|
495
|
+
require 'thread_frame'
|
496
|
+
puts eval("x=1
|
497
|
+
LineCache::getline(RubyVM::ThreadFrame.current.iseq, 1)")
|
498
|
+
puts eval("x=2
|
499
|
+
LineCache::getline(RubyVM::ThreadFrame.current.iseq, 2)")
|
407
500
|
end
|
data/test/test-linecache.rb
CHANGED
@@ -146,8 +146,24 @@ class TestLineCache < Test::Unit::TestCase
|
|
146
146
|
def test_sha1
|
147
147
|
test_file = File.join(@@TEST_DIR, 'short-file')
|
148
148
|
LineCache::cache(test_file)
|
149
|
-
assert_equal('
|
149
|
+
assert_equal('3e1d87f3399fc73ae5683e106bce1b5ba823fc50',
|
150
150
|
LineCache::sha1(test_file))
|
151
151
|
end
|
152
152
|
|
153
|
+
def test_iseq_cache
|
154
|
+
require 'thread_frame'
|
155
|
+
template = "x=1
|
156
|
+
y=2
|
157
|
+
LineCache::getline(RubyVM::ThreadFrame.current.iseq, %d)"
|
158
|
+
assert_equal("x=1", eval(template % 1))
|
159
|
+
assert_equal("y=2", eval(template % 2))
|
160
|
+
string = "a = 1
|
161
|
+
b = 2
|
162
|
+
LineCache::map_iseq(RubyVM::ThreadFrame.current.iseq)"
|
163
|
+
temp_filename = eval(string)
|
164
|
+
got_lines = File.open(temp_filename).readlines.join('')
|
165
|
+
assert_equal(string, got_lines.chomp)
|
166
|
+
assert_equal(1, File.unlink(temp_filename))
|
167
|
+
end
|
168
|
+
|
153
169
|
end
|
metadata
CHANGED
@@ -4,8 +4,8 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
-
|
8
|
-
version: "0.
|
7
|
+
- 45
|
8
|
+
version: "0.45"
|
9
9
|
platform: ruby
|
10
10
|
authors:
|
11
11
|
- R. Bernstein
|
@@ -13,7 +13,7 @@ autorequire:
|
|
13
13
|
bindir: bin
|
14
14
|
cert_chain: []
|
15
15
|
|
16
|
-
date: 2010-
|
16
|
+
date: 2010-12-10 00:00:00 -05:00
|
17
17
|
default_executable:
|
18
18
|
dependencies:
|
19
19
|
- !ruby/object:Gem::Dependency
|
@@ -52,7 +52,6 @@ files:
|
|
52
52
|
- NEWS
|
53
53
|
- README
|
54
54
|
- Rakefile
|
55
|
-
- VERSION
|
56
55
|
- lib/tracelines.rb
|
57
56
|
- lib/linecache.rb
|
58
57
|
- test/parse-show.rb
|
@@ -91,17 +90,20 @@ files:
|
|
91
90
|
- test/short-file
|
92
91
|
has_rdoc: true
|
93
92
|
homepage: http://rubyforge.org/projects/rocky-hacks/linecache
|
94
|
-
licenses:
|
95
|
-
|
93
|
+
licenses:
|
94
|
+
- GPL2
|
96
95
|
post_install_message:
|
97
|
-
rdoc_options:
|
98
|
-
|
96
|
+
rdoc_options:
|
97
|
+
- --main
|
98
|
+
- README
|
99
|
+
- --title
|
100
|
+
- LineCache 0.45 Documentation
|
99
101
|
require_paths:
|
100
102
|
- lib
|
101
103
|
required_ruby_version: !ruby/object:Gem::Requirement
|
102
104
|
none: false
|
103
105
|
requirements:
|
104
|
-
- -
|
106
|
+
- - ~>
|
105
107
|
- !ruby/object:Gem::Version
|
106
108
|
segments:
|
107
109
|
- 1
|
@@ -118,15 +120,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
118
120
|
version: "0"
|
119
121
|
requirements: []
|
120
122
|
|
121
|
-
rubyforge_project:
|
123
|
+
rubyforge_project: columnize
|
122
124
|
rubygems_version: 1.3.7
|
123
125
|
signing_key:
|
124
126
|
specification_version: 3
|
125
|
-
summary:
|
126
|
-
test_files:
|
127
|
-
|
128
|
-
- test/lnum-diag.rb
|
129
|
-
- test/rcov-bug.rb
|
130
|
-
- test/test-lnum.rb
|
131
|
-
- test/test-linecache.rb
|
132
|
-
- test/test-tracelines.rb
|
127
|
+
summary: Module to format an Array as an Array of String aligned in columns
|
128
|
+
test_files: []
|
129
|
+
|
data/VERSION
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
0.44
|