live_ast_ripper 0.6.3 → 0.6.4
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES.rdoc +4 -0
- data/MANIFEST +8 -0
- data/devel/levitate.rb +339 -233
- data/lib/live_ast_ripper/test.rb +50 -0
- data/lib/live_ast_ripper/version.rb +1 -1
- data/lib/live_ast_ripper.rb +2 -0
- metadata +4 -5
data/CHANGES.rdoc
CHANGED
data/MANIFEST
ADDED
data/devel/levitate.rb
CHANGED
@@ -1,33 +1,231 @@
|
|
1
1
|
|
2
2
|
class Levitate
|
3
|
-
|
4
|
-
|
3
|
+
class Installer
|
4
|
+
def initialize
|
5
|
+
require 'fileutils'
|
6
|
+
require 'rbconfig'
|
7
|
+
require 'find'
|
5
8
|
|
6
|
-
|
9
|
+
rb_root = RbConfig::CONFIG["sitelibdir"]
|
10
|
+
@spec = []
|
7
11
|
|
8
|
-
|
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
|
9
57
|
|
10
|
-
|
11
|
-
|
12
|
-
|
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
|
76
|
+
|
77
|
+
def define_evaluated_reader(instance, name, value)
|
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
|
85
|
+
|
86
|
+
def define_reader(klass, name, &block)
|
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
|
96
|
+
|
97
|
+
def define_writer(klass, name, &block)
|
98
|
+
klass.class_eval do
|
99
|
+
writer = "#{name}="
|
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
|
13
106
|
end
|
14
107
|
end
|
15
108
|
end
|
16
109
|
|
17
|
-
|
110
|
+
module Ruby
|
111
|
+
module_function
|
18
112
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
113
|
+
def executable
|
114
|
+
require 'rbconfig'
|
115
|
+
|
116
|
+
name = File.join(
|
117
|
+
RbConfig::CONFIG["bindir"],
|
118
|
+
RbConfig::CONFIG["RUBY_INSTALL_NAME"]
|
119
|
+
)
|
120
|
+
|
121
|
+
if RbConfig::CONFIG["host"] =~ %r!(mswin|cygwin|mingw)! and
|
122
|
+
File.basename(name) !~ %r!\.(exe|com|bat|cmd)\Z!i
|
123
|
+
name + RbConfig::CONFIG["EXEEXT"]
|
24
124
|
else
|
25
|
-
|
125
|
+
name
|
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
|
26
162
|
end
|
27
163
|
end
|
28
|
-
|
164
|
+
|
165
|
+
def no_warnings(&block)
|
166
|
+
with_warnings(nil, &block)
|
167
|
+
end
|
29
168
|
end
|
30
169
|
|
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
|
+
|
31
229
|
attribute :version_constant_name do
|
32
230
|
"VERSION"
|
33
231
|
end
|
@@ -90,10 +288,16 @@ class Levitate
|
|
90
288
|
"spec.html"
|
91
289
|
end
|
92
290
|
|
93
|
-
|
291
|
+
attr_lazy :spec_output do
|
94
292
|
"#{spec_output_dir}/#{spec_output_file}"
|
95
293
|
end
|
96
294
|
|
295
|
+
[:gem, :tgz].each { |ext|
|
296
|
+
attribute ext do
|
297
|
+
"pkg/#{gem_name}-#{version}.#{ext}"
|
298
|
+
end
|
299
|
+
}
|
300
|
+
|
97
301
|
attribute :rcov_options do
|
98
302
|
# workaround for the default rspec task
|
99
303
|
Dir["*"].select { |f| File.directory? f }.inject(Array.new) { |acc, dir|
|
@@ -105,6 +309,14 @@ class Levitate
|
|
105
309
|
} + ["--text-report"]
|
106
310
|
end
|
107
311
|
|
312
|
+
attribute :readme_file do
|
313
|
+
"README.rdoc"
|
314
|
+
end
|
315
|
+
|
316
|
+
attribute :manifest_file do
|
317
|
+
"MANIFEST"
|
318
|
+
end
|
319
|
+
|
108
320
|
attribute :generated_files do
|
109
321
|
[]
|
110
322
|
end
|
@@ -114,9 +326,17 @@ class Levitate
|
|
114
326
|
end
|
115
327
|
|
116
328
|
attribute :files do
|
117
|
-
if
|
329
|
+
if File.file? manifest_file
|
330
|
+
File.read(manifest_file).split("\n")
|
331
|
+
elsif source_control?
|
118
332
|
IO.popen("git ls-files") { |pipe| pipe.read.split "\n" }
|
119
|
-
end.to_a + generated_files
|
333
|
+
end.to_a + [manifest_file] + generated_files
|
334
|
+
end
|
335
|
+
|
336
|
+
def files_in_require_paths
|
337
|
+
require_paths.inject([]) { |acc, dir|
|
338
|
+
acc + Dir.glob("#{dir}/**/*.rb")
|
339
|
+
}
|
120
340
|
end
|
121
341
|
|
122
342
|
attribute :rdoc_files do
|
@@ -160,6 +380,8 @@ class Levitate
|
|
160
380
|
attribute :gemspec do
|
161
381
|
Gem::Specification.new do |g|
|
162
382
|
%w[
|
383
|
+
authors
|
384
|
+
email
|
163
385
|
summary
|
164
386
|
version
|
165
387
|
description
|
@@ -168,6 +390,7 @@ class Levitate
|
|
168
390
|
extra_rdoc_files
|
169
391
|
require_paths
|
170
392
|
required_ruby_version
|
393
|
+
extensions
|
171
394
|
].each do |param|
|
172
395
|
t = send(param) and g.send("#{param}=", t)
|
173
396
|
end
|
@@ -180,8 +403,6 @@ class Levitate
|
|
180
403
|
development_dependencies.each { |dep|
|
181
404
|
g.add_development_dependency(*dep)
|
182
405
|
}
|
183
|
-
g.authors = developers.map { |d| d[0] }
|
184
|
-
g.email = developers.map { |d| d[1] }
|
185
406
|
extra_gemspec.call(g)
|
186
407
|
end
|
187
408
|
end
|
@@ -246,6 +467,14 @@ class Levitate
|
|
246
467
|
nil
|
247
468
|
end
|
248
469
|
|
470
|
+
def authors
|
471
|
+
developers.map { |d| d[0] }
|
472
|
+
end
|
473
|
+
|
474
|
+
def email
|
475
|
+
developers.map { |d| d[1] }
|
476
|
+
end
|
477
|
+
|
249
478
|
attribute :dependencies do
|
250
479
|
[]
|
251
480
|
end
|
@@ -258,18 +487,17 @@ class Levitate
|
|
258
487
|
[]
|
259
488
|
end
|
260
489
|
|
261
|
-
attribute :
|
262
|
-
|
263
|
-
"https://github.com/quix/levitate/raw/master/levitate.rb"
|
264
|
-
IO.popen("curl -s #{url}") { |f| f.read }
|
490
|
+
attribute :extensions do
|
491
|
+
["ext/#{gem_name}/extconf.rb"].select { |f| File.file? f }
|
265
492
|
end
|
266
|
-
|
267
|
-
attribute :
|
268
|
-
|
493
|
+
|
494
|
+
attribute :so_file do
|
495
|
+
unless extensions.empty?
|
496
|
+
require 'rbconfig'
|
497
|
+
"lib/" + gem_name + "." + RbConfig::CONFIG["DLEXT"]
|
498
|
+
end
|
269
499
|
end
|
270
500
|
|
271
|
-
#### tasks
|
272
|
-
|
273
501
|
def define_clean
|
274
502
|
require 'rake/clean'
|
275
503
|
task :clean do
|
@@ -279,8 +507,10 @@ class Levitate
|
|
279
507
|
|
280
508
|
def define_package
|
281
509
|
if source_control?
|
282
|
-
|
283
|
-
|
510
|
+
task manifest_file do
|
511
|
+
create_manifest
|
512
|
+
end
|
513
|
+
CLEAN.add manifest_file
|
284
514
|
task :package => :clean
|
285
515
|
Gem::PackageTask.new(gemspec).define
|
286
516
|
end
|
@@ -288,7 +518,7 @@ class Levitate
|
|
288
518
|
|
289
519
|
def define_spec
|
290
520
|
unless spec_files.empty?
|
291
|
-
no_warnings {
|
521
|
+
Ruby.no_warnings {
|
292
522
|
require 'spec/rake/spectask'
|
293
523
|
}
|
294
524
|
|
@@ -320,7 +550,7 @@ class Levitate
|
|
320
550
|
|
321
551
|
desc "run specs individually"
|
322
552
|
task :spec_deps do
|
323
|
-
|
553
|
+
run_ruby_on_each(*spec_files)
|
324
554
|
end
|
325
555
|
|
326
556
|
task :prerelease => [:spec, :spec_deps]
|
@@ -376,7 +606,7 @@ class Levitate
|
|
376
606
|
|
377
607
|
desc "run tests individually"
|
378
608
|
task :test_deps do
|
379
|
-
|
609
|
+
run_ruby_on_each(*test_files)
|
380
610
|
end
|
381
611
|
|
382
612
|
task :prerelease => [:test, :test_deps]
|
@@ -389,7 +619,7 @@ class Levitate
|
|
389
619
|
def define_doc
|
390
620
|
desc "run rdoc"
|
391
621
|
task :doc => :clean_doc do
|
392
|
-
gem 'rdoc' rescue nil
|
622
|
+
Kernel.send :gem, 'rdoc' rescue nil
|
393
623
|
require 'rdoc/rdoc'
|
394
624
|
args = (
|
395
625
|
gemspec.rdoc_options +
|
@@ -418,7 +648,6 @@ class Levitate
|
|
418
648
|
if source_control?
|
419
649
|
desc "publish docs"
|
420
650
|
task :publish => [:clean, :check_directory, :doc] do
|
421
|
-
current_branch = `git branch`[/^\* (\S+)$/, 1] or raise "??? branch"
|
422
651
|
if rubyforge_info
|
423
652
|
user, project = rubyforge_info
|
424
653
|
Dir.chdir(doc_dir) do
|
@@ -437,7 +666,6 @@ class Levitate
|
|
437
666
|
FileUtils.rmdir "doc"
|
438
667
|
git "add", "."
|
439
668
|
git "commit", "-m", "generated by rdoc"
|
440
|
-
git "checkout", current_branch
|
441
669
|
git "push", "-f", "origin", "gh-pages"
|
442
670
|
end
|
443
671
|
end
|
@@ -453,6 +681,22 @@ class Levitate
|
|
453
681
|
task :uninstall do
|
454
682
|
Installer.new.uninstall
|
455
683
|
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
|
456
700
|
end
|
457
701
|
|
458
702
|
def define_check_directory
|
@@ -466,10 +710,7 @@ class Levitate
|
|
466
710
|
def define_ping
|
467
711
|
task :ping do
|
468
712
|
require 'rbconfig'
|
469
|
-
[
|
470
|
-
"github.com",
|
471
|
-
("rubyforge.org" if rubyforge_info),
|
472
|
-
].compact.each do |server|
|
713
|
+
%w[github.com].each { |server|
|
473
714
|
cmd = "ping " + (
|
474
715
|
if RbConfig::CONFIG["host"] =~ %r!darwin!
|
475
716
|
"-c2 #{server}"
|
@@ -480,26 +721,23 @@ class Levitate
|
|
480
721
|
unless `#{cmd}` =~ %r!0% packet loss!
|
481
722
|
raise "No ping for #{server}"
|
482
723
|
end
|
483
|
-
|
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
|
724
|
+
}
|
492
725
|
end
|
493
726
|
end
|
494
727
|
|
495
728
|
def define_update_levitate
|
729
|
+
url = ENV["LEVITATE"] ||
|
730
|
+
"https://github.com/quix/levitate/raw/master/levitate.rb"
|
496
731
|
task :update_levitate do
|
497
|
-
if
|
498
|
-
|
732
|
+
if system "curl", "-s", "-o", __FILE__, url
|
733
|
+
if `git diff #{__FILE__}` == ""
|
734
|
+
puts "Already up-to-date."
|
735
|
+
else
|
736
|
+
git "commit", __FILE__, "-m", "updated levitate"
|
737
|
+
puts "Updated levitate."
|
738
|
+
end
|
499
739
|
else
|
500
|
-
|
501
|
-
git "commit", __FILE__, "-m", "update levitate"
|
502
|
-
puts "Updated levitate."
|
740
|
+
raise "levitate download failed"
|
503
741
|
end
|
504
742
|
end
|
505
743
|
end
|
@@ -524,22 +762,30 @@ class Levitate
|
|
524
762
|
end
|
525
763
|
end
|
526
764
|
|
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
|
+
|
527
779
|
def define_release
|
528
|
-
task :prerelease => [
|
529
|
-
:clean,
|
530
|
-
:check_directory,
|
531
|
-
:check_levitate,
|
532
|
-
:ping,
|
533
|
-
history_file
|
534
|
-
]
|
780
|
+
task :prerelease => [:clean, :check_directory, :ping, history_file]
|
535
781
|
|
536
782
|
task :finish_release do
|
537
783
|
git "tag", "#{gem_name}-" + version.to_s
|
538
784
|
git "push", "--tags", "origin", "master"
|
539
|
-
sh "gem", "push",
|
785
|
+
sh "gem", "push", gem
|
540
786
|
end
|
541
787
|
|
542
|
-
task :release => [:prerelease, :package, :finish_release
|
788
|
+
task :release => [:prerelease, :package, :finish_release]
|
543
789
|
end
|
544
790
|
|
545
791
|
def define_debug_gem
|
@@ -548,22 +794,34 @@ class Levitate
|
|
548
794
|
end
|
549
795
|
end
|
550
796
|
|
551
|
-
|
797
|
+
def define_extension
|
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
|
552
810
|
|
553
|
-
|
554
|
-
|
555
|
-
|
556
|
-
}
|
557
|
-
end
|
811
|
+
if Rake::Task[so_file].needed?
|
812
|
+
task :test => so_file
|
813
|
+
end
|
558
814
|
|
559
|
-
|
560
|
-
|
561
|
-
|
815
|
+
task :cross_native_gem do
|
816
|
+
Rake::Task[:gem].reenable
|
817
|
+
Rake.application.top_level_tasks.replace %w[cross native gem]
|
818
|
+
Rake.application.top_level
|
819
|
+
end
|
562
820
|
|
563
|
-
|
564
|
-
|
821
|
+
task :gem => :cross_native_gem
|
822
|
+
end
|
565
823
|
end
|
566
|
-
|
824
|
+
|
567
825
|
def open_browser(*files)
|
568
826
|
sh(*([browser].flatten + files))
|
569
827
|
end
|
@@ -572,7 +830,7 @@ class Levitate
|
|
572
830
|
task_names.each { |task_name|
|
573
831
|
Rake::Task[task_name].actions.map! { |action|
|
574
832
|
lambda { |*args|
|
575
|
-
no_warnings {
|
833
|
+
Ruby.no_warnings {
|
576
834
|
action.call(*args)
|
577
835
|
}
|
578
836
|
}
|
@@ -588,110 +846,10 @@ class Levitate
|
|
588
846
|
File.directory? ".git"
|
589
847
|
end
|
590
848
|
|
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
|
631
|
-
|
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
849
|
class << self
|
694
|
-
|
850
|
+
include Util
|
851
|
+
|
852
|
+
# From minitest, part of the Ruby source; by Ryan Davis.
|
695
853
|
def capture_io
|
696
854
|
require 'stringio'
|
697
855
|
|
@@ -726,7 +884,7 @@ class Levitate
|
|
726
884
|
Tempfile.open("run-rdoc-code") { |temp_file|
|
727
885
|
temp_file.print(final_code)
|
728
886
|
temp_file.close
|
729
|
-
actual = run_file_and_capture(temp_file.path).chomp
|
887
|
+
actual = Ruby.run_file_and_capture(temp_file.path).chomp
|
730
888
|
}
|
731
889
|
|
732
890
|
instance_exec2(instance, expected, actual, index, &block)
|
@@ -796,57 +954,5 @@ class Levitate
|
|
796
954
|
end
|
797
955
|
Object.const_set("Test#{file}".gsub(".", ""), klass)
|
798
956
|
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
|
846
957
|
end
|
847
958
|
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/test.rb
CHANGED
@@ -22,6 +22,27 @@ module LiveASTRipper::Test
|
|
22
22
|
nil]]
|
23
23
|
end
|
24
24
|
|
25
|
+
#
|
26
|
+
# singleton_no_arg_def(:f, "foo") returns the ast of
|
27
|
+
#
|
28
|
+
# def self.f
|
29
|
+
# "foo"
|
30
|
+
# end
|
31
|
+
#
|
32
|
+
def singleton_no_arg_def(name, ret)
|
33
|
+
[:defs,
|
34
|
+
[:var_ref, [:@kw, "self"]],
|
35
|
+
[:@period, "."],
|
36
|
+
[:@ident, name.to_s],
|
37
|
+
[:params, nil, nil, nil, nil, nil],
|
38
|
+
[:bodystmt,
|
39
|
+
[[:string_literal,
|
40
|
+
[:string_content, [:@tstring_content, ret]]]],
|
41
|
+
nil,
|
42
|
+
nil,
|
43
|
+
nil]]
|
44
|
+
end
|
45
|
+
|
25
46
|
#
|
26
47
|
# no_arg_def_return(no_arg_def(:f, "A#f")) == "A#f"
|
27
48
|
#
|
@@ -56,6 +77,35 @@ module LiveASTRipper::Test
|
|
56
77
|
nil]]
|
57
78
|
end
|
58
79
|
|
80
|
+
#
|
81
|
+
# singleton_binop_def(:A, :f, :+) returns the ast of
|
82
|
+
#
|
83
|
+
# def A.f(x, y)
|
84
|
+
# x + y
|
85
|
+
# end
|
86
|
+
#
|
87
|
+
def singleton_binop_def(const, name, op)
|
88
|
+
[:defs,
|
89
|
+
[:var_ref, [:@const, const.to_s]],
|
90
|
+
[:@period, "."],
|
91
|
+
[:@ident, name.to_s],
|
92
|
+
[:paren,
|
93
|
+
[:params,
|
94
|
+
[[:@ident, "x"], [:@ident, "y"]],
|
95
|
+
nil,
|
96
|
+
nil,
|
97
|
+
nil,
|
98
|
+
nil]],
|
99
|
+
[:bodystmt,
|
100
|
+
[[:binary,
|
101
|
+
[:var_ref, [:@ident, "x"]],
|
102
|
+
:+,
|
103
|
+
[:var_ref, [:@ident, "y"]]]],
|
104
|
+
nil,
|
105
|
+
nil,
|
106
|
+
nil]]
|
107
|
+
end
|
108
|
+
|
59
109
|
#
|
60
110
|
# binop_define_method(:f, :*) returns the ast of
|
61
111
|
#
|
data/lib/live_ast_ripper.rb
CHANGED
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.4
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- James M. Lawrence
|
@@ -10,8 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-
|
14
|
-
default_executable:
|
13
|
+
date: 2011-05-17 00:00:00 Z
|
15
14
|
dependencies: []
|
16
15
|
|
17
16
|
description: A Ripper-based parser plugin for LiveAST.
|
@@ -32,7 +31,7 @@ files:
|
|
32
31
|
- lib/live_ast_ripper.rb
|
33
32
|
- lib/live_ast_ripper/test.rb
|
34
33
|
- lib/live_ast_ripper/version.rb
|
35
|
-
|
34
|
+
- MANIFEST
|
36
35
|
homepage: http://quix.github.com/live_ast_ripper
|
37
36
|
licenses: []
|
38
37
|
|
@@ -59,7 +58,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
59
58
|
requirements: []
|
60
59
|
|
61
60
|
rubyforge_project:
|
62
|
-
rubygems_version: 1.
|
61
|
+
rubygems_version: 1.7.1
|
63
62
|
signing_key:
|
64
63
|
specification_version: 3
|
65
64
|
summary: A Ripper-based parser plugin for LiveAST.
|