Class: DissociatedIntrospection::Inspection
- Inherits:
-
Object
- Object
- DissociatedIntrospection::Inspection
- Defined in:
- lib/dissociated_introspection/inspection.rb
Instance Method Summary collapse
- #class_macros ⇒ Array
- #extended_modules ⇒ Array<Module>
- #get_class ⇒ Class
- #included_modules ⇒ Array<Module>
-
#initialize(file:, parent_class_replacement: :RecordingParent) ⇒ Inspection
constructor
A new instance of Inspection.
-
#locally_defined_constants(type = nil) ⇒ Hash{Symbol => Any}
].
- #missing_constants ⇒ Hash{String => Module}
- #parsed_source ⇒ DissociatedIntrospection::RubyClass
- #prepend_modules ⇒ Array<Module>
- #sandbox_module ⇒ Module
Constructor Details
#initialize(file:, parent_class_replacement: :RecordingParent) ⇒ Inspection
Returns a new instance of Inspection.
8 9 10 11 |
# File 'lib/dissociated_introspection/inspection.rb', line 8 def initialize(file:, parent_class_replacement: :RecordingParent) @file = file @parent_class_replacement = parent_class_replacement end |
Instance Method Details
#class_macros ⇒ Array
19 20 21 |
# File 'lib/dissociated_introspection/inspection.rb', line 19 def class_macros get_class.__missing_class_macros__ end |
#extended_modules ⇒ Array<Module>
24 25 26 |
# File 'lib/dissociated_introspection/inspection.rb', line 24 def extended_modules find_class_macro_by_type(:extend) { |a| add_method_referenced_name a.first } end |
#get_class ⇒ Class
14 15 16 |
# File 'lib/dissociated_introspection/inspection.rb', line 14 def get_class @get_class ||= get_sandbox_class end |
#included_modules ⇒ Array<Module>
29 30 31 |
# File 'lib/dissociated_introspection/inspection.rb', line 29 def included_modules find_class_macro_by_type(:include) { |a| add_method_referenced_name a.first } end |
#locally_defined_constants(type = nil) ⇒ Hash{Symbol => Any}
Returns ].
45 46 47 48 49 |
# File 'lib/dissociated_introspection/inspection.rb', line 45 def locally_defined_constants(type=nil) symbol_consts = get_class.constants - get_class.__missing_constants__.keys - [:BasicObject] consts = symbol_consts.each_with_object({}){|c, hash| hash[c] = get_class.const_get(c) } type ? consts.select { |s, c| c.is_a?(type) } : consts end |
#missing_constants ⇒ Hash{String => Module}
39 40 41 |
# File 'lib/dissociated_introspection/inspection.rb', line 39 def missing_constants get_class.__missing_constants__ end |
#parsed_source ⇒ DissociatedIntrospection::RubyClass
52 53 54 |
# File 'lib/dissociated_introspection/inspection.rb', line 52 def parsed_source @parsed_source ||= RubyClass.new(source: file.read, parse_with_comments: true) end |
#prepend_modules ⇒ Array<Module>
34 35 36 |
# File 'lib/dissociated_introspection/inspection.rb', line 34 def prepend_modules find_class_macro_by_type(:prepend) { |a| add_method_referenced_name a.first } end |
#sandbox_module ⇒ Module
57 58 59 |
# File 'lib/dissociated_introspection/inspection.rb', line 57 def sandbox_module @sandbox_module ||= Module.new end |