dissociated_introspection 0.9.1 → 0.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/.travis.yml +4 -4
- data/CHANGELOG.md +17 -0
- data/dissociated_introspection.gemspec +4 -4
- data/lib/dissociated_introspection/eval_sandbox.rb +2 -2
- data/lib/dissociated_introspection/inspection.rb +1 -1
- data/lib/dissociated_introspection/method_in_liner.rb +49 -0
- data/lib/dissociated_introspection/recording_parent.rb +0 -2
- data/lib/dissociated_introspection/ruby_class/create_def.rb +19 -0
- data/lib/dissociated_introspection/ruby_class/def.rb +17 -4
- data/lib/dissociated_introspection/ruby_class.rb +9 -12
- data/lib/dissociated_introspection/ruby_code.rb +1 -1
- data/lib/dissociated_introspection/version.rb +1 -1
- data/lib/dissociated_introspection.rb +3 -0
- metadata +15 -26
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: e29a242da18895cccd18d06de8fae99dbc8ead7835c6b7650372ed96adc7b50e
|
4
|
+
data.tar.gz: 27710c993d783cdc7233de04167f219ab5e064300328a39c0bdab98af90b496d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 76fce8889a4f4a81d66b1a63a7f6b00e670d41cda764fbb01fb2fce1a8615e27597279fc7766fb13ddf020b2742b0d38068f4f41a4f3936ea2a96239ee666c37
|
7
|
+
data.tar.gz: ca2c807f35eaeaf35d5f2e259074527815c21017d4466f7b6a64d8be41b6e8f9e57c9af0092a3e8b55395c3589e05e85a7a0cce6832556074616754911ce4648
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,23 @@
|
|
1
1
|
# Changelog
|
2
2
|
All notable changes to this project will be documented in this file.
|
3
3
|
|
4
|
+
## 0.12.0 - 2018-08-02
|
5
|
+
### Enhancement
|
6
|
+
- MethodInLiner will now recursively in-lines methods.
|
7
|
+
|
8
|
+
## 0.11.0 - 2018-08-01
|
9
|
+
### Enhancement
|
10
|
+
- Ability to Inline local methods with the exception of ones with arguments passed.
|
11
|
+
|
12
|
+
## 0.10.0 - 2018-07-28
|
13
|
+
### Fix
|
14
|
+
- Require Ruby core lib resources. (Forwardable, Pathname)
|
15
|
+
- Deal with change in how Ruby order's it's constants.
|
16
|
+
### Enhancement
|
17
|
+
- RubyClass::Def methods return RubyCode object so that AST could be inspected
|
18
|
+
### Deprecation
|
19
|
+
- Dropping support for Ruby version 2.1
|
20
|
+
|
4
21
|
## 0.9.1 - 2018-01-16
|
5
22
|
### Fix
|
6
23
|
- `DissociatedIntrospection::RubyClass#class_begin` added back to public API
|
@@ -19,12 +19,12 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
20
|
spec.require_paths = ["lib"]
|
21
21
|
|
22
|
-
spec.required_ruby_version = '>=
|
22
|
+
spec.required_ruby_version = '>= 3.0'
|
23
23
|
|
24
|
-
spec.add_runtime_dependency "parser", "
|
25
|
-
spec.add_runtime_dependency "unparser", "~> 0.
|
24
|
+
spec.add_runtime_dependency "parser", ">= 3.1.2.0"
|
25
|
+
spec.add_runtime_dependency "unparser", "~> 0.4.9"
|
26
26
|
|
27
|
-
spec.add_development_dependency "bundler", "~>
|
27
|
+
spec.add_development_dependency "bundler", "~> 2.3"
|
28
28
|
spec.add_development_dependency "rake", "~> 10.0"
|
29
29
|
spec.add_development_dependency "rspec", "~> 3.3"
|
30
30
|
end
|
@@ -11,7 +11,7 @@ module DissociatedIntrospection
|
|
11
11
|
def call
|
12
12
|
module_namespace.module_eval(recording_parent.read, recording_parent.path)
|
13
13
|
module_namespace.module_eval(file.read, file.path)
|
14
|
-
module_namespace.const_get(module_namespace.constants.last)
|
14
|
+
module_namespace.const_get(module_namespace.constants.select{|c| c != :RecordingParent}.last)
|
15
15
|
end
|
16
16
|
|
17
17
|
def constants
|
@@ -27,4 +27,4 @@ module DissociatedIntrospection
|
|
27
27
|
end
|
28
28
|
|
29
29
|
end
|
30
|
-
end
|
30
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module DissociatedIntrospection
|
2
|
+
class MethodInLiner
|
3
|
+
attr_reader :defs, :ruby_code
|
4
|
+
# @param [Array<DissociatedIntrospection::RubyClass::Def>] defs
|
5
|
+
# @param [DissociatedIntrospection::RubyCode] ruby_code
|
6
|
+
def initialize(ruby_code, defs:)
|
7
|
+
@defs = defs
|
8
|
+
@ruby_code = ruby_code
|
9
|
+
end
|
10
|
+
|
11
|
+
# @return [DissociatedIntrospection::RubyCode]
|
12
|
+
def in_line
|
13
|
+
rewriter = InLiner.new
|
14
|
+
rewriter.defs = defs
|
15
|
+
result = rewriter.process(ruby_code.ast)
|
16
|
+
RubyCode.build_from_ast(result)
|
17
|
+
end
|
18
|
+
|
19
|
+
class InLiner < Parser::TreeRewriter
|
20
|
+
attr_accessor :defs
|
21
|
+
|
22
|
+
def on_send(node)
|
23
|
+
if (result = in_line_calls(node))
|
24
|
+
result
|
25
|
+
else
|
26
|
+
super
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def in_line_calls(node)
|
31
|
+
called_on, method_name, *args = *node
|
32
|
+
# TODO: Deal with args by replacing lvar with passed objects
|
33
|
+
return unless args.empty? && called_on_self?(called_on)
|
34
|
+
called_method = called_method(method_name)
|
35
|
+
return unless called_method
|
36
|
+
processed_called_method = process(called_method.body.ast)
|
37
|
+
node.updated(processed_called_method.type, processed_called_method.children)
|
38
|
+
end
|
39
|
+
|
40
|
+
def called_on_self?(called_on)
|
41
|
+
called_on.nil? || called_on.type == :self
|
42
|
+
end
|
43
|
+
|
44
|
+
def called_method(method_name)
|
45
|
+
defs.detect { |_def| _def.name == method_name }
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module DissociatedIntrospection
|
2
|
+
class RubyClass
|
3
|
+
class CreateDef
|
4
|
+
attr_reader :ast, :comments
|
5
|
+
|
6
|
+
def initialize(ast, comments)
|
7
|
+
@ast = ast
|
8
|
+
@comments = comments
|
9
|
+
end
|
10
|
+
|
11
|
+
def create
|
12
|
+
def_comments = comments.select do |comment|
|
13
|
+
comment.location.last_line + 1 == ast.location.first_line
|
14
|
+
end
|
15
|
+
Def.new(RubyCode.build_from_ast(ast, comments: def_comments))
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -1,28 +1,41 @@
|
|
1
1
|
module DissociatedIntrospection
|
2
2
|
class RubyClass
|
3
3
|
class Def
|
4
|
-
|
4
|
+
# @param [DissociatedIntrospection::RubyClass] ruby_code
|
5
5
|
def initialize(ruby_code)
|
6
6
|
@ruby_code = ruby_code
|
7
7
|
end
|
8
8
|
|
9
|
+
# @return [Symbol, NilClass]
|
9
10
|
def name
|
10
11
|
ruby_code.ast.children[0]
|
11
12
|
end
|
12
13
|
|
14
|
+
# @return [DissociatedIntrospection::RubyClass]
|
13
15
|
def arguments
|
14
|
-
|
16
|
+
RubyCode.build_from_ast(ruby_code.ast.children[1])
|
15
17
|
end
|
16
18
|
|
19
|
+
# @return [DissociatedIntrospection::RubyClass]
|
17
20
|
def body
|
18
|
-
|
21
|
+
RubyCode.build_from_ast(ruby_code.ast.children[2])
|
19
22
|
end
|
20
23
|
|
24
|
+
# @return [String]
|
21
25
|
def source
|
22
26
|
ruby_code.source
|
23
27
|
end
|
24
28
|
|
25
|
-
|
29
|
+
def to_s
|
30
|
+
ruby_code.source
|
31
|
+
end
|
32
|
+
|
33
|
+
# @return [Parser::AST]
|
34
|
+
def ast
|
35
|
+
ruby_code.ast
|
36
|
+
end
|
37
|
+
|
38
|
+
# @return [DissociatedIntrospection::RubyClass]
|
26
39
|
attr_reader :ruby_code
|
27
40
|
end
|
28
41
|
end
|
@@ -4,6 +4,7 @@ module DissociatedIntrospection
|
|
4
4
|
extend Forwardable
|
5
5
|
using Try
|
6
6
|
|
7
|
+
# @param [DissociatedIntrospection::RubyCode, String, Parse::AST, Hash{source: String, parse_with_comments: [Boolean]}] ruby_code
|
7
8
|
def initialize(ruby_code)
|
8
9
|
@ruby_code = if ruby_code.is_a?(Hash) && ruby_code.key?(:source)
|
9
10
|
RubyCode.build_from_source(
|
@@ -64,12 +65,12 @@ module DissociatedIntrospection
|
|
64
65
|
self.class.new(RubyCode.build_from_ast(new_ast, comments: comments))
|
65
66
|
end
|
66
67
|
|
67
|
-
# @return [DissociatedIntrospection::RubyClass::Def]
|
68
|
+
# @return [Array<DissociatedIntrospection::RubyClass::Def>]
|
68
69
|
def defs
|
69
70
|
class_begin.children.select { |n| n.try(:type) == :def }.map(&method(:create_def))
|
70
71
|
end
|
71
72
|
|
72
|
-
# @return [DissociatedIntrospection::RubyClass::Def]
|
73
|
+
# @return [Array<DissociatedIntrospection::RubyClass::Def>]
|
73
74
|
def class_defs
|
74
75
|
ns = class_begin.children.select { |n| :defs == n.try(:type) }.map do |n|
|
75
76
|
create_def(n.updated(:def, n.children[1..-1]))
|
@@ -81,6 +82,7 @@ module DissociatedIntrospection
|
|
81
82
|
[*ns, *ns2]
|
82
83
|
end
|
83
84
|
|
85
|
+
# @private
|
84
86
|
def inspect_methods(type=:instance_methods)
|
85
87
|
public_send(if type == :instance_methods
|
86
88
|
:defs
|
@@ -143,10 +145,7 @@ module DissociatedIntrospection
|
|
143
145
|
private
|
144
146
|
|
145
147
|
def create_def(n)
|
146
|
-
|
147
|
-
comment.location.last_line+1 == n.location.first_line
|
148
|
-
end
|
149
|
-
Def.new(RubyCode.build_from_ast(n, comments: def_comments))
|
148
|
+
CreateDef.new(n, comments).create
|
150
149
|
end
|
151
150
|
|
152
151
|
def scrub_inner_classes_ast
|
@@ -156,18 +155,16 @@ module DissociatedIntrospection
|
|
156
155
|
end
|
157
156
|
|
158
157
|
def find_class
|
159
|
-
depth_first_search(ast, :class)
|
158
|
+
depth_first_search(ast, :class) || ast
|
160
159
|
end
|
161
160
|
|
162
161
|
def depth_first_search(node, target, stop=nil)
|
163
162
|
return false unless node.is_a?(Parser::AST::Node)
|
164
163
|
return node if node.type == target
|
165
164
|
return false if stop && node.type == stop
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
return v if v.is_a?(Parser::AST::Node)
|
170
|
-
end
|
165
|
+
[*node.children].each do |kid|
|
166
|
+
v = depth_first_search(kid, target, stop)
|
167
|
+
return v if v.is_a?(Parser::AST::Node)
|
171
168
|
end
|
172
169
|
false
|
173
170
|
end
|
@@ -1,6 +1,5 @@
|
|
1
1
|
module DissociatedIntrospection
|
2
2
|
class RubyCode
|
3
|
-
|
4
3
|
# @param [String] source
|
5
4
|
# @param [true, false] parse_with_comments
|
6
5
|
# @return [DissociatedIntrospection::RubyCode]
|
@@ -52,6 +51,7 @@ module DissociatedIntrospection
|
|
52
51
|
def source
|
53
52
|
@source = @source.nil? ? source_from_ast : @source
|
54
53
|
end
|
54
|
+
alias_method :to_s, :source
|
55
55
|
|
56
56
|
# @return [String]
|
57
57
|
def source_from_ast
|
@@ -1,12 +1,15 @@
|
|
1
1
|
require 'parser/current'
|
2
2
|
require 'unparser'
|
3
|
+
require 'forwardable'
|
3
4
|
require 'dissociated_introspection/version'
|
4
5
|
require 'dissociated_introspection/try'
|
5
6
|
require 'dissociated_introspection/eval_sandbox'
|
6
7
|
require 'dissociated_introspection/wrap_in_modules'
|
7
8
|
require 'dissociated_introspection/ruby_code'
|
8
9
|
require 'dissociated_introspection/ruby_class'
|
10
|
+
require 'dissociated_introspection/ruby_class/create_def'
|
9
11
|
require 'dissociated_introspection/ruby_class/def'
|
12
|
+
require 'dissociated_introspection/method_in_liner'
|
10
13
|
require 'dissociated_introspection/inspection'
|
11
14
|
require 'dissociated_introspection/method_call'
|
12
15
|
|
metadata
CHANGED
@@ -1,69 +1,57 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dissociated_introspection
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.13.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dustin Zeisler
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-07-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: parser
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "~>"
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '2.1'
|
20
17
|
- - ">="
|
21
18
|
- !ruby/object:Gem::Version
|
22
|
-
version:
|
19
|
+
version: 3.1.2.0
|
23
20
|
type: :runtime
|
24
21
|
prerelease: false
|
25
22
|
version_requirements: !ruby/object:Gem::Requirement
|
26
23
|
requirements:
|
27
|
-
- - "~>"
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
version: '2.1'
|
30
24
|
- - ">="
|
31
25
|
- !ruby/object:Gem::Version
|
32
|
-
version:
|
26
|
+
version: 3.1.2.0
|
33
27
|
- !ruby/object:Gem::Dependency
|
34
28
|
name: unparser
|
35
29
|
requirement: !ruby/object:Gem::Requirement
|
36
30
|
requirements:
|
37
31
|
- - "~>"
|
38
32
|
- !ruby/object:Gem::Version
|
39
|
-
version:
|
40
|
-
- - ">="
|
41
|
-
- !ruby/object:Gem::Version
|
42
|
-
version: 0.2.6
|
33
|
+
version: 0.4.9
|
43
34
|
type: :runtime
|
44
35
|
prerelease: false
|
45
36
|
version_requirements: !ruby/object:Gem::Requirement
|
46
37
|
requirements:
|
47
38
|
- - "~>"
|
48
39
|
- !ruby/object:Gem::Version
|
49
|
-
version:
|
50
|
-
- - ">="
|
51
|
-
- !ruby/object:Gem::Version
|
52
|
-
version: 0.2.6
|
40
|
+
version: 0.4.9
|
53
41
|
- !ruby/object:Gem::Dependency
|
54
42
|
name: bundler
|
55
43
|
requirement: !ruby/object:Gem::Requirement
|
56
44
|
requirements:
|
57
45
|
- - "~>"
|
58
46
|
- !ruby/object:Gem::Version
|
59
|
-
version: '
|
47
|
+
version: '2.3'
|
60
48
|
type: :development
|
61
49
|
prerelease: false
|
62
50
|
version_requirements: !ruby/object:Gem::Requirement
|
63
51
|
requirements:
|
64
52
|
- - "~>"
|
65
53
|
- !ruby/object:Gem::Version
|
66
|
-
version: '
|
54
|
+
version: '2.3'
|
67
55
|
- !ruby/object:Gem::Dependency
|
68
56
|
name: rake
|
69
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -116,8 +104,10 @@ files:
|
|
116
104
|
- lib/dissociated_introspection/eval_sandbox.rb
|
117
105
|
- lib/dissociated_introspection/inspection.rb
|
118
106
|
- lib/dissociated_introspection/method_call.rb
|
107
|
+
- lib/dissociated_introspection/method_in_liner.rb
|
119
108
|
- lib/dissociated_introspection/recording_parent.rb
|
120
109
|
- lib/dissociated_introspection/ruby_class.rb
|
110
|
+
- lib/dissociated_introspection/ruby_class/create_def.rb
|
121
111
|
- lib/dissociated_introspection/ruby_class/def.rb
|
122
112
|
- lib/dissociated_introspection/ruby_code.rb
|
123
113
|
- lib/dissociated_introspection/try.rb
|
@@ -127,7 +117,7 @@ homepage: https://github.com/zeisler/dissociated_introspection
|
|
127
117
|
licenses:
|
128
118
|
- MIT
|
129
119
|
metadata: {}
|
130
|
-
post_install_message:
|
120
|
+
post_install_message:
|
131
121
|
rdoc_options: []
|
132
122
|
require_paths:
|
133
123
|
- lib
|
@@ -135,16 +125,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
135
125
|
requirements:
|
136
126
|
- - ">="
|
137
127
|
- !ruby/object:Gem::Version
|
138
|
-
version: '
|
128
|
+
version: '3.0'
|
139
129
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
140
130
|
requirements:
|
141
131
|
- - ">="
|
142
132
|
- !ruby/object:Gem::Version
|
143
133
|
version: '0'
|
144
134
|
requirements: []
|
145
|
-
|
146
|
-
|
147
|
-
signing_key:
|
135
|
+
rubygems_version: 3.3.7
|
136
|
+
signing_key:
|
148
137
|
specification_version: 4
|
149
138
|
summary: Introspect methods, parameters, class macros, and constants without loading
|
150
139
|
a parent class or any other dependencies.
|