dissociated_introspection 0.1.2 → 0.1.3
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
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4132b5ad0c5655e9caa5db59a8bc9ba45491b17d
|
4
|
+
data.tar.gz: c51638262fdd7f96ee519735a3a325f4c05af8af
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2d49c20e5ccb107ceb57ee9834307d7075159ff02f4e83d87f2dda3c5630b624f76dcf2d2d42bc6be7605b180070823adc2de20e471b646bb5511a88d1de1b6b
|
7
|
+
data.tar.gz: 7907ee3d1c8f6b9703ffbe0753cfbb7b13b6c7d49e6edd14d933a32220dd15e6da11c1331c80e3d80312c9b60d5d9ef037622be6818babfd2a9cf23cbd858f6c
|
@@ -3,40 +3,57 @@ require 'ostruct'
|
|
3
3
|
module DissociatedIntrospection
|
4
4
|
class Inspection
|
5
5
|
|
6
|
+
# @param file [File]
|
7
|
+
# @optional parent_class_replacement [Symbol]
|
6
8
|
def initialize(file:, parent_class_replacement: :RecordingParent)
|
7
9
|
@file = file
|
8
10
|
@parent_class_replacement = parent_class_replacement
|
9
11
|
end
|
10
12
|
|
13
|
+
# @return [Class]
|
11
14
|
def get_class
|
12
15
|
@get_class ||= _get_class
|
13
16
|
end
|
14
17
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
+
# @return [Array]
|
19
|
+
def class_macros
|
20
|
+
get_class.__missing_class_macros__
|
18
21
|
end
|
19
22
|
|
23
|
+
# @return [Array<Module>]
|
20
24
|
def extended_modules
|
21
25
|
find_class_macro_by_type(:extend) { |a| add_method_name_wo_parent a.first }
|
22
26
|
end
|
23
27
|
|
28
|
+
# @return [Array<Module>]
|
24
29
|
def included_modules
|
25
30
|
find_class_macro_by_type(:include) { |a| add_method_name_wo_parent a.first }
|
26
31
|
end
|
27
32
|
|
33
|
+
# @return [Array<Module>]
|
28
34
|
def prepend_modules
|
29
35
|
find_class_macro_by_type(:prepend) { |a| add_method_name_wo_parent a.first }
|
30
36
|
end
|
31
37
|
|
38
|
+
# @return [Hash{String => Module}]
|
32
39
|
def missing_constants
|
33
40
|
get_class.__missing_constants__
|
34
41
|
end
|
35
42
|
|
43
|
+
# @optional type [Module, Class]
|
44
|
+
# @return [Array<Symbol>]
|
45
|
+
def locally_defined_constants(type=nil)
|
46
|
+
consts = get_class.constants - get_class.__missing_constants__.keys - [:BasicObject]
|
47
|
+
return consts unless type
|
48
|
+
consts.select{ |c| get_class.const_get(c).is_a?(type)}
|
49
|
+
end
|
50
|
+
|
51
|
+
# @return [DissociatedIntrospection::RubyClass]
|
36
52
|
def parsed_source
|
37
53
|
@parsed_source ||= RubyClass.new(source: file.read)
|
38
54
|
end
|
39
55
|
|
56
|
+
# @return [Module]
|
40
57
|
def sandbox_module
|
41
58
|
@sandbox_module ||= Module.new
|
42
59
|
end
|
@@ -3,7 +3,7 @@ class RecordingParent < BasicObject
|
|
3
3
|
class << self
|
4
4
|
|
5
5
|
def method_missing(m, *args, &block)
|
6
|
-
__missing_class_macros__.push({m => [args, block].compact})
|
6
|
+
__missing_class_macros__.push({ m => [args, block].compact })
|
7
7
|
end
|
8
8
|
|
9
9
|
def __missing_class_macros__
|
@@ -12,19 +12,23 @@ class RecordingParent < BasicObject
|
|
12
12
|
|
13
13
|
module ConstMissing
|
14
14
|
def const_missing(const_sym)
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
15
|
+
if const_defined?("::#{const_sym}")
|
16
|
+
Kernel.const_get("::#{const_sym}")
|
17
|
+
else
|
18
|
+
const = self.const_set(const_sym, Module.new)
|
19
|
+
const.extend ConstMissing
|
20
|
+
const.module_eval(<<-RUBY, __FILE__, __LINE__+1)
|
21
|
+
def self.name
|
22
|
+
"#{name.gsub(/#<Module:.*>::/, '')}::#{const_sym}"
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.inspect
|
26
|
+
name
|
27
|
+
end
|
28
|
+
RUBY
|
29
|
+
RecordingParent.__missing_constants__[const_sym] = const
|
30
|
+
const
|
31
|
+
end
|
28
32
|
end
|
29
33
|
end
|
30
34
|
|
@@ -85,6 +85,10 @@ module DissociatedIntrospection
|
|
85
85
|
Unparser.unparse(ast)
|
86
86
|
end
|
87
87
|
|
88
|
+
def scrub_inner_classes
|
89
|
+
self.class.new(ast: find_class.updated(find_class.type, class_begin.updated(class_begin.type, class_begin.children.reject { |n| n.try(:type) == :class })))
|
90
|
+
end
|
91
|
+
|
88
92
|
private
|
89
93
|
|
90
94
|
attr_reader :source
|