live_ast_ripper 0.6.2 → 0.6.3
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES.rdoc +4 -0
- data/devel/levitate.rb +233 -339
- data/lib/live_ast_ripper/version.rb +1 -1
- data/lib/live_ast_ripper.rb +50 -34
- metadata +2 -3
- data/MANIFEST +0 -8
data/CHANGES.rdoc
CHANGED
data/devel/levitate.rb
CHANGED
@@ -1,231 +1,33 @@
|
|
1
1
|
|
2
2
|
class Levitate
|
3
|
-
|
4
|
-
|
5
|
-
require 'fileutils'
|
6
|
-
require 'rbconfig'
|
7
|
-
require 'find'
|
8
|
-
|
9
|
-
rb_root = RbConfig::CONFIG["sitelibdir"]
|
10
|
-
@spec = []
|
11
|
-
|
12
|
-
Find.find "lib" do |source|
|
13
|
-
next if source == "lib"
|
14
|
-
next unless File.directory?(source) || File.extname(source) == ".rb"
|
15
|
-
dest = File.join(rb_root, source.sub(%r!\Alib/!, ""))
|
16
|
-
@spec << { :source => source, :dest => dest }
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
def install
|
21
|
-
@spec.each do |entry|
|
22
|
-
source, dest = entry.values_at(:source, :dest)
|
23
|
-
if File.directory?(source)
|
24
|
-
unless File.directory?(dest)
|
25
|
-
puts "mkdir #{dest}"
|
26
|
-
FileUtils.mkdir(dest)
|
27
|
-
end
|
28
|
-
else
|
29
|
-
puts "install #{source} --> #{dest}"
|
30
|
-
FileUtils.install(source, dest)
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
def uninstall
|
36
|
-
@spec.reverse.each do |entry|
|
37
|
-
source, dest = entry.values_at(:source, :dest)
|
38
|
-
if File.directory?(source)
|
39
|
-
if File.directory?(dest)
|
40
|
-
puts "rmdir #{dest}"
|
41
|
-
FileUtils.rmdir(dest)
|
42
|
-
end
|
43
|
-
else
|
44
|
-
if File.file?(dest)
|
45
|
-
puts "rm #{dest}"
|
46
|
-
FileUtils.rm(dest)
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
module AttrLazy
|
54
|
-
def attr_lazy(name, &block)
|
55
|
-
AttrLazy.define_reader(class << self ; self ; end, name, &block)
|
56
|
-
end
|
57
|
-
|
58
|
-
def attr_lazy_accessor(name, &block)
|
59
|
-
attr_lazy(name, &block)
|
60
|
-
AttrLazy.define_writer(class << self ; self ; end, name, &block)
|
61
|
-
end
|
62
|
-
|
63
|
-
class << self
|
64
|
-
def included(mod)
|
65
|
-
(class << mod ; self ; end).class_eval do
|
66
|
-
def attr_lazy(name, &block)
|
67
|
-
AttrLazy.define_reader(self, name, &block)
|
68
|
-
end
|
69
|
-
|
70
|
-
def attr_lazy_accessor(name, &block)
|
71
|
-
attr_lazy(name, &block)
|
72
|
-
AttrLazy.define_writer(self, name, &block)
|
73
|
-
end
|
74
|
-
end
|
75
|
-
end
|
3
|
+
def initialize(gem_name)
|
4
|
+
@gem_name = gem_name
|
76
5
|
|
77
|
-
|
78
|
-
(class << instance ; self ; end).class_eval do
|
79
|
-
remove_method name rescue nil
|
80
|
-
define_method name do
|
81
|
-
value
|
82
|
-
end
|
83
|
-
end
|
84
|
-
end
|
6
|
+
$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')
|
85
7
|
|
86
|
-
|
87
|
-
klass.class_eval do
|
88
|
-
remove_method name rescue nil
|
89
|
-
define_method name do
|
90
|
-
value = instance_eval(&block)
|
91
|
-
AttrLazy.define_evaluated_reader(self, name, value)
|
92
|
-
value
|
93
|
-
end
|
94
|
-
end
|
95
|
-
end
|
8
|
+
yield self
|
96
9
|
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
remove_method writer rescue nil
|
101
|
-
define_method writer do |value|
|
102
|
-
AttrLazy.define_evaluated_reader(self, name, value)
|
103
|
-
value
|
104
|
-
end
|
105
|
-
end
|
10
|
+
self.class.instance_methods(false).each do |name|
|
11
|
+
if name.to_s =~ %r!\Adefine_!
|
12
|
+
send(name)
|
106
13
|
end
|
107
14
|
end
|
108
15
|
end
|
109
16
|
|
110
|
-
|
111
|
-
module_function
|
112
|
-
|
113
|
-
def executable
|
114
|
-
require 'rbconfig'
|
115
|
-
|
116
|
-
name = File.join(
|
117
|
-
RbConfig::CONFIG["bindir"],
|
118
|
-
RbConfig::CONFIG["RUBY_INSTALL_NAME"]
|
119
|
-
)
|
17
|
+
attr_reader :gem_name
|
120
18
|
|
121
|
-
|
122
|
-
|
123
|
-
|
19
|
+
def self.attribute(name, &block)
|
20
|
+
var = :"@#{name}"
|
21
|
+
define_method name do
|
22
|
+
if instance_variable_defined?(var)
|
23
|
+
instance_variable_get(var)
|
124
24
|
else
|
125
|
-
|
126
|
-
end
|
127
|
-
end
|
128
|
-
|
129
|
-
def run(*args)
|
130
|
-
cmd = [executable, *args]
|
131
|
-
unless system(*cmd)
|
132
|
-
cmd_str = cmd.map { |t| "'#{t}'" }.join(", ")
|
133
|
-
raise "system(#{cmd_str}) failed with status #{$?.exitstatus}"
|
134
|
-
end
|
135
|
-
end
|
136
|
-
|
137
|
-
def run_code_and_capture(code)
|
138
|
-
IO.popen(%{"#{executable}"}, "r+") { |pipe|
|
139
|
-
pipe.print(code)
|
140
|
-
pipe.flush
|
141
|
-
pipe.close_write
|
142
|
-
pipe.read
|
143
|
-
}
|
144
|
-
end
|
145
|
-
|
146
|
-
def run_file_and_capture(file)
|
147
|
-
unless File.file? file
|
148
|
-
raise "file does not exist: `#{file}'"
|
149
|
-
end
|
150
|
-
IO.popen(%{"#{executable}" "#{file}"}, "r") { |pipe|
|
151
|
-
pipe.read
|
152
|
-
}
|
153
|
-
end
|
154
|
-
|
155
|
-
def with_warnings(value = true)
|
156
|
-
previous = $VERBOSE
|
157
|
-
$VERBOSE = value
|
158
|
-
begin
|
159
|
-
yield
|
160
|
-
ensure
|
161
|
-
$VERBOSE = previous
|
25
|
+
instance_variable_set(var, instance_eval(&block))
|
162
26
|
end
|
163
27
|
end
|
164
|
-
|
165
|
-
def no_warnings(&block)
|
166
|
-
with_warnings(nil, &block)
|
167
|
-
end
|
28
|
+
attr_writer name
|
168
29
|
end
|
169
30
|
|
170
|
-
module Util
|
171
|
-
module_function
|
172
|
-
|
173
|
-
def run_ruby_on_each(*files)
|
174
|
-
files.each { |file|
|
175
|
-
Ruby.run("-w", file)
|
176
|
-
}
|
177
|
-
end
|
178
|
-
|
179
|
-
def to_camel_case(str)
|
180
|
-
str.split('_').map { |t| t.capitalize }.join
|
181
|
-
end
|
182
|
-
|
183
|
-
def write_file(file)
|
184
|
-
contents = yield
|
185
|
-
File.open(file, "wb") { |out|
|
186
|
-
out.print(contents)
|
187
|
-
}
|
188
|
-
contents
|
189
|
-
end
|
190
|
-
|
191
|
-
def instance_exec2(obj, *args, &block)
|
192
|
-
method_name = ["_", obj.object_id, "_", Thread.current.object_id].join
|
193
|
-
(class << obj ; self ; end).class_eval do
|
194
|
-
define_method method_name, &block
|
195
|
-
begin
|
196
|
-
obj.send(method_name, *args)
|
197
|
-
ensure
|
198
|
-
remove_method method_name
|
199
|
-
end
|
200
|
-
end
|
201
|
-
end
|
202
|
-
end
|
203
|
-
|
204
|
-
include AttrLazy
|
205
|
-
include Util
|
206
|
-
|
207
|
-
def initialize(gem_name)
|
208
|
-
$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')
|
209
|
-
|
210
|
-
require 'rubygems/package_task'
|
211
|
-
|
212
|
-
@gem_name = gem_name
|
213
|
-
|
214
|
-
yield self
|
215
|
-
|
216
|
-
self.class.instance_methods(false).select { |t|
|
217
|
-
t.to_s =~ %r!\Adefine_!
|
218
|
-
}.sort.each { |method_name|
|
219
|
-
send(method_name)
|
220
|
-
}
|
221
|
-
end
|
222
|
-
|
223
|
-
class << self
|
224
|
-
alias_method :attribute, :attr_lazy_accessor
|
225
|
-
end
|
226
|
-
|
227
|
-
attr_reader :gem_name
|
228
|
-
|
229
31
|
attribute :version_constant_name do
|
230
32
|
"VERSION"
|
231
33
|
end
|
@@ -288,16 +90,10 @@ class Levitate
|
|
288
90
|
"spec.html"
|
289
91
|
end
|
290
92
|
|
291
|
-
|
93
|
+
attribute :spec_output do
|
292
94
|
"#{spec_output_dir}/#{spec_output_file}"
|
293
95
|
end
|
294
96
|
|
295
|
-
[:gem, :tgz].each { |ext|
|
296
|
-
attribute ext do
|
297
|
-
"pkg/#{gem_name}-#{version}.#{ext}"
|
298
|
-
end
|
299
|
-
}
|
300
|
-
|
301
97
|
attribute :rcov_options do
|
302
98
|
# workaround for the default rspec task
|
303
99
|
Dir["*"].select { |f| File.directory? f }.inject(Array.new) { |acc, dir|
|
@@ -309,14 +105,6 @@ class Levitate
|
|
309
105
|
} + ["--text-report"]
|
310
106
|
end
|
311
107
|
|
312
|
-
attribute :readme_file do
|
313
|
-
"README.rdoc"
|
314
|
-
end
|
315
|
-
|
316
|
-
attribute :manifest_file do
|
317
|
-
"MANIFEST"
|
318
|
-
end
|
319
|
-
|
320
108
|
attribute :generated_files do
|
321
109
|
[]
|
322
110
|
end
|
@@ -326,17 +114,9 @@ class Levitate
|
|
326
114
|
end
|
327
115
|
|
328
116
|
attribute :files do
|
329
|
-
if
|
330
|
-
File.read(manifest_file).split("\n")
|
331
|
-
elsif source_control?
|
117
|
+
if source_control?
|
332
118
|
IO.popen("git ls-files") { |pipe| pipe.read.split "\n" }
|
333
|
-
end.to_a +
|
334
|
-
end
|
335
|
-
|
336
|
-
def files_in_require_paths
|
337
|
-
require_paths.inject([]) { |acc, dir|
|
338
|
-
acc + Dir.glob("#{dir}/**/*.rb")
|
339
|
-
}
|
119
|
+
end.to_a + generated_files
|
340
120
|
end
|
341
121
|
|
342
122
|
attribute :rdoc_files do
|
@@ -380,8 +160,6 @@ class Levitate
|
|
380
160
|
attribute :gemspec do
|
381
161
|
Gem::Specification.new do |g|
|
382
162
|
%w[
|
383
|
-
authors
|
384
|
-
email
|
385
163
|
summary
|
386
164
|
version
|
387
165
|
description
|
@@ -390,7 +168,6 @@ class Levitate
|
|
390
168
|
extra_rdoc_files
|
391
169
|
require_paths
|
392
170
|
required_ruby_version
|
393
|
-
extensions
|
394
171
|
].each do |param|
|
395
172
|
t = send(param) and g.send("#{param}=", t)
|
396
173
|
end
|
@@ -403,6 +180,8 @@ class Levitate
|
|
403
180
|
development_dependencies.each { |dep|
|
404
181
|
g.add_development_dependency(*dep)
|
405
182
|
}
|
183
|
+
g.authors = developers.map { |d| d[0] }
|
184
|
+
g.email = developers.map { |d| d[1] }
|
406
185
|
extra_gemspec.call(g)
|
407
186
|
end
|
408
187
|
end
|
@@ -467,14 +246,6 @@ class Levitate
|
|
467
246
|
nil
|
468
247
|
end
|
469
248
|
|
470
|
-
def authors
|
471
|
-
developers.map { |d| d[0] }
|
472
|
-
end
|
473
|
-
|
474
|
-
def email
|
475
|
-
developers.map { |d| d[1] }
|
476
|
-
end
|
477
|
-
|
478
249
|
attribute :dependencies do
|
479
250
|
[]
|
480
251
|
end
|
@@ -487,17 +258,18 @@ class Levitate
|
|
487
258
|
[]
|
488
259
|
end
|
489
260
|
|
490
|
-
attribute :
|
491
|
-
["
|
261
|
+
attribute :remote_levitate do
|
262
|
+
url = ENV["LEVITATE"] ||
|
263
|
+
"https://github.com/quix/levitate/raw/master/levitate.rb"
|
264
|
+
IO.popen("curl -s #{url}") { |f| f.read }
|
492
265
|
end
|
493
|
-
|
494
|
-
attribute :
|
495
|
-
|
496
|
-
require 'rbconfig'
|
497
|
-
"lib/" + gem_name + "." + RbConfig::CONFIG["DLEXT"]
|
498
|
-
end
|
266
|
+
|
267
|
+
attribute :local_levitate do
|
268
|
+
File.open(__FILE__, "rb") { |f| f.read }
|
499
269
|
end
|
500
270
|
|
271
|
+
#### tasks
|
272
|
+
|
501
273
|
def define_clean
|
502
274
|
require 'rake/clean'
|
503
275
|
task :clean do
|
@@ -507,10 +279,8 @@ class Levitate
|
|
507
279
|
|
508
280
|
def define_package
|
509
281
|
if source_control?
|
510
|
-
|
511
|
-
|
512
|
-
end
|
513
|
-
CLEAN.add manifest_file
|
282
|
+
require 'rubygems/package_task'
|
283
|
+
|
514
284
|
task :package => :clean
|
515
285
|
Gem::PackageTask.new(gemspec).define
|
516
286
|
end
|
@@ -518,7 +288,7 @@ class Levitate
|
|
518
288
|
|
519
289
|
def define_spec
|
520
290
|
unless spec_files.empty?
|
521
|
-
|
291
|
+
no_warnings {
|
522
292
|
require 'spec/rake/spectask'
|
523
293
|
}
|
524
294
|
|
@@ -550,7 +320,7 @@ class Levitate
|
|
550
320
|
|
551
321
|
desc "run specs individually"
|
552
322
|
task :spec_deps do
|
553
|
-
|
323
|
+
run_each_file(*spec_files)
|
554
324
|
end
|
555
325
|
|
556
326
|
task :prerelease => [:spec, :spec_deps]
|
@@ -606,7 +376,7 @@ class Levitate
|
|
606
376
|
|
607
377
|
desc "run tests individually"
|
608
378
|
task :test_deps do
|
609
|
-
|
379
|
+
run_each_file(*test_files)
|
610
380
|
end
|
611
381
|
|
612
382
|
task :prerelease => [:test, :test_deps]
|
@@ -619,7 +389,7 @@ class Levitate
|
|
619
389
|
def define_doc
|
620
390
|
desc "run rdoc"
|
621
391
|
task :doc => :clean_doc do
|
622
|
-
|
392
|
+
gem 'rdoc' rescue nil
|
623
393
|
require 'rdoc/rdoc'
|
624
394
|
args = (
|
625
395
|
gemspec.rdoc_options +
|
@@ -648,6 +418,7 @@ class Levitate
|
|
648
418
|
if source_control?
|
649
419
|
desc "publish docs"
|
650
420
|
task :publish => [:clean, :check_directory, :doc] do
|
421
|
+
current_branch = `git branch`[/^\* (\S+)$/, 1] or raise "??? branch"
|
651
422
|
if rubyforge_info
|
652
423
|
user, project = rubyforge_info
|
653
424
|
Dir.chdir(doc_dir) do
|
@@ -666,6 +437,7 @@ class Levitate
|
|
666
437
|
FileUtils.rmdir "doc"
|
667
438
|
git "add", "."
|
668
439
|
git "commit", "-m", "generated by rdoc"
|
440
|
+
git "checkout", current_branch
|
669
441
|
git "push", "-f", "origin", "gh-pages"
|
670
442
|
end
|
671
443
|
end
|
@@ -681,22 +453,6 @@ class Levitate
|
|
681
453
|
task :uninstall do
|
682
454
|
Installer.new.uninstall
|
683
455
|
end
|
684
|
-
|
685
|
-
if so_file
|
686
|
-
dest = File.join(RbConfig::CONFIG["sitearchdir"], File.basename(so_file))
|
687
|
-
|
688
|
-
task :install => so_file do
|
689
|
-
puts "install #{so_file} --> #{dest}"
|
690
|
-
FileUtils.install(so_file, dest)
|
691
|
-
end
|
692
|
-
|
693
|
-
task :uninstall do
|
694
|
-
if File.file?(dest)
|
695
|
-
puts "rm #{dest}"
|
696
|
-
FileUtils.rm(dest)
|
697
|
-
end
|
698
|
-
end
|
699
|
-
end
|
700
456
|
end
|
701
457
|
|
702
458
|
def define_check_directory
|
@@ -710,7 +466,10 @@ class Levitate
|
|
710
466
|
def define_ping
|
711
467
|
task :ping do
|
712
468
|
require 'rbconfig'
|
713
|
-
|
469
|
+
[
|
470
|
+
"github.com",
|
471
|
+
("rubyforge.org" if rubyforge_info),
|
472
|
+
].compact.each do |server|
|
714
473
|
cmd = "ping " + (
|
715
474
|
if RbConfig::CONFIG["host"] =~ %r!darwin!
|
716
475
|
"-c2 #{server}"
|
@@ -721,23 +480,26 @@ class Levitate
|
|
721
480
|
unless `#{cmd}` =~ %r!0% packet loss!
|
722
481
|
raise "No ping for #{server}"
|
723
482
|
end
|
724
|
-
|
483
|
+
end
|
484
|
+
end
|
485
|
+
end
|
486
|
+
|
487
|
+
def define_check_levitate
|
488
|
+
task :check_levitate do
|
489
|
+
unless local_levitate == remote_levitate
|
490
|
+
raise "levitate is out of date"
|
491
|
+
end
|
725
492
|
end
|
726
493
|
end
|
727
494
|
|
728
495
|
def define_update_levitate
|
729
|
-
url = ENV["LEVITATE"] ||
|
730
|
-
"https://github.com/quix/levitate/raw/master/levitate.rb"
|
731
496
|
task :update_levitate do
|
732
|
-
if
|
733
|
-
|
734
|
-
puts "Already up-to-date."
|
735
|
-
else
|
736
|
-
git "commit", __FILE__, "-m", "updated levitate"
|
737
|
-
puts "Updated levitate."
|
738
|
-
end
|
497
|
+
if local_levitate == remote_levitate
|
498
|
+
puts "Already up-to-date."
|
739
499
|
else
|
740
|
-
|
500
|
+
File.open(__FILE__, "w") { |f| f.print(remote_levitate) }
|
501
|
+
git "commit", __FILE__, "-m", "update levitate"
|
502
|
+
puts "Updated levitate."
|
741
503
|
end
|
742
504
|
end
|
743
505
|
end
|
@@ -762,30 +524,22 @@ class Levitate
|
|
762
524
|
end
|
763
525
|
end
|
764
526
|
|
765
|
-
def last_release
|
766
|
-
`git tag`.lines.select { |t| t.index(gem_name) == 0 }.last.chomp
|
767
|
-
end
|
768
|
-
|
769
|
-
def git(*args)
|
770
|
-
sh "git", *args
|
771
|
-
end
|
772
|
-
|
773
|
-
def create_manifest
|
774
|
-
write_file(manifest_file) {
|
775
|
-
files.sort.join("\n")
|
776
|
-
}
|
777
|
-
end
|
778
|
-
|
779
527
|
def define_release
|
780
|
-
task :prerelease => [
|
528
|
+
task :prerelease => [
|
529
|
+
:clean,
|
530
|
+
:check_directory,
|
531
|
+
:check_levitate,
|
532
|
+
:ping,
|
533
|
+
history_file
|
534
|
+
]
|
781
535
|
|
782
536
|
task :finish_release do
|
783
537
|
git "tag", "#{gem_name}-" + version.to_s
|
784
538
|
git "push", "--tags", "origin", "master"
|
785
|
-
sh "gem", "push", gem
|
539
|
+
sh "gem", "push", "pkg/#{gem_name}-#{version}.gem"
|
786
540
|
end
|
787
541
|
|
788
|
-
task :release => [:prerelease, :package, :finish_release]
|
542
|
+
task :release => [:prerelease, :package, :finish_release, :publish]
|
789
543
|
end
|
790
544
|
|
791
545
|
def define_debug_gem
|
@@ -794,34 +548,22 @@ class Levitate
|
|
794
548
|
end
|
795
549
|
end
|
796
550
|
|
797
|
-
|
798
|
-
if so_file and (source_control? or !File.file?(so_file))
|
799
|
-
require 'rbconfig'
|
800
|
-
require 'rake/extensiontask'
|
801
|
-
|
802
|
-
Rake::ExtensionTask.new gem_name, gemspec do |ext|
|
803
|
-
ext.cross_compile = true
|
804
|
-
ext.cross_platform = 'i386-mswin32'
|
805
|
-
ext.cross_compiling do |gemspec|
|
806
|
-
gemspec.post_install_message =
|
807
|
-
"U got dat binary versionation of this gemination!"
|
808
|
-
end
|
809
|
-
end
|
551
|
+
#### helpers
|
810
552
|
|
811
|
-
|
812
|
-
|
813
|
-
|
553
|
+
def files_in_require_paths
|
554
|
+
require_paths.inject([]) { |acc, dir|
|
555
|
+
acc + Dir.glob("#{dir}/**/*.rb")
|
556
|
+
}
|
557
|
+
end
|
814
558
|
|
815
|
-
|
816
|
-
|
817
|
-
|
818
|
-
Rake.application.top_level
|
819
|
-
end
|
559
|
+
def last_release
|
560
|
+
`git tag`.lines.select { |t| t.index(gem_name) == 0 }.last.chomp
|
561
|
+
end
|
820
562
|
|
821
|
-
|
822
|
-
|
563
|
+
def git(*args)
|
564
|
+
sh "git", *args
|
823
565
|
end
|
824
|
-
|
566
|
+
|
825
567
|
def open_browser(*files)
|
826
568
|
sh(*([browser].flatten + files))
|
827
569
|
end
|
@@ -830,7 +572,7 @@ class Levitate
|
|
830
572
|
task_names.each { |task_name|
|
831
573
|
Rake::Task[task_name].actions.map! { |action|
|
832
574
|
lambda { |*args|
|
833
|
-
|
575
|
+
no_warnings {
|
834
576
|
action.call(*args)
|
835
577
|
}
|
836
578
|
}
|
@@ -846,10 +588,110 @@ class Levitate
|
|
846
588
|
File.directory? ".git"
|
847
589
|
end
|
848
590
|
|
849
|
-
|
850
|
-
|
591
|
+
#### utility for instance and class
|
592
|
+
|
593
|
+
module Util
|
594
|
+
def ruby_bin
|
595
|
+
require 'rbconfig'
|
596
|
+
|
597
|
+
name = File.join(
|
598
|
+
RbConfig::CONFIG["bindir"],
|
599
|
+
RbConfig::CONFIG["RUBY_INSTALL_NAME"]
|
600
|
+
)
|
601
|
+
|
602
|
+
if RbConfig::CONFIG["host"] =~ %r!(mswin|cygwin|mingw)! and
|
603
|
+
File.basename(name) !~ %r!\.(exe|com|bat|cmd)\Z!i
|
604
|
+
name + RbConfig::CONFIG["EXEEXT"]
|
605
|
+
else
|
606
|
+
name
|
607
|
+
end
|
608
|
+
end
|
609
|
+
|
610
|
+
def ruby_command
|
611
|
+
[ruby_bin] + Levitate.ruby_opts.to_a
|
612
|
+
end
|
613
|
+
|
614
|
+
def ruby_command_string
|
615
|
+
ruby_command.join(" ")
|
616
|
+
end
|
617
|
+
|
618
|
+
def run(*args)
|
619
|
+
cmd = ruby_command + args
|
620
|
+
unless system(*cmd)
|
621
|
+
cmd_str = cmd.map { |t| "'#{t}'" }.join(", ")
|
622
|
+
raise "system(#{cmd_str}) failed with status #{$?.exitstatus}"
|
623
|
+
end
|
624
|
+
end
|
625
|
+
|
626
|
+
def run_each_file(*files)
|
627
|
+
files.each { |file|
|
628
|
+
run("-w", file)
|
629
|
+
}
|
630
|
+
end
|
851
631
|
|
852
|
-
|
632
|
+
def run_code_and_capture(code)
|
633
|
+
IO.popen(ruby_command_string, "r+") { |pipe|
|
634
|
+
pipe.print(code)
|
635
|
+
pipe.flush
|
636
|
+
pipe.close_write
|
637
|
+
pipe.read
|
638
|
+
}
|
639
|
+
end
|
640
|
+
|
641
|
+
def run_file_and_capture(file)
|
642
|
+
unless File.file? file
|
643
|
+
raise "file does not exist: `#{file}'"
|
644
|
+
end
|
645
|
+
IO.popen(ruby_command_string + " " + file, "r") { |pipe|
|
646
|
+
pipe.read
|
647
|
+
}
|
648
|
+
end
|
649
|
+
|
650
|
+
def with_warnings(value = true)
|
651
|
+
previous = $VERBOSE
|
652
|
+
$VERBOSE = value
|
653
|
+
begin
|
654
|
+
yield
|
655
|
+
ensure
|
656
|
+
$VERBOSE = previous
|
657
|
+
end
|
658
|
+
end
|
659
|
+
|
660
|
+
def no_warnings(&block)
|
661
|
+
with_warnings(nil, &block)
|
662
|
+
end
|
663
|
+
|
664
|
+
def to_camel_case(str)
|
665
|
+
str.split('_').map { |t| t.capitalize }.join
|
666
|
+
end
|
667
|
+
|
668
|
+
def write_file(file)
|
669
|
+
contents = yield
|
670
|
+
File.open(file, "wb") { |out|
|
671
|
+
out.print(contents)
|
672
|
+
}
|
673
|
+
contents
|
674
|
+
end
|
675
|
+
|
676
|
+
def instance_exec2(obj, *args, &block)
|
677
|
+
method_name = ["_", obj.object_id, "_", Thread.current.object_id].join
|
678
|
+
(class << obj ; self ; end).class_eval do
|
679
|
+
define_method method_name, &block
|
680
|
+
begin
|
681
|
+
obj.send(method_name, *args)
|
682
|
+
ensure
|
683
|
+
remove_method method_name
|
684
|
+
end
|
685
|
+
end
|
686
|
+
end
|
687
|
+
end
|
688
|
+
extend Util
|
689
|
+
include Util
|
690
|
+
|
691
|
+
#### public helpers for testing
|
692
|
+
|
693
|
+
class << self
|
694
|
+
# From 'minitest' by Ryan Davis.
|
853
695
|
def capture_io
|
854
696
|
require 'stringio'
|
855
697
|
|
@@ -884,7 +726,7 @@ class Levitate
|
|
884
726
|
Tempfile.open("run-rdoc-code") { |temp_file|
|
885
727
|
temp_file.print(final_code)
|
886
728
|
temp_file.close
|
887
|
-
actual =
|
729
|
+
actual = run_file_and_capture(temp_file.path).chomp
|
888
730
|
}
|
889
731
|
|
890
732
|
instance_exec2(instance, expected, actual, index, &block)
|
@@ -954,5 +796,57 @@ class Levitate
|
|
954
796
|
end
|
955
797
|
Object.const_set("Test#{file}".gsub(".", ""), klass)
|
956
798
|
end
|
799
|
+
|
800
|
+
def ruby_opts
|
801
|
+
@ruby_opts ||= []
|
802
|
+
end
|
803
|
+
attr_writer :ruby_opts
|
804
|
+
end
|
805
|
+
|
806
|
+
#### raw install, bypass gems
|
807
|
+
|
808
|
+
class Installer
|
809
|
+
def initialize
|
810
|
+
require 'fileutils'
|
811
|
+
require 'rbconfig'
|
812
|
+
require 'find'
|
813
|
+
|
814
|
+
@fu = FileUtils::Verbose
|
815
|
+
@spec = []
|
816
|
+
|
817
|
+
rb_root = RbConfig::CONFIG["sitelibdir"]
|
818
|
+
|
819
|
+
Find.find "lib" do |source|
|
820
|
+
next if source == "lib"
|
821
|
+
next unless File.directory?(source) || File.extname(source) == ".rb"
|
822
|
+
dest = File.join(rb_root, source.sub(%r!\Alib/!, ""))
|
823
|
+
@spec << [source, dest]
|
824
|
+
end
|
825
|
+
end
|
826
|
+
|
827
|
+
def install
|
828
|
+
@spec.each do |source, dest|
|
829
|
+
if File.directory?(source)
|
830
|
+
@fu.mkdir(dest) unless File.directory?(dest)
|
831
|
+
else
|
832
|
+
@fu.install(source, dest)
|
833
|
+
end
|
834
|
+
end
|
835
|
+
end
|
836
|
+
|
837
|
+
def uninstall
|
838
|
+
@spec.reverse.each do |source, dest|
|
839
|
+
if File.directory?(source)
|
840
|
+
@fu.rmdir(dest) if File.directory?(dest)
|
841
|
+
else
|
842
|
+
@fu.rm(dest) if File.file?(dest)
|
843
|
+
end
|
844
|
+
end
|
845
|
+
end
|
957
846
|
end
|
958
847
|
end
|
848
|
+
|
849
|
+
lambda do
|
850
|
+
config = File.join(File.dirname(__FILE__), "levitate_config.rb")
|
851
|
+
require config if File.file? config
|
852
|
+
end.call
|
data/lib/live_ast_ripper.rb
CHANGED
@@ -6,7 +6,7 @@ require 'ripper'
|
|
6
6
|
#
|
7
7
|
class LiveASTRipper
|
8
8
|
#
|
9
|
-
# Returns a line-to-
|
9
|
+
# Returns a line-to-AST hash where the AST corresponds to the method
|
10
10
|
# or block defined at the given line.
|
11
11
|
#
|
12
12
|
# This method is the only requirement of a LiveAST parser plugin.
|
@@ -17,52 +17,68 @@ class LiveASTRipper
|
|
17
17
|
@defs
|
18
18
|
end
|
19
19
|
|
20
|
-
def process(sexp)
|
21
|
-
line =
|
22
|
-
case sexp.first
|
23
|
-
when :def
|
24
|
-
sexp[1][2][0]
|
25
|
-
when :method_add_block
|
26
|
-
case sexp[1][0]
|
27
|
-
when :method_add_arg
|
28
|
-
sexp[1][1][1].last[0]
|
29
|
-
when :call, :command_call
|
30
|
-
sexp[1][3][2][0]
|
31
|
-
when :command
|
32
|
-
sexp[1][1][2][0]
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
if line
|
20
|
+
def process(sexp) #:nodoc:
|
21
|
+
line = line_of(sexp) and
|
37
22
|
@defs[line] = @defs.has_key?(line) ? :multiple : sexp
|
38
|
-
end
|
39
23
|
|
40
|
-
|
24
|
+
LiveASTRipper.steamroll_toplevel(sexp) if LiveASTRipper.steamroll
|
41
25
|
|
42
26
|
sexp.each do |elem|
|
43
27
|
process(elem) if elem.is_a? Array
|
44
28
|
end
|
45
29
|
end
|
46
30
|
|
47
|
-
def
|
48
|
-
|
49
|
-
|
50
|
-
sexp
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
when :
|
56
|
-
|
57
|
-
|
58
|
-
|
31
|
+
def line_of(sexp) #:nodoc:
|
32
|
+
case sexp.first
|
33
|
+
when :def
|
34
|
+
sexp[1][2][0]
|
35
|
+
when :method_add_block
|
36
|
+
case sexp[1][0]
|
37
|
+
when :method_add_arg
|
38
|
+
sexp[1][1][1].last[0]
|
39
|
+
when :call, :command_call
|
40
|
+
sexp[1][3][2][0]
|
41
|
+
when :command
|
42
|
+
sexp[1][1][2][0]
|
59
43
|
end
|
60
|
-
|
44
|
+
end
|
61
45
|
end
|
62
46
|
|
63
47
|
class << self
|
48
|
+
def steamroll_toplevel(sexp) #:nodoc:
|
49
|
+
# remove [line, column]
|
50
|
+
if sexp.first.is_a?(Symbol) and sexp.first[0] == "@"
|
51
|
+
sexp.pop
|
52
|
+
end
|
53
|
+
|
54
|
+
sexp.map! { |elem|
|
55
|
+
case elem
|
56
|
+
when :brace_block, :do_block
|
57
|
+
:block
|
58
|
+
else
|
59
|
+
elem
|
60
|
+
end
|
61
|
+
}
|
62
|
+
end
|
63
|
+
|
64
|
+
#
|
65
|
+
# Destructive operation on +ast+:
|
66
|
+
#
|
67
|
+
# * remove [line, column] pairs
|
68
|
+
# * change +:brace_block+ and +:do_block+ to +:block+
|
69
|
+
#
|
70
|
+
def steamroll_ast(ast)
|
71
|
+
steamroll_toplevel(ast)
|
72
|
+
ast.each do |elem|
|
73
|
+
steamroll_ast(elem) if elem.is_a? Array
|
74
|
+
end
|
75
|
+
ast
|
76
|
+
end
|
77
|
+
|
64
78
|
#
|
65
|
-
#
|
79
|
+
# When true-valued, steamroll all ASTs created by the parser.
|
80
|
+
# Default is +false+. (Although referencing
|
81
|
+
# <code>LiveASTRipper::Test</code> will set it to +true+.)
|
66
82
|
#
|
67
83
|
attr_accessor :steamroll
|
68
84
|
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: live_ast_ripper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.6.
|
5
|
+
version: 0.6.3
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- James M. Lawrence
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-03-
|
13
|
+
date: 2011-03-21 00:00:00 -04:00
|
14
14
|
default_executable:
|
15
15
|
dependencies: []
|
16
16
|
|
@@ -32,7 +32,6 @@ files:
|
|
32
32
|
- lib/live_ast_ripper.rb
|
33
33
|
- lib/live_ast_ripper/test.rb
|
34
34
|
- lib/live_ast_ripper/version.rb
|
35
|
-
- MANIFEST
|
36
35
|
has_rdoc: true
|
37
36
|
homepage: http://quix.github.com/live_ast_ripper
|
38
37
|
licenses: []
|