dissociated_introspection 0.9.1 → 0.13.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 943e04bc256389529fa5d43a1e0cba4fbb8a1451
4
- data.tar.gz: 6651fde5dde7b492b0adc926d96f5b1be689d0db
2
+ SHA256:
3
+ metadata.gz: e29a242da18895cccd18d06de8fae99dbc8ead7835c6b7650372ed96adc7b50e
4
+ data.tar.gz: 27710c993d783cdc7233de04167f219ab5e064300328a39c0bdab98af90b496d
5
5
  SHA512:
6
- metadata.gz: b4ab2267f0cccdcd2e8b6512f5ca6f33b85a4bf4cc0842b2b380b9dc2ce23741de14276cf2b205aaac312b1388ffc3e4a450f97d0a9d3852738223370195770d
7
- data.tar.gz: 1e22d5ec0bb0b2a23eb690c61bfdde2a4b0299b441e947a8929a3d72183db59a68f2dc03aa0c9832e0e260bfa9a6024c59f4cb7aa4066b7a3da15aaf5ea6b0f1
6
+ metadata.gz: 76fce8889a4f4a81d66b1a63a7f6b00e670d41cda764fbb01fb2fce1a8615e27597279fc7766fb13ddf020b2742b0d38068f4f41a4f3936ea2a96239ee666c37
7
+ data.tar.gz: ca2c807f35eaeaf35d5f2e259074527815c21017d4466f7b6a64d8be41b6e8f9e57c9af0092a3e8b55395c3589e05e85a7a0cce6832556074616754911ce4648
data/.travis.yml CHANGED
@@ -1,8 +1,8 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.1.9
4
- - 2.2.7
5
- - 2.3.4
6
- - 2.4.1
3
+ - 2.2.9
4
+ - 2.3.7
5
+ - 2.4.4
6
+ - 2.5.1
7
7
  sudo: false
8
8
  cache: bundler
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 = '>= 2.1'
22
+ spec.required_ruby_version = '>= 3.0'
23
23
 
24
- spec.add_runtime_dependency "parser", "~> 2.1", ">= 2.1.9"
25
- spec.add_runtime_dependency "unparser", "~> 0.2", ">= 0.2.6"
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", "~> 1.9"
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
@@ -1,8 +1,8 @@
1
1
  require 'ostruct'
2
+ require "pathname"
2
3
 
3
4
  module DissociatedIntrospection
4
5
  class Inspection
5
-
6
6
  # @param file [File]
7
7
  # @optional parent_class_replacement [Symbol]
8
8
  def initialize(file:, parent_class_replacement: :RecordingParent)
@@ -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
@@ -1,7 +1,5 @@
1
1
  class RecordingParent < BasicObject
2
-
3
2
  class << self
4
-
5
3
  def method_missing(m, *args, &block)
6
4
  __missing_class_macros__.push({ m => [args, block].compact })
7
5
  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
- Unparser.unparse(ruby_code.ast.children[1])
16
+ RubyCode.build_from_ast(ruby_code.ast.children[1])
15
17
  end
16
18
 
19
+ # @return [DissociatedIntrospection::RubyClass]
17
20
  def body
18
- Unparser.unparse(ruby_code.ast.children[2])
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
- private
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
- def_comments = comments.select do |comment|
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
- if (children = node.children)
167
- children.each do |kid|
168
- v = depth_first_search(kid, target, stop)
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,3 +1,3 @@
1
1
  module DissociatedIntrospection
2
- VERSION = "0.9.1"
2
+ VERSION = "0.13.0"
3
3
  end
@@ -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.9.1
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: 2018-01-16 00:00:00.000000000 Z
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: 2.1.9
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: 2.1.9
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: '0.2'
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: '0.2'
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: '1.9'
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: '1.9'
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: '2.1'
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
- rubyforge_project:
146
- rubygems_version: 2.6.11
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.