lib/dissociated_introspection/inspection.rb in dissociated_introspection-0.1.3 vs lib/dissociated_introspection/inspection.rb in dissociated_introspection-0.1.4

- old
+ new

@@ -43,11 +43,11 @@ # @optional type [Module, Class] # @return [Array<Symbol>] def locally_defined_constants(type=nil) consts = get_class.constants - get_class.__missing_constants__.keys - [:BasicObject] return consts unless type - consts.select{ |c| get_class.const_get(c).is_a?(type)} + consts.select { |c| get_class.const_get(c).is_a?(type) } end # @return [DissociatedIntrospection::RubyClass] def parsed_source @parsed_source ||= RubyClass.new(source: file.read) @@ -59,28 +59,31 @@ end private def add_method_name_wo_parent(_module) - def _module.referenced_name + _class_name_ = parsed_source.class_name + + _module.define_singleton_method(:referenced_name) do n = name.split("::") - return n[2..-1].join("::") if n.first =~ /#<Module:.*>/ - return n[1..-1].join("::") + n = n.drop(1) if n.first =~ /#<Module:.*>/ + n = n.drop(1) if n.first == _class_name_ + return n.join("::") end _module end def find_class_macro_by_type(type) get_class.__missing_class_macros__.select { |h| h.keys.first == type }.map { |h| yield(h.values.first.first) } end def _get_class modified_class_source = parsed_source.modify_parent_class(parent_class_replacement) - path = if file.is_a? Pathname - file.to_s - else - file.path - end + path = if file.is_a? Pathname + file.to_s + else + file.path + end load_sandbox(OpenStruct.new(read: modified_class_source.to_ruby_str, path: path)) end def load_sandbox(file) @klass ||= EvalSandbox.new(file: file, module_namespace: sandbox_module).call \ No newline at end of file