mvz-live_ast 1.1.2 → 1.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGES.rdoc +6 -0
- data/README.rdoc +3 -4
- data/lib/live_ast/linker.rb +1 -1
- data/lib/live_ast/ruby_parser/unparser.rb +12 -1
- data/lib/live_ast/version.rb +1 -1
- data/test/alias_test.rb +24 -0
- data/test/to_ruby/to_ruby_test.rb +10 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 53bc1d58d2c1645ff3d34a4f5f6df3e34a8fb352
|
4
|
+
data.tar.gz: 6e52ea854d98d13be30b16bd6e3e2acb9933b9ba
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 139a51f52879ec099027541c3826d807eafff81b0e2d06352d7c62ba5d971c143608224213e7fa2a6f1273a5b4eff5d4c2456c7c56e2614714489d9ffc44e5d0
|
7
|
+
data.tar.gz: 9c7397ca3f90654b71cc0ef9c904f7432e5548a249a1c69200eda4f17e8ade860fd0c4f1ac59cac8c0f93d6ddfe1d268986468220f31cdfe422bb4674fc14461
|
data/CHANGES.rdoc
CHANGED
@@ -1,6 +1,12 @@
|
|
1
1
|
|
2
2
|
= live_ast Changes
|
3
3
|
|
4
|
+
== Version 1.1.3
|
5
|
+
|
6
|
+
* Keep ASTs in the cache when they are fetched, allowing aliased methods to
|
7
|
+
retrieve their AST under both names.
|
8
|
+
* Do not destroy the AST when creating ruby source
|
9
|
+
|
4
10
|
== Version 1.1.2
|
5
11
|
|
6
12
|
* Update dependencies
|
data/README.rdoc
CHANGED
@@ -326,15 +326,14 @@ paranoia; the noninvasive option may be the most appropriate.
|
|
326
326
|
+ast_eval+ and +load+ cache all incoming code, while
|
327
327
|
<code>require</code>d files are cached on a need-to-know basis. When
|
328
328
|
an AST is requested, the corresponding source file is parsed and
|
329
|
-
discarded, leaving behind method and block ASTs. +to_ast+
|
329
|
+
discarded, leaving behind method and block ASTs. +to_ast+ fetches an
|
330
330
|
AST from the cache and attaches it to the appropriate object (a Proc
|
331
331
|
or Module).
|
332
332
|
|
333
333
|
Ignored, unextracted ASTs will therefore linger in the cache. Since
|
334
334
|
sexps are generally small there is little need for concern unless one
|
335
|
-
is continually evaling/reloading
|
336
|
-
|
337
|
-
to be garbage collected. To flush the cache,
|
335
|
+
is continually evaling/reloading. Nevertheless it is possible that old
|
336
|
+
ASTs will eventually need to be garbage collected. To flush the cache,
|
338
337
|
|
339
338
|
(1) Check that +to_ast+ has been called on all objects whose ASTs are
|
340
339
|
desired.
|
data/lib/live_ast/linker.rb
CHANGED
@@ -10,7 +10,18 @@ module LiveAST
|
|
10
10
|
# Return a ruby source string which reflects the given AST.
|
11
11
|
#
|
12
12
|
def self.unparse(sexp)
|
13
|
-
::Ruby2Ruby.new.process(sexp)
|
13
|
+
::Ruby2Ruby.new.process(clone_sexp(sexp))
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.clone_sexp(sexp)
|
17
|
+
sexp.clone.map! do |elem|
|
18
|
+
case elem
|
19
|
+
when Sexp
|
20
|
+
clone_sexp(elem)
|
21
|
+
else
|
22
|
+
elem
|
23
|
+
end
|
24
|
+
end
|
14
25
|
end
|
15
26
|
end
|
16
27
|
end
|
data/lib/live_ast/version.rb
CHANGED
data/test/alias_test.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require_relative 'main'
|
2
|
+
|
3
|
+
class AliasTest < RegularTest
|
4
|
+
class A
|
5
|
+
def f
|
6
|
+
"A#f"
|
7
|
+
end
|
8
|
+
|
9
|
+
alias g f
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_alias_unbound_method
|
13
|
+
expected = no_arg_def(:f, "A#f")
|
14
|
+
assert_equal expected, A.instance_method(:f).to_ast
|
15
|
+
assert_equal expected, A.instance_method(:g).to_ast
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_alias_method
|
19
|
+
expected = no_arg_def(:f, "A#f")
|
20
|
+
assert_equal expected, A.new.method(:f).to_ast
|
21
|
+
assert_equal expected, A.new.method(:g).to_ast
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
@@ -83,5 +83,15 @@ class ToRubyTest < RegularTest
|
|
83
83
|
end.instance_method(:f).to_ruby
|
84
84
|
assert_equal src, dst
|
85
85
|
end
|
86
|
+
|
87
|
+
def test_to_ast_after_to_ruby
|
88
|
+
src = %{lambda { "moo" }}
|
89
|
+
expected_ast = ast_eval(src, binding).to_ast
|
90
|
+
|
91
|
+
lmb = ast_eval(src, binding)
|
92
|
+
lmb.to_ruby
|
93
|
+
|
94
|
+
assert_equal expected_ast, lmb.to_ast
|
95
|
+
end
|
86
96
|
end if LiveAST.parser::Test.respond_to?(:unparser_matches_ruby2ruby?) &&
|
87
97
|
LiveAST.parser::Test.unparser_matches_ruby2ruby?
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mvz-live_ast
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James M. Lawrence
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-10-
|
12
|
+
date: 2014-10-23 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: ruby_parser
|
@@ -145,6 +145,7 @@ files:
|
|
145
145
|
- lib/live_ast/to_ast.rb
|
146
146
|
- lib/live_ast/to_ruby.rb
|
147
147
|
- lib/live_ast/version.rb
|
148
|
+
- test/alias_test.rb
|
148
149
|
- test/ast_eval/ast_eval_test.rb
|
149
150
|
- test/ast_load/ast_load_test.rb
|
150
151
|
- test/attr_test.rb
|
@@ -244,6 +245,7 @@ test_files:
|
|
244
245
|
- test/thread_test.rb
|
245
246
|
- test/load_path_test.rb
|
246
247
|
- test/ast_load/ast_load_test.rb
|
248
|
+
- test/alias_test.rb
|
247
249
|
- test/rubyspec_test.rb
|
248
250
|
- test/redefine_method_test.rb
|
249
251
|
- test/lambda_test.rb
|
@@ -274,3 +276,4 @@ test_files:
|
|
274
276
|
- test/base/noninvasive_test.rb
|
275
277
|
- test/base/reload_test.rb
|
276
278
|
- test/encoding_test.rb
|
279
|
+
has_rdoc:
|