live_ast_ruby_parser 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/devel/levitate.rb +233 -340
- data/lib/live_ast_ruby_parser/version.rb +1 -1
- metadata +2 -3
- data/MANIFEST +0 -9
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,12 +168,10 @@ 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
|
397
174
|
g.name = gem_name
|
398
|
-
g.has_rdoc = true
|
399
175
|
g.homepage = url if url
|
400
176
|
dependencies.each { |dep|
|
401
177
|
g.add_dependency(*dep)
|
@@ -403,6 +179,8 @@ class Levitate
|
|
403
179
|
development_dependencies.each { |dep|
|
404
180
|
g.add_development_dependency(*dep)
|
405
181
|
}
|
182
|
+
g.authors = developers.map { |d| d[0] }
|
183
|
+
g.email = developers.map { |d| d[1] }
|
406
184
|
extra_gemspec.call(g)
|
407
185
|
end
|
408
186
|
end
|
@@ -467,14 +245,6 @@ class Levitate
|
|
467
245
|
nil
|
468
246
|
end
|
469
247
|
|
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
248
|
attribute :dependencies do
|
479
249
|
[]
|
480
250
|
end
|
@@ -487,17 +257,18 @@ class Levitate
|
|
487
257
|
[]
|
488
258
|
end
|
489
259
|
|
490
|
-
attribute :
|
491
|
-
["
|
260
|
+
attribute :remote_levitate do
|
261
|
+
url = ENV["LEVITATE"] ||
|
262
|
+
"https://github.com/quix/levitate/raw/master/levitate.rb"
|
263
|
+
IO.popen("curl -s #{url}") { |f| f.read }
|
492
264
|
end
|
493
|
-
|
494
|
-
attribute :
|
495
|
-
|
496
|
-
require 'rbconfig'
|
497
|
-
"lib/" + gem_name + "." + RbConfig::CONFIG["DLEXT"]
|
498
|
-
end
|
265
|
+
|
266
|
+
attribute :local_levitate do
|
267
|
+
File.open(__FILE__, "rb") { |f| f.read }
|
499
268
|
end
|
500
269
|
|
270
|
+
#### tasks
|
271
|
+
|
501
272
|
def define_clean
|
502
273
|
require 'rake/clean'
|
503
274
|
task :clean do
|
@@ -507,10 +278,8 @@ class Levitate
|
|
507
278
|
|
508
279
|
def define_package
|
509
280
|
if source_control?
|
510
|
-
|
511
|
-
|
512
|
-
end
|
513
|
-
CLEAN.add manifest_file
|
281
|
+
require 'rubygems/package_task'
|
282
|
+
|
514
283
|
task :package => :clean
|
515
284
|
Gem::PackageTask.new(gemspec).define
|
516
285
|
end
|
@@ -518,7 +287,7 @@ class Levitate
|
|
518
287
|
|
519
288
|
def define_spec
|
520
289
|
unless spec_files.empty?
|
521
|
-
|
290
|
+
no_warnings {
|
522
291
|
require 'spec/rake/spectask'
|
523
292
|
}
|
524
293
|
|
@@ -550,7 +319,7 @@ class Levitate
|
|
550
319
|
|
551
320
|
desc "run specs individually"
|
552
321
|
task :spec_deps do
|
553
|
-
|
322
|
+
run_each_file(*spec_files)
|
554
323
|
end
|
555
324
|
|
556
325
|
task :prerelease => [:spec, :spec_deps]
|
@@ -606,7 +375,7 @@ class Levitate
|
|
606
375
|
|
607
376
|
desc "run tests individually"
|
608
377
|
task :test_deps do
|
609
|
-
|
378
|
+
run_each_file(*test_files)
|
610
379
|
end
|
611
380
|
|
612
381
|
task :prerelease => [:test, :test_deps]
|
@@ -619,7 +388,7 @@ class Levitate
|
|
619
388
|
def define_doc
|
620
389
|
desc "run rdoc"
|
621
390
|
task :doc => :clean_doc do
|
622
|
-
|
391
|
+
gem 'rdoc' rescue nil
|
623
392
|
require 'rdoc/rdoc'
|
624
393
|
args = (
|
625
394
|
gemspec.rdoc_options +
|
@@ -648,6 +417,7 @@ class Levitate
|
|
648
417
|
if source_control?
|
649
418
|
desc "publish docs"
|
650
419
|
task :publish => [:clean, :check_directory, :doc] do
|
420
|
+
current_branch = `git branch`[/^\* (\S+)$/, 1] or raise "??? branch"
|
651
421
|
if rubyforge_info
|
652
422
|
user, project = rubyforge_info
|
653
423
|
Dir.chdir(doc_dir) do
|
@@ -666,6 +436,7 @@ class Levitate
|
|
666
436
|
FileUtils.rmdir "doc"
|
667
437
|
git "add", "."
|
668
438
|
git "commit", "-m", "generated by rdoc"
|
439
|
+
git "checkout", current_branch
|
669
440
|
git "push", "-f", "origin", "gh-pages"
|
670
441
|
end
|
671
442
|
end
|
@@ -681,22 +452,6 @@ class Levitate
|
|
681
452
|
task :uninstall do
|
682
453
|
Installer.new.uninstall
|
683
454
|
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
455
|
end
|
701
456
|
|
702
457
|
def define_check_directory
|
@@ -710,7 +465,10 @@ class Levitate
|
|
710
465
|
def define_ping
|
711
466
|
task :ping do
|
712
467
|
require 'rbconfig'
|
713
|
-
|
468
|
+
[
|
469
|
+
"github.com",
|
470
|
+
("rubyforge.org" if rubyforge_info),
|
471
|
+
].compact.each do |server|
|
714
472
|
cmd = "ping " + (
|
715
473
|
if RbConfig::CONFIG["host"] =~ %r!darwin!
|
716
474
|
"-c2 #{server}"
|
@@ -721,23 +479,26 @@ class Levitate
|
|
721
479
|
unless `#{cmd}` =~ %r!0% packet loss!
|
722
480
|
raise "No ping for #{server}"
|
723
481
|
end
|
724
|
-
|
482
|
+
end
|
483
|
+
end
|
484
|
+
end
|
485
|
+
|
486
|
+
def define_check_levitate
|
487
|
+
task :check_levitate do
|
488
|
+
unless local_levitate == remote_levitate
|
489
|
+
raise "levitate is out of date"
|
490
|
+
end
|
725
491
|
end
|
726
492
|
end
|
727
493
|
|
728
494
|
def define_update_levitate
|
729
|
-
url = ENV["LEVITATE"] ||
|
730
|
-
"https://github.com/quix/levitate/raw/master/levitate.rb"
|
731
495
|
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
|
496
|
+
if local_levitate == remote_levitate
|
497
|
+
puts "Already up-to-date."
|
739
498
|
else
|
740
|
-
|
499
|
+
File.open(__FILE__, "w") { |f| f.print(remote_levitate) }
|
500
|
+
git "commit", __FILE__, "-m", "update levitate"
|
501
|
+
puts "Updated levitate."
|
741
502
|
end
|
742
503
|
end
|
743
504
|
end
|
@@ -762,30 +523,22 @@ class Levitate
|
|
762
523
|
end
|
763
524
|
end
|
764
525
|
|
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
526
|
def define_release
|
780
|
-
task :prerelease => [
|
527
|
+
task :prerelease => [
|
528
|
+
:clean,
|
529
|
+
:check_directory,
|
530
|
+
:check_levitate,
|
531
|
+
:ping,
|
532
|
+
history_file
|
533
|
+
]
|
781
534
|
|
782
535
|
task :finish_release do
|
783
536
|
git "tag", "#{gem_name}-" + version.to_s
|
784
537
|
git "push", "--tags", "origin", "master"
|
785
|
-
sh "gem", "push", gem
|
538
|
+
sh "gem", "push", "pkg/#{gem_name}-#{version}.gem"
|
786
539
|
end
|
787
540
|
|
788
|
-
task :release => [:prerelease, :package, :finish_release]
|
541
|
+
task :release => [:prerelease, :package, :finish_release, :publish]
|
789
542
|
end
|
790
543
|
|
791
544
|
def define_debug_gem
|
@@ -794,34 +547,22 @@ class Levitate
|
|
794
547
|
end
|
795
548
|
end
|
796
549
|
|
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
|
550
|
+
#### helpers
|
810
551
|
|
811
|
-
|
812
|
-
|
813
|
-
|
552
|
+
def files_in_require_paths
|
553
|
+
require_paths.inject([]) { |acc, dir|
|
554
|
+
acc + Dir.glob("#{dir}/**/*.rb")
|
555
|
+
}
|
556
|
+
end
|
814
557
|
|
815
|
-
|
816
|
-
|
817
|
-
|
818
|
-
Rake.application.top_level
|
819
|
-
end
|
558
|
+
def last_release
|
559
|
+
`git tag`.lines.select { |t| t.index(gem_name) == 0 }.last.chomp
|
560
|
+
end
|
820
561
|
|
821
|
-
|
822
|
-
|
562
|
+
def git(*args)
|
563
|
+
sh "git", *args
|
823
564
|
end
|
824
|
-
|
565
|
+
|
825
566
|
def open_browser(*files)
|
826
567
|
sh(*([browser].flatten + files))
|
827
568
|
end
|
@@ -830,7 +571,7 @@ class Levitate
|
|
830
571
|
task_names.each { |task_name|
|
831
572
|
Rake::Task[task_name].actions.map! { |action|
|
832
573
|
lambda { |*args|
|
833
|
-
|
574
|
+
no_warnings {
|
834
575
|
action.call(*args)
|
835
576
|
}
|
836
577
|
}
|
@@ -846,10 +587,110 @@ class Levitate
|
|
846
587
|
File.directory? ".git"
|
847
588
|
end
|
848
589
|
|
849
|
-
|
850
|
-
|
590
|
+
#### utility for instance and class
|
591
|
+
|
592
|
+
module Util
|
593
|
+
def ruby_bin
|
594
|
+
require 'rbconfig'
|
595
|
+
|
596
|
+
name = File.join(
|
597
|
+
RbConfig::CONFIG["bindir"],
|
598
|
+
RbConfig::CONFIG["RUBY_INSTALL_NAME"]
|
599
|
+
)
|
600
|
+
|
601
|
+
if RbConfig::CONFIG["host"] =~ %r!(mswin|cygwin|mingw)! and
|
602
|
+
File.basename(name) !~ %r!\.(exe|com|bat|cmd)\Z!i
|
603
|
+
name + RbConfig::CONFIG["EXEEXT"]
|
604
|
+
else
|
605
|
+
name
|
606
|
+
end
|
607
|
+
end
|
608
|
+
|
609
|
+
def ruby_command
|
610
|
+
[ruby_bin] + Levitate.ruby_opts.to_a
|
611
|
+
end
|
612
|
+
|
613
|
+
def ruby_command_string
|
614
|
+
ruby_command.join(" ")
|
615
|
+
end
|
616
|
+
|
617
|
+
def run(*args)
|
618
|
+
cmd = ruby_command + args
|
619
|
+
unless system(*cmd)
|
620
|
+
cmd_str = cmd.map { |t| "'#{t}'" }.join(", ")
|
621
|
+
raise "system(#{cmd_str}) failed with status #{$?.exitstatus}"
|
622
|
+
end
|
623
|
+
end
|
624
|
+
|
625
|
+
def run_each_file(*files)
|
626
|
+
files.each { |file|
|
627
|
+
run("-w", file)
|
628
|
+
}
|
629
|
+
end
|
851
630
|
|
852
|
-
|
631
|
+
def run_code_and_capture(code)
|
632
|
+
IO.popen(ruby_command_string, "r+") { |pipe|
|
633
|
+
pipe.print(code)
|
634
|
+
pipe.flush
|
635
|
+
pipe.close_write
|
636
|
+
pipe.read
|
637
|
+
}
|
638
|
+
end
|
639
|
+
|
640
|
+
def run_file_and_capture(file)
|
641
|
+
unless File.file? file
|
642
|
+
raise "file does not exist: `#{file}'"
|
643
|
+
end
|
644
|
+
IO.popen(ruby_command_string + " " + file, "r") { |pipe|
|
645
|
+
pipe.read
|
646
|
+
}
|
647
|
+
end
|
648
|
+
|
649
|
+
def with_warnings(value = true)
|
650
|
+
previous = $VERBOSE
|
651
|
+
$VERBOSE = value
|
652
|
+
begin
|
653
|
+
yield
|
654
|
+
ensure
|
655
|
+
$VERBOSE = previous
|
656
|
+
end
|
657
|
+
end
|
658
|
+
|
659
|
+
def no_warnings(&block)
|
660
|
+
with_warnings(nil, &block)
|
661
|
+
end
|
662
|
+
|
663
|
+
def to_camel_case(str)
|
664
|
+
str.split('_').map { |t| t.capitalize }.join
|
665
|
+
end
|
666
|
+
|
667
|
+
def write_file(file)
|
668
|
+
contents = yield
|
669
|
+
File.open(file, "wb") { |out|
|
670
|
+
out.print(contents)
|
671
|
+
}
|
672
|
+
contents
|
673
|
+
end
|
674
|
+
|
675
|
+
def instance_exec2(obj, *args, &block)
|
676
|
+
method_name = ["_", obj.object_id, "_", Thread.current.object_id].join
|
677
|
+
(class << obj ; self ; end).class_eval do
|
678
|
+
define_method method_name, &block
|
679
|
+
begin
|
680
|
+
obj.send(method_name, *args)
|
681
|
+
ensure
|
682
|
+
remove_method method_name
|
683
|
+
end
|
684
|
+
end
|
685
|
+
end
|
686
|
+
end
|
687
|
+
extend Util
|
688
|
+
include Util
|
689
|
+
|
690
|
+
#### public helpers for testing
|
691
|
+
|
692
|
+
class << self
|
693
|
+
# From 'minitest' by Ryan Davis.
|
853
694
|
def capture_io
|
854
695
|
require 'stringio'
|
855
696
|
|
@@ -884,7 +725,7 @@ class Levitate
|
|
884
725
|
Tempfile.open("run-rdoc-code") { |temp_file|
|
885
726
|
temp_file.print(final_code)
|
886
727
|
temp_file.close
|
887
|
-
actual =
|
728
|
+
actual = run_file_and_capture(temp_file.path).chomp
|
888
729
|
}
|
889
730
|
|
890
731
|
instance_exec2(instance, expected, actual, index, &block)
|
@@ -954,5 +795,57 @@ class Levitate
|
|
954
795
|
end
|
955
796
|
Object.const_set("Test#{file}".gsub(".", ""), klass)
|
956
797
|
end
|
798
|
+
|
799
|
+
def ruby_opts
|
800
|
+
@ruby_opts ||= []
|
801
|
+
end
|
802
|
+
attr_writer :ruby_opts
|
803
|
+
end
|
804
|
+
|
805
|
+
#### raw install, bypass gems
|
806
|
+
|
807
|
+
class Installer
|
808
|
+
def initialize
|
809
|
+
require 'fileutils'
|
810
|
+
require 'rbconfig'
|
811
|
+
require 'find'
|
812
|
+
|
813
|
+
@fu = FileUtils::Verbose
|
814
|
+
@spec = []
|
815
|
+
|
816
|
+
rb_root = RbConfig::CONFIG["sitelibdir"]
|
817
|
+
|
818
|
+
Find.find "lib" do |source|
|
819
|
+
next if source == "lib"
|
820
|
+
next unless File.directory?(source) || File.extname(source) == ".rb"
|
821
|
+
dest = File.join(rb_root, source.sub(%r!\Alib/!, ""))
|
822
|
+
@spec << [source, dest]
|
823
|
+
end
|
824
|
+
end
|
825
|
+
|
826
|
+
def install
|
827
|
+
@spec.each do |source, dest|
|
828
|
+
if File.directory?(source)
|
829
|
+
@fu.mkdir(dest) unless File.directory?(dest)
|
830
|
+
else
|
831
|
+
@fu.install(source, dest)
|
832
|
+
end
|
833
|
+
end
|
834
|
+
end
|
835
|
+
|
836
|
+
def uninstall
|
837
|
+
@spec.reverse.each do |source, dest|
|
838
|
+
if File.directory?(source)
|
839
|
+
@fu.rmdir(dest) if File.directory?(dest)
|
840
|
+
else
|
841
|
+
@fu.rm(dest) if File.file?(dest)
|
842
|
+
end
|
843
|
+
end
|
844
|
+
end
|
957
845
|
end
|
958
846
|
end
|
847
|
+
|
848
|
+
lambda do
|
849
|
+
config = File.join(File.dirname(__FILE__), "levitate_config.rb")
|
850
|
+
require config if File.file? config
|
851
|
+
end.call
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: live_ast_ruby_parser
|
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,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-05-
|
13
|
+
date: 2011-05-18 00:00:00 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: ruby_parser
|
@@ -53,7 +53,6 @@ files:
|
|
53
53
|
- lib/live_ast_ruby_parser/test.rb
|
54
54
|
- lib/live_ast_ruby_parser/unparser.rb
|
55
55
|
- lib/live_ast_ruby_parser/version.rb
|
56
|
-
- MANIFEST
|
57
56
|
homepage: http://quix.github.com/live_ast_ruby_parser
|
58
57
|
licenses: []
|
59
58
|
|