live_ast 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES.rdoc CHANGED
@@ -1,6 +1,13 @@
1
1
 
2
2
  = LiveAST ChangeLog
3
3
 
4
+ == Version 0.2.1
5
+
6
+ * fixed some rdoc issues
7
+ * removed rubyforge references
8
+ * update ruby_parser
9
+ * less MRI-centric tests
10
+
4
11
  == Version 0.2.0
5
12
 
6
13
  * initial release
data/MANIFEST CHANGED
@@ -7,7 +7,6 @@ lib/live_ast.rb
7
7
  lib/live_ast/ast_eval.rb
8
8
  lib/live_ast/ast_load.rb
9
9
  lib/live_ast/base.rb
10
- lib/live_ast/cache.rb
11
10
  lib/live_ast/error.rb
12
11
  lib/live_ast/evaler.rb
13
12
  lib/live_ast/linker.rb
data/README.rdoc CHANGED
@@ -56,6 +56,8 @@ methods and procs.
56
56
 
57
57
  % gem install live_ast
58
58
 
59
+ A manual install option is also available.
60
+
59
61
  == Description
60
62
 
61
63
  LiveAST enables a program to find the ASTs of objects created by
@@ -69,15 +71,18 @@ another parser may be easily substituted (in fact the name +to_ast+ is
69
71
  used instead of +to_sexp+ because LiveAST has no understanding of what
70
72
  the parser outputs).
71
73
 
74
+ Note that RubyParser does not currently support the newer Ruby 1.9
75
+ syntax features (<code>Racc::ParseError</code> will be raised).
76
+
72
77
  LiveAST is thread-safe.
73
78
 
74
79
  Ruby 1.9.2 or higher is required.
75
80
 
76
81
  == Links
77
82
 
78
- * Documentation: http://liveast.rubyforge.org
79
- * Rubyforge home: http://rubyforge.org/projects/liveast/
80
- * Repository: http://github.com/quix/live_ast
83
+ * Home: https://github.com/quix/live_ast
84
+ * Documentation: http://quix.github.com/live_ast
85
+ * Feature Requests, Bug Reports: http://github.com/quix/live_ast/issues
81
86
 
82
87
  == +to_ruby+
83
88
 
@@ -149,6 +154,18 @@ or blocks in order for its AST to be available.
149
154
  a = lambda { } ; b = lambda { }
150
155
  a.to_ast # => raises LiveAST::MultipleDefinitionsOnSameLineError
151
156
 
157
+ == Manual Download/Install
158
+
159
+ http://github.com/quix/live_ast/archives/master
160
+
161
+ % tar zxvf live_ast-x.x.x.tgz
162
+ % cd live_ast-x.x.x
163
+ % rake install
164
+
165
+ To uninstall,
166
+
167
+ % rake uninstall
168
+
152
169
  == Technical Issues
153
170
 
154
171
  You can probably ignore this section. Goodbye.
@@ -240,19 +257,18 @@ give the old AST,
240
257
  load "foo.rb" # oops! forgot to use ast_load
241
258
  p Foo.instance_method(:bar).to_ast # => stale AST
242
259
 
243
- Realize that +foo.rb+ may be referenced by an unknown number of
244
- methods and blocks. If the original +foo.rb+ source were dumped in
245
- favor of the modified +foo.rb+, then an unknown number of those
246
- references would be invalidated (and some may even point to the wrong
247
- AST!).
260
+ Realize that <code>foo.rb</code> may be referenced by an unknown
261
+ number of methods and blocks. If the original <code>foo.rb</code>
262
+ source were dumped in favor of the modified <code>foo.rb</code>, then
263
+ an unknown number of those references would be invalidated (and some
264
+ may even point to the wrong AST!).
248
265
 
249
266
  This is the reason for the caching that results in the stale AST
250
267
  above. It should now be clear why the default behavior of
251
268
  <code>require 'live_ast'</code> is to redefine +load+: doing so
252
269
  prevents this problem entirely. On the other hand if it is fully known
253
270
  where and when files are being reloaded (if at all) then there's no
254
- need for paranoia; this noninvasive option may be most the
255
- appropriate.
271
+ need for paranoia; the noninvasive option may be the most appropriate.
256
272
 
257
273
  === The Source/AST Cache
258
274
 
@@ -351,7 +367,7 @@ to fill in the missing binding argument. Unfortunately a limitation
351
367
  with tracing events in MRI places a few odd restrictions on the syntax
352
368
  surrounding +eval+, though all restrictions can be trivially
353
369
  sidestepped. Nonetheless it does work (it passes rubyspec minus the
354
- backtrace issue) despite being somewhat impractical.
370
+ above backtrace issue) despite being somewhat impractical.
355
371
 
356
372
  This (mis)feature is maintained in a separate branch named
357
373
  +replace_eval+ on github (not part of the gem). For more information see
data/Rakefile CHANGED
@@ -2,17 +2,19 @@ require_relative 'devel/jumpstart'
2
2
 
3
3
  Jumpstart.new "live_ast" do |s|
4
4
  s.developer "James M. Lawrence", "quixoticsycophant@gmail.com"
5
- s.rubyforge_user = "quix"
6
- s.rubyforge_name = "liveast"
5
+ s.github_user = "quix"
7
6
  s.camel_name = "LiveAST"
8
7
  s.rdoc_title = "LiveAST: Live Abstract Syntax Trees"
8
+ s.extra_rdoc_options = ["-a"]
9
9
 
10
10
  # my code compensates for a ruby_parser bug; make this equal for now
11
- s.dependency("ruby_parser", "= 2.0.5")
11
+ s.dependency("ruby_parser", "= 2.0.6")
12
12
 
13
13
  s.rdoc_files = %w[
14
14
  README.rdoc
15
15
  lib/live_ast/ast_eval.rb
16
+ lib/live_ast/to_ast.rb
17
+ lib/live_ast/to_ruby.rb
16
18
  lib/live_ast/base.rb
17
19
  lib/live_ast/version.rb
18
20
  ]
data/devel/jumpstart.rb CHANGED
@@ -311,14 +311,6 @@ class Jumpstart
311
311
  end or "0.0.0"
312
312
  end
313
313
 
314
- attribute :rubyforge_name do
315
- name.gsub('_', '')
316
- end
317
-
318
- attribute :rubyforge_user do
319
- email.first[%r!\A.*?(?=@)!]
320
- end
321
-
322
314
  attribute :readme_file do
323
315
  "README.rdoc"
324
316
  end
@@ -328,7 +320,7 @@ class Jumpstart
328
320
  end
329
321
 
330
322
  attribute :doc_dir do
331
- "documentation"
323
+ "doc"
332
324
  end
333
325
 
334
326
  attribute :spec_files do
@@ -420,6 +412,10 @@ class Jumpstart
420
412
  }
421
413
  end
422
414
 
415
+ attribute :extra_rdoc_options do
416
+ []
417
+ end
418
+
423
419
  attribute :browser do
424
420
  require 'rbconfig'
425
421
  if RbConfig::CONFIG["host"] =~ %r!darwin!
@@ -448,10 +444,6 @@ class Jumpstart
448
444
  )
449
445
  }
450
446
 
451
- if rubyforge_name
452
- g.rubyforge_project = rubyforge_name
453
- end
454
-
455
447
  if url
456
448
  g.homepage = url
457
449
  end
@@ -516,10 +508,14 @@ class Jumpstart
516
508
  begin
517
509
  readme_contents.match(%r!^\*.*?(http://\S+)!)[1]
518
510
  rescue
519
- "http://#{rubyforge_name}.rubyforge.org"
511
+ "http://#{github_user}.github.com/#{name}"
520
512
  end
521
513
  end
522
514
 
515
+ attribute :github_user do
516
+ "FIXME"
517
+ end
518
+
523
519
  attribute :extra_deps do
524
520
  []
525
521
  end
@@ -642,8 +638,14 @@ class Jumpstart
642
638
 
643
639
  desc "run full_test then open browser"
644
640
  task :show_test => :full_test do
641
+ show = lambda { open_browser(cov_dir + "/index.html") }
645
642
  if ruby_18?
646
- open_browser(cov_dir + "/index.html")
643
+ show.call
644
+ else
645
+ SimpleCov.at_exit do
646
+ SimpleCov.result.format!
647
+ show.call
648
+ end
647
649
  end
648
650
  end
649
651
 
@@ -662,9 +664,11 @@ class Jumpstart
662
664
  def define_doc
663
665
  desc "run rdoc"
664
666
  task :doc => :clean_doc do
667
+ Kernel.send :gem, 'rdoc' rescue nil
665
668
  require 'rdoc/rdoc'
666
669
  args = (
667
670
  gemspec.rdoc_options +
671
+ extra_rdoc_options +
668
672
  gemspec.require_paths.clone +
669
673
  gemspec.extra_rdoc_files +
670
674
  ["-o", doc_dir]
@@ -687,14 +691,19 @@ class Jumpstart
687
691
  end
688
692
 
689
693
  def define_publish
690
- desc "upload docs"
691
- task :publish => [:clean_doc, :doc] do
692
- require 'rake/contrib/sshpublisher'
693
- Rake::SshDirPublisher.new(
694
- "#{rubyforge_user}@rubyforge.org",
695
- "/var/www/gforge-projects/#{rubyforge_name}",
696
- doc_dir
697
- ).upload
694
+ desc "publish docs"
695
+ task :publish => [:clean, :check_directory, :doc] do
696
+ git "branch", "-D", "gh-pages"
697
+ git "checkout", "--orphan", "gh-pages"
698
+ FileUtils.rm ".git/index"
699
+ git "clean", "-fdx", "-e", "doc"
700
+ Dir["doc/*"].each { |path|
701
+ FileUtils.mv path, "."
702
+ }
703
+ FileUtils.rmdir "doc"
704
+ git "add", "."
705
+ git "commit", "-m", "generated by rdoc"
706
+ git "push", "-f", "origin", "gh-pages"
698
707
  end
699
708
  end
700
709
 
@@ -845,7 +854,7 @@ class Jumpstart
845
854
  git(*%w(push --tags origin master))
846
855
  end
847
856
 
848
- task :release => [:prerelease, :package, :publish, :finish_release]
857
+ task :release => [:prerelease, :package, :finish_release]
849
858
  end
850
859
 
851
860
  def define_debug_gem
@@ -3,10 +3,8 @@ require 'live_ast/base'
3
3
  module Kernel
4
4
  private
5
5
 
6
- #
7
6
  # The same as +eval+ except that the binding argument is required
8
7
  # and AST-accessible objects are created.
9
- #
10
8
  def ast_eval(*args)
11
9
  LiveAST::Evaler.eval(args[0], *args)
12
10
  end
data/lib/live_ast/base.rb CHANGED
@@ -4,7 +4,6 @@ require 'live_ast/parser'
4
4
  require 'live_ast/loader'
5
5
  require 'live_ast/evaler'
6
6
  require 'live_ast/linker'
7
- require 'live_ast/cache'
8
7
  require 'live_ast/error'
9
8
 
10
9
  module LiveAST
@@ -14,7 +13,7 @@ module LiveAST
14
13
  #
15
14
  # For use in noninvasive mode (<code>require 'live_ast/base'</code>).
16
15
  #
17
- # Extract an object's AST.
16
+ # Equivalent to <code>obj.to_ast</code>.
18
17
  #
19
18
  def ast(obj) #:nodoc:
20
19
  case obj
@@ -38,7 +37,7 @@ module LiveAST
38
37
  #
39
38
  # For use in noninvasive mode (<code>require 'live_ast/base'</code>).
40
39
  #
41
- # Equivalent to Kernel#ast_eval.
40
+ # Equivalent to <code>Kernel#ast_eval</code>.
42
41
  #
43
42
  def eval(*args) #:nodoc:
44
43
  Evaler.eval(args[0], *args)
@@ -47,7 +46,7 @@ module LiveAST
47
46
  #
48
47
  # For use in noninvasive mode (<code>require 'live_ast/base'</code>).
49
48
  #
50
- # Equivalent to Kernel#ast_load.
49
+ # Equivalent to <code>Kernel#ast_load</code>.
51
50
  #
52
51
  def load(file, wrap = false) #:nodoc:
53
52
  Loader.load(file, wrap)
@@ -17,8 +17,7 @@ module LiveAST
17
17
 
18
18
  class NoSourceError < ASTNotFoundError
19
19
  def message
20
- "No source found for the requested AST. " <<
21
- "Are you sure it was written in ruby?"
20
+ "No source found for the requested AST."
22
21
  end
23
22
  end
24
23
 
@@ -1,4 +1,18 @@
1
1
  module LiveAST
2
+ class Cache
3
+ def initialize(*args)
4
+ @source, @user_line = args
5
+ @asts = nil
6
+ end
7
+
8
+ def fetch_ast(line)
9
+ @asts ||= Parser.new.parse(@source).tap do
10
+ @source = nil
11
+ end
12
+ @asts.delete(line - @user_line + 1)
13
+ end
14
+ end
15
+
2
16
  module Attacher
3
17
  VAR_NAME = :@_live_ast
4
18
 
@@ -77,7 +91,7 @@ module LiveAST
77
91
  end
78
92
 
79
93
  #
80
- # create a cache along with a uniquely-identifing key for it
94
+ # create a cache along with a unique key for it
81
95
  #
82
96
  def new_cache(contents, file, user_line, file_is_key)
83
97
  key = file_is_key ? file : file + REVISION_TOKEN + @counter
@@ -2,8 +2,7 @@ require 'live_ast/base'
2
2
 
3
3
  [Method, UnboundMethod].each do |klass|
4
4
  klass.class_eval do
5
- # Extract the AST of this object.
6
- def to_ast
5
+ def to_ast #:nodoc:
7
6
  LiveAST::Linker.find_method_ast(owner, name, *source_location)
8
7
  end
9
8
  end
@@ -15,3 +14,13 @@ class Proc
15
14
  LiveAST::Linker.find_proc_ast(self)
16
15
  end
17
16
  end
17
+
18
+ class Method
19
+ # :method: to_ast
20
+ # Extract the AST of this object.
21
+ end
22
+
23
+ class UnboundMethod
24
+ # :method: to_ast
25
+ # Extract the AST of this object.
26
+ end
@@ -4,9 +4,32 @@ require 'live_ast/base'
4
4
 
5
5
  [Method, UnboundMethod, Proc].each do |klass|
6
6
  klass.class_eval do
7
- # Generate ruby code which reflects the AST of this object.
8
- def to_ruby
7
+ def to_ruby #:nodoc:
9
8
  Ruby2Ruby.new.process(LiveAST.ast(self))
10
9
  end
11
10
  end
12
11
  end
12
+
13
+ class Method
14
+ # :method: to_ruby
15
+ # Generate ruby code which reflects the AST of this object.
16
+ #
17
+ # Defined by <code>require 'live_ast/to_ruby'</code>. The ruby2ruby
18
+ # gem must be installed.
19
+ end
20
+
21
+ class UnboundMethod
22
+ # :method: to_ruby
23
+ # Generate ruby code which reflects the AST of this object.
24
+ #
25
+ # Defined by <code>require 'live_ast/to_ruby'</code>. The ruby2ruby
26
+ # gem must be installed.
27
+ end
28
+
29
+ class Proc
30
+ # :method: to_ruby
31
+ # Generate ruby code which reflects the AST of this object.
32
+ #
33
+ # Defined by <code>require 'live_ast/to_ruby'</code>. The ruby2ruby
34
+ # gem must be installed.
35
+ end
@@ -1,3 +1,3 @@
1
1
  module LiveAST
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
data/test/shared/main.rb CHANGED
@@ -66,11 +66,15 @@ class BaseTest < JLMiniTest
66
66
 
67
67
  DATA_DIR = File.expand_path(File.dirname(__FILE__) + "/../data")
68
68
 
69
- def temp_file(basename = nil)
70
- unless basename
71
- basename = ('a'..'z').to_a.shuffle.join + ".rb"
69
+ def self.stdlib_has_source?
70
+ case RUBY_ENGINE
71
+ when "ruby" # MRI; possibly others; not jruby
72
+ true
72
73
  end
74
+ end
73
75
 
76
+ def temp_file(basename = nil)
77
+ basename ||= ('a'..'z').to_a.shuffle.join + ".rb"
74
78
  path = DATA_DIR + "/" + basename
75
79
  FileUtils.mkdir DATA_DIR unless File.directory? DATA_DIR
76
80
 
data/test/stdlib_test.rb CHANGED
@@ -1,11 +1,13 @@
1
1
  require_relative 'shared/main'
2
2
 
3
3
  class StdlibTest < RegularTest
4
- def test_pp
5
- assert_not_nil method(:pp).to_ast
6
- end
7
-
8
- def test_find
9
- assert_not_nil Find.method(:find).to_ast
4
+ if stdlib_has_source?
5
+ def test_pp
6
+ assert_not_nil method(:pp).to_ast
7
+ end
8
+
9
+ def test_find
10
+ assert_not_nil Find.method(:find).to_ast
11
+ end
10
12
  end
11
13
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: live_ast
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.2.0
5
+ version: 0.2.1
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-02-17 00:00:00 -05:00
13
+ date: 2011-02-20 00:00:00 -05:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -21,7 +21,7 @@ dependencies:
21
21
  requirements:
22
22
  - - "="
23
23
  - !ruby/object:Gem::Version
24
- version: 2.0.5
24
+ version: 2.0.6
25
25
  type: :runtime
26
26
  version_requirements: *id001
27
27
  description: LiveAST enables a program to find the ASTs of objects created by dynamically generated code.
@@ -42,7 +42,6 @@ files:
42
42
  - lib/live_ast/ast_eval.rb
43
43
  - lib/live_ast/ast_load.rb
44
44
  - lib/live_ast/base.rb
45
- - lib/live_ast/cache.rb
46
45
  - lib/live_ast/error.rb
47
46
  - lib/live_ast/evaler.rb
48
47
  - lib/live_ast/linker.rb
@@ -89,7 +88,7 @@ files:
89
88
  - test/to_ruby_test.rb
90
89
  - MANIFEST
91
90
  has_rdoc: true
92
- homepage: http://liveast.rubyforge.org
91
+ homepage: http://quix.github.com/live_ast
93
92
  licenses: []
94
93
 
95
94
  post_install_message:
@@ -109,8 +108,6 @@ rdoc_options:
109
108
  - --exclude
110
109
  - lib/live_ast/ast_load.rb
111
110
  - --exclude
112
- - lib/live_ast/cache.rb
113
- - --exclude
114
111
  - lib/live_ast/error.rb
115
112
  - --exclude
116
113
  - lib/live_ast/evaler.rb
@@ -125,10 +122,6 @@ rdoc_options:
125
122
  - --exclude
126
123
  - lib/live_ast/replace_raise.rb
127
124
  - --exclude
128
- - lib/live_ast/to_ast.rb
129
- - --exclude
130
- - lib/live_ast/to_ruby.rb
131
- - --exclude
132
125
  - test/ast_eval_feature_test.rb
133
126
  - --exclude
134
127
  - test/ast_load_feature_test.rb
@@ -214,7 +207,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
214
207
  version: "0"
215
208
  requirements: []
216
209
 
217
- rubyforge_project: liveast
210
+ rubyforge_project:
218
211
  rubygems_version: 1.5.2
219
212
  signing_key:
220
213
  specification_version: 3
@@ -1,14 +0,0 @@
1
- module LiveAST
2
- class Cache
3
- def initialize(*args)
4
- @source, @user_line, @asts = args
5
- end
6
-
7
- def fetch_ast(line)
8
- @asts ||= Parser.new.parse(@source).tap do
9
- @source = nil
10
- end
11
- @asts.delete(line - @user_line + 1)
12
- end
13
- end
14
- end