dissociated_introspection 0.1.2 → 0.1.3

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
2
  SHA1:
3
- metadata.gz: d849d81fbfed605aef10279579f64a7bf4c6c919
4
- data.tar.gz: e6ea63a48f9efceaa3f114f293f646925d164b3f
3
+ metadata.gz: 4132b5ad0c5655e9caa5db59a8bc9ba45491b17d
4
+ data.tar.gz: c51638262fdd7f96ee519735a3a325f4c05af8af
5
5
  SHA512:
6
- metadata.gz: e328b5c631c8b886b27b4bdb041f393b71233b8f84fd355a006fad02410bd440e8a5232f4800982b10727d04aa5c6fd7ab601a9880dd6b8e65394aecee43347b
7
- data.tar.gz: edc4a6562641d90a9515206a8a276a5321f9606f8ca71a34f7343a6a32c18c9d4845ae9d458421a808b2ada00c8795acfd0a4342d39684fe1557b167bfd34ca2
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
- def class_macros(type=nil)
16
- # FIXME
17
- return get_class.__missing_class_macros__ if type.nil?
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
- const = self.const_set(const_sym, Class.new)
16
- const.extend ConstMissing
17
- const.module_eval(<<-RUBY, __FILE__, __LINE__+1)
18
- def self.name
19
- "#{name.gsub(/#<Module:.*>::/, '')}::#{const_sym}"
20
- end
21
-
22
- def self.inspect
23
- name
24
- end
25
- RUBY
26
- RecordingParent.__missing_constants__[const_sym] = const
27
- const
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
@@ -1,3 +1,3 @@
1
1
  module DissociatedIntrospection
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dissociated_introspection
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dustin Zeisler