Class: Looksee::Adapter::Base
- Inherits:
-
Object
- Object
- Looksee::Adapter::Base
- Defined in:
- lib/looksee/adapter/base.rb
Direct Known Subclasses
Instance Method Summary collapse
-
#describe_module(mod) ⇒ Object
Return a description of the given module.
- #has_no_methods?(mod) ⇒ Boolean
- #internal_undefined_instance_methods(mod) ⇒ Object
-
#lookup_modules(object) ⇒ Object
Return the chain of classes and modules which comprise the object’s method lookup path.
- #module_name(mod) ⇒ Object
- #singleton_instance(singleton_class) ⇒ Object
Instance Method Details
#describe_module(mod) ⇒ Object
Return a description of the given module.
This is used for the module labels in the Inspector output.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/looksee/adapter/base.rb', line 24 def describe_module(mod) Module === mod or raise TypeError, "expected Module, got: #{mod.inspect}" num_brackets = 0 object = mod while (instance = singleton_instance(object)) num_brackets += 1 object = instance end if object.is_a?(Module) description = module_name(object) if description.empty? is_class = Class === object description = "unnamed #{is_class ? 'Class' : 'Module'}" end else description = "#{module_name(object.class)} instance" end if num_brackets == 0 description else "#{'['*num_brackets}#{description}#{']'*num_brackets}" end end |
#has_no_methods?(mod) ⇒ Boolean
55 56 57 58 59 |
# File 'lib/looksee/adapter/base.rb', line 55 def has_no_methods?(mod) [:public, :protected, :private].all? do |visibility| Looksee.safe_call(Module, "#{visibility}_instance_methods", mod, false).empty? end && internal_undefined_instance_methods(mod).empty? end |
#internal_undefined_instance_methods(mod) ⇒ Object
51 52 53 |
# File 'lib/looksee/adapter/base.rb', line 51 def internal_undefined_instance_methods(mod) raise NotImplementedError, "abstract" end |
#lookup_modules(object) ⇒ Object
Return the chain of classes and modules which comprise the object’s method lookup path.
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/looksee/adapter/base.rb', line 8 def lookup_modules(object) start = begin singleton_class = (class << object; self; end) singleton_class unless has_no_methods?(singleton_class) && !(Class === object) rescue TypeError # immediate object end start ||= Looksee.safe_call(Object, :class, object) start.ancestors end |
#module_name(mod) ⇒ Object
65 66 67 |
# File 'lib/looksee/adapter/base.rb', line 65 def module_name(mod) Looksee.safe_call(Module, :name, mod) || '' end |
#singleton_instance(singleton_class) ⇒ Object
61 62 63 |
# File 'lib/looksee/adapter/base.rb', line 61 def singleton_instance(singleton_class) raise NotImplementedError, "abstract" end |