dissociated_introspection 0.9.1 → 0.11.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 +13 -0
- data/dissociated_introspection.gemspec +3 -3
- data/lib/dissociated_introspection.rb +3 -0
- 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 +40 -0
- data/lib/dissociated_introspection/recording_parent.rb +0 -2
- data/lib/dissociated_introspection/ruby_class.rb +6 -7
- 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_code.rb +1 -0
- data/lib/dissociated_introspection/version.rb +1 -1
- metadata +12 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 882e7dbe56d7d2cf361e7d572a72c955c74d58e0918140255ce15606a6f3cb3d
|
4
|
+
data.tar.gz: df0f04acc33076c45a5c2eb0a7c1d1d2ac40f901b931fbacfbd75210c5241068
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 91404ea1dddef2e77f98c9c81d0e73c4280a9313426c7ecd745a18e72aca525f78ac68d41c5f9ab393bd9284ac4133a293d70898e1416dbaabd6f22467d216b6
|
7
|
+
data.tar.gz: ced0ed7383e7a6ebf0b4c51a4ce5afffbeabaf5523131bdf5245578be4c7d48268653293be12712a26852928f5b3f85f318820749364308970d5069ebb9b036f
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,19 @@
|
|
1
1
|
# Changelog
|
2
2
|
All notable changes to this project will be documented in this file.
|
3
3
|
|
4
|
+
## 0.11.0 - 2018-08-01
|
5
|
+
### Enhancement
|
6
|
+
- Ability to Inline local methods with the exception of ones with arguments passed.
|
7
|
+
|
8
|
+
## 0.10.0 - 2018-07-28
|
9
|
+
### Fix
|
10
|
+
- Require Ruby core lib resources. (Forwardable, Pathname)
|
11
|
+
- Deal with change in how Ruby order's it's constants.
|
12
|
+
### Enhancement
|
13
|
+
- RubyClass::Def methods return RubyCode object so that AST could be inspected
|
14
|
+
### Deprecation
|
15
|
+
- Dropping support for Ruby version 2.1
|
16
|
+
|
4
17
|
## 0.9.1 - 2018-01-16
|
5
18
|
### Fix
|
6
19
|
- `DissociatedIntrospection::RubyClass#class_begin` added back to public API
|
@@ -19,10 +19,10 @@ 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 = '>= 2.
|
22
|
+
spec.required_ruby_version = '>= 2.2'
|
23
23
|
|
24
|
-
spec.add_runtime_dependency "parser", "~> 2.
|
25
|
-
spec.add_runtime_dependency "unparser", "~> 0.2", ">= 0.2.
|
24
|
+
spec.add_runtime_dependency "parser", "~> 2.2", ">= 2.2.1"
|
25
|
+
spec.add_runtime_dependency "unparser", "~> 0.2", ">= 0.2.8"
|
26
26
|
|
27
27
|
spec.add_development_dependency "bundler", "~> 1.9"
|
28
28
|
spec.add_development_dependency "rake", "~> 10.0"
|
@@ -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
|
|
@@ -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,40 @@
|
|
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
|
+
called_on, method_name, *args = *node
|
24
|
+
# TODO: Deal with args by replacing lvar with passed objects
|
25
|
+
return super unless args.empty? && called_on_self?(called_on)
|
26
|
+
called_method = called_method(method_name)
|
27
|
+
return super unless called_method
|
28
|
+
node.updated(called_method.body.ast.type, called_method.body.ast.children)
|
29
|
+
end
|
30
|
+
|
31
|
+
def called_on_self?(called_on)
|
32
|
+
called_on.nil? || called_on.type == :self
|
33
|
+
end
|
34
|
+
|
35
|
+
def called_method(method_name)
|
36
|
+
defs.detect { |_def| _def.name == method_name }
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
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,7 +155,7 @@ 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)
|
@@ -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
|
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.11.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: 2018-
|
11
|
+
date: 2018-08-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: parser
|
@@ -16,20 +16,20 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '2.
|
19
|
+
version: '2.2'
|
20
20
|
- - ">="
|
21
21
|
- !ruby/object:Gem::Version
|
22
|
-
version: 2.1
|
22
|
+
version: 2.2.1
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
26
26
|
requirements:
|
27
27
|
- - "~>"
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version: '2.
|
29
|
+
version: '2.2'
|
30
30
|
- - ">="
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version: 2.1
|
32
|
+
version: 2.2.1
|
33
33
|
- !ruby/object:Gem::Dependency
|
34
34
|
name: unparser
|
35
35
|
requirement: !ruby/object:Gem::Requirement
|
@@ -39,7 +39,7 @@ dependencies:
|
|
39
39
|
version: '0.2'
|
40
40
|
- - ">="
|
41
41
|
- !ruby/object:Gem::Version
|
42
|
-
version: 0.2.
|
42
|
+
version: 0.2.8
|
43
43
|
type: :runtime
|
44
44
|
prerelease: false
|
45
45
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -49,7 +49,7 @@ dependencies:
|
|
49
49
|
version: '0.2'
|
50
50
|
- - ">="
|
51
51
|
- !ruby/object:Gem::Version
|
52
|
-
version: 0.2.
|
52
|
+
version: 0.2.8
|
53
53
|
- !ruby/object:Gem::Dependency
|
54
54
|
name: bundler
|
55
55
|
requirement: !ruby/object:Gem::Requirement
|
@@ -116,8 +116,10 @@ files:
|
|
116
116
|
- lib/dissociated_introspection/eval_sandbox.rb
|
117
117
|
- lib/dissociated_introspection/inspection.rb
|
118
118
|
- lib/dissociated_introspection/method_call.rb
|
119
|
+
- lib/dissociated_introspection/method_in_liner.rb
|
119
120
|
- lib/dissociated_introspection/recording_parent.rb
|
120
121
|
- lib/dissociated_introspection/ruby_class.rb
|
122
|
+
- lib/dissociated_introspection/ruby_class/create_def.rb
|
121
123
|
- lib/dissociated_introspection/ruby_class/def.rb
|
122
124
|
- lib/dissociated_introspection/ruby_code.rb
|
123
125
|
- lib/dissociated_introspection/try.rb
|
@@ -135,7 +137,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
135
137
|
requirements:
|
136
138
|
- - ">="
|
137
139
|
- !ruby/object:Gem::Version
|
138
|
-
version: '2.
|
140
|
+
version: '2.2'
|
139
141
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
140
142
|
requirements:
|
141
143
|
- - ">="
|
@@ -143,7 +145,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
143
145
|
version: '0'
|
144
146
|
requirements: []
|
145
147
|
rubyforge_project:
|
146
|
-
rubygems_version: 2.
|
148
|
+
rubygems_version: 2.7.7
|
147
149
|
signing_key:
|
148
150
|
specification_version: 4
|
149
151
|
summary: Introspect methods, parameters, class macros, and constants without loading
|