dissociated_introspection 0.7.1 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +10 -0
- data/README.md +1 -1
- data/lib/dissociated_introspection/block.rb +11 -0
- data/lib/dissociated_introspection/inspection.rb +1 -1
- data/lib/dissociated_introspection/method_call.rb +75 -0
- data/lib/dissociated_introspection/ruby_class.rb +38 -37
- data/lib/dissociated_introspection/ruby_class/def.rb +2 -2
- data/lib/dissociated_introspection/ruby_code.rb +0 -2
- data/lib/dissociated_introspection/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 36a8544f5157efb38e2cfe40ec2888847211b761
|
4
|
+
data.tar.gz: f70dd03c6c9e52966e95068d59637e70e6a13714
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cd41ba99f377e6988fa6884f44ce62b25e83b425c12d59292a971102a9c6a4120b0aa5f37a4bf7fb769a3866e5b36b0d76c44215adf1e30a5fce6eaa362920db
|
7
|
+
data.tar.gz: f0fc7cdcaccbedfd83b1992a7cd040c54ff7eeead3860940f5f44e7ce7b25a10bef12e6b9aff8b0761249b17ab8f20f3f0c55ee7864169cf50fcc11d8a66ba92
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,16 @@
|
|
1
1
|
# Changelog
|
2
2
|
All notable changes to this project will be documented in this file.
|
3
3
|
|
4
|
+
## 0.8.0 - 2017-03-24
|
5
|
+
### Enhancement
|
6
|
+
- DissociatedIntrospection::RubyClass#class_defs returns same api as #defs
|
7
|
+
- DissociatedIntrospection::RubyClass#class_method_calls inspect method name and its arguments ie. attr_reader :name
|
8
|
+
|
9
|
+
### Deprecated
|
10
|
+
- DissociatedIntrospection::RubyClass#is_class? changed to #class?
|
11
|
+
- DissociatedIntrospection::RubyClass#has_parent_class? changed to #parent_class?
|
12
|
+
- DissociatedIntrospection::RubyCode#to_ruby_str changed to #source
|
13
|
+
|
4
14
|
## 0.7.1 - 2016-10-20
|
5
15
|
### Fix
|
6
16
|
- `DissociatedIntrospection::RubyClass#defs` fixed parse issue when class has one method.
|
data/README.md
CHANGED
@@ -83,7 +83,7 @@ module DissociatedIntrospection
|
|
83
83
|
else
|
84
84
|
file.path
|
85
85
|
end
|
86
|
-
load_sandbox(OpenStruct.new(read: modified_class_source.
|
86
|
+
load_sandbox(OpenStruct.new(read: modified_class_source.source, path: path))
|
87
87
|
end
|
88
88
|
|
89
89
|
def load_sandbox(file)
|
@@ -0,0 +1,75 @@
|
|
1
|
+
module DissociatedIntrospection
|
2
|
+
class Lambda
|
3
|
+
attr_reader :ast
|
4
|
+
|
5
|
+
def initialize(ast)
|
6
|
+
@ast = ast
|
7
|
+
end
|
8
|
+
|
9
|
+
def type
|
10
|
+
ast.type
|
11
|
+
end
|
12
|
+
|
13
|
+
def body
|
14
|
+
RubyCode.build_from_ast(ast.to_a[2])
|
15
|
+
end
|
16
|
+
|
17
|
+
def arguments
|
18
|
+
RubyCode.build_from_ast(ast.to_a[1])
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
class MethodCall
|
23
|
+
attr_reader :ruby_code
|
24
|
+
|
25
|
+
def initialize(ruby_code)
|
26
|
+
@ruby_code = ruby_code
|
27
|
+
end
|
28
|
+
|
29
|
+
def arguments
|
30
|
+
ruby_code.ast.children[2..-1].map do |c|
|
31
|
+
case c.type
|
32
|
+
when :sym, :str
|
33
|
+
c.to_a.first
|
34
|
+
when :block
|
35
|
+
Lambda.new(c)
|
36
|
+
else
|
37
|
+
c
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def name
|
43
|
+
ruby_code.ast.children[1]
|
44
|
+
end
|
45
|
+
|
46
|
+
def to_h
|
47
|
+
{ name: name, arguments: arguments }
|
48
|
+
end
|
49
|
+
|
50
|
+
class Argument
|
51
|
+
attr_reader :ast
|
52
|
+
|
53
|
+
def initialize(ast)
|
54
|
+
@ast = ast
|
55
|
+
end
|
56
|
+
|
57
|
+
def type
|
58
|
+
ast.type
|
59
|
+
end
|
60
|
+
|
61
|
+
def value
|
62
|
+
case type
|
63
|
+
when :block
|
64
|
+
Block.new(ast.children)
|
65
|
+
else
|
66
|
+
ast.children[0]
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def to_h
|
71
|
+
{ type: type, value: value }
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
@@ -1,6 +1,7 @@
|
|
1
1
|
module DissociatedIntrospection
|
2
2
|
class RubyClass
|
3
3
|
attr_reader :ruby_code
|
4
|
+
extend Forwardable
|
4
5
|
using Try
|
5
6
|
|
6
7
|
def initialize(ruby_code)
|
@@ -14,19 +15,9 @@ module DissociatedIntrospection
|
|
14
15
|
end
|
15
16
|
end
|
16
17
|
|
17
|
-
|
18
|
-
ruby_code.ast
|
19
|
-
end
|
20
|
-
|
21
|
-
def source
|
22
|
-
ruby_code.source
|
23
|
-
end
|
18
|
+
def_delegators :ruby_code, :ast, :source, :comments
|
24
19
|
|
25
|
-
def
|
26
|
-
ruby_code.comments
|
27
|
-
end
|
28
|
-
|
29
|
-
def is_class?
|
20
|
+
def class?
|
30
21
|
ast.type == :class
|
31
22
|
end
|
32
23
|
|
@@ -38,25 +29,25 @@ module DissociatedIntrospection
|
|
38
29
|
Unparser.unparse(find_class.to_a[1])
|
39
30
|
end
|
40
31
|
|
41
|
-
def
|
32
|
+
def parent_class?
|
42
33
|
return false unless find_class
|
43
34
|
find_class.to_a[1].try(:type) == :const
|
44
35
|
end
|
45
36
|
|
46
37
|
def change_class_name(class_name)
|
47
|
-
|
38
|
+
nodes = ast.to_a.dup
|
48
39
|
nodes[0] = Parser::CurrentRuby.parse(class_name)
|
49
40
|
new_ast = ast.updated(nil, nodes, nil)
|
50
41
|
self.class.new(ast: new_ast)
|
51
42
|
end
|
52
43
|
|
53
44
|
def modify_parent_class(parent_class)
|
54
|
-
|
55
|
-
if has_parent_class?
|
45
|
+
if parent_class?
|
56
46
|
class_node = find_class.to_a.dup
|
57
47
|
class_node[1] = Parser::CurrentRuby.parse(parent_class.to_s)
|
58
48
|
new_ast = find_class.updated(nil, class_node, nil)
|
59
49
|
else
|
50
|
+
nodes = ast.to_a.dup
|
60
51
|
nodes[1] = nodes[0].updated(:const, [nil, parent_class.to_sym])
|
61
52
|
new_ast = ast.updated(nil, nodes, nil)
|
62
53
|
end
|
@@ -65,11 +56,18 @@ module DissociatedIntrospection
|
|
65
56
|
end
|
66
57
|
|
67
58
|
def defs
|
68
|
-
class_begin.children.select { |n| n.try(:type) == :def }.map
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
59
|
+
class_begin.children.select { |n| n.try(:type) == :def }.map(&method(:create_def))
|
60
|
+
end
|
61
|
+
|
62
|
+
def class_defs
|
63
|
+
class_begin.children.select { |n| [:defs, :sclass].include? n.try(:type) }.map do |n|
|
64
|
+
new_n = if n.type == :defs # def self.method;end
|
65
|
+
n.updated(:def, n.children[1..-1])
|
66
|
+
elsif n.type == :sclass # class >> self; def method;end
|
67
|
+
n.updated(:def, n.children[1].children, location: n.children[1].location)
|
68
|
+
end
|
69
|
+
|
70
|
+
create_def(new_n)
|
73
71
|
end
|
74
72
|
end
|
75
73
|
|
@@ -77,18 +75,16 @@ module DissociatedIntrospection
|
|
77
75
|
find_class.children.find { |n| n.try(:type) == :begin } || find_class
|
78
76
|
end
|
79
77
|
|
80
|
-
def to_ruby_str
|
81
|
-
source
|
82
|
-
end
|
83
|
-
|
84
78
|
def scrub_inner_classes
|
85
|
-
self.class.new RubyCode.build_from_ast(
|
86
|
-
|
79
|
+
self.class.new RubyCode.build_from_ast(
|
80
|
+
scrub_inner_classes_ast,
|
81
|
+
comments: comments
|
82
|
+
)
|
87
83
|
end
|
88
84
|
|
89
85
|
def module_nesting
|
90
86
|
ary = []
|
91
|
-
m
|
87
|
+
m = ast
|
92
88
|
while m
|
93
89
|
if (m = depth_first_search(m, :module, :class))
|
94
90
|
name = m.to_a[0].to_a[1]
|
@@ -99,8 +95,21 @@ module DissociatedIntrospection
|
|
99
95
|
ary
|
100
96
|
end
|
101
97
|
|
98
|
+
def class_method_calls
|
99
|
+
class_begin.children.select { |n| n.try(:type) == :send }.map do |ast|
|
100
|
+
MethodCall.new(RubyCode.build_from_ast(ast))
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
102
104
|
private
|
103
105
|
|
106
|
+
def create_def(n)
|
107
|
+
def_comments = comments.select do |comment|
|
108
|
+
comment.location.last_line+1 == n.location.first_line
|
109
|
+
end
|
110
|
+
Def.new(RubyCode.build_from_ast(n, comments: def_comments))
|
111
|
+
end
|
112
|
+
|
104
113
|
def scrub_inner_classes_ast
|
105
114
|
find_class.updated(find_class.type,
|
106
115
|
class_begin.updated(class_begin.type,
|
@@ -121,15 +130,7 @@ module DissociatedIntrospection
|
|
121
130
|
return v if v.is_a?(Parser::AST::Node)
|
122
131
|
end
|
123
132
|
end
|
124
|
-
|
125
|
-
end
|
126
|
-
|
127
|
-
def nodes
|
128
|
-
@nodes ||= ast.to_a.dup
|
129
|
-
end
|
130
|
-
|
131
|
-
def reset_nodes
|
132
|
-
@nodes = nil
|
133
|
+
false
|
133
134
|
end
|
134
135
|
end
|
135
136
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dissociated_introspection
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dustin Zeisler
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-03-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: parser
|
@@ -101,8 +101,10 @@ files:
|
|
101
101
|
- bin/setup
|
102
102
|
- dissociated_introspection.gemspec
|
103
103
|
- lib/dissociated_introspection.rb
|
104
|
+
- lib/dissociated_introspection/block.rb
|
104
105
|
- lib/dissociated_introspection/eval_sandbox.rb
|
105
106
|
- lib/dissociated_introspection/inspection.rb
|
107
|
+
- lib/dissociated_introspection/method_call.rb
|
106
108
|
- lib/dissociated_introspection/recording_parent.rb
|
107
109
|
- lib/dissociated_introspection/ruby_class.rb
|
108
110
|
- lib/dissociated_introspection/ruby_class/def.rb
|