class TkInspect::ClassBrowser::Base

Attributes

browsing_method[RW]
class_data_sources[RW]
main_component[RW]
module_method_data_source[RW]
selected_class_path[RW]
selected_method[RW]
selected_module[RW]
tk_root[RW]

Public Class Methods

new() click to toggle source
# File lib/tk_inspect/class_browser/base.rb, line 13
def initialize
  @tk_root = nil
  @main_component = nil
  @selected_class_path = []
  @loaded_code = {}
  @class_filter = nil
  @browsing_method = 'hierarchy'
  @class_data_sources = {
    hierarchy: ClassTreeDataSource.new,
    namespaces: ClassNamespaceDataSource.new
  }.with_indifferent_access
  @module_method_data_source = ModuleMethodDataSource.new
end

Public Instance Methods

class_data_source() click to toggle source
# File lib/tk_inspect/class_browser/base.rb, line 38
def class_data_source
  @class_data_sources[browsing_method]
end
code_for_file(file) click to toggle source
# File lib/tk_inspect/class_browser/base.rb, line 72
def code_for_file(file)
  @loaded_code[file] || begin
                          @loaded_code[file] = IO.read(file)
                          @loaded_code[file]
                        end
end
code_for_method(meth) click to toggle source
# File lib/tk_inspect/class_browser/base.rb, line 61
def code_for_method(meth)
  return nil unless meth.present?
  class_name = selected_class_name
  return nil unless class_name.present?
  klass = Object.const_get(class_name)
  method = klass.instance_method(meth)
  file, line = method.source_location
  return nil unless file && line
  return code_for_file(file), line, file
end
create_root() click to toggle source
# File lib/tk_inspect/class_browser/base.rb, line 31
def create_root
  @tk_root = TkComponent::Window.new(title: "Class Browser")
  @main_component = RootComponent.new
  @main_component.class_browser = self
  @tk_root.place_root_component(@main_component)
end
refresh() click to toggle source
# File lib/tk_inspect/class_browser/base.rb, line 27
def refresh
  @main_component.nil? ? create_root : @main_component.regenerate
end
select_class_name(class_name) click to toggle source
# File lib/tk_inspect/class_browser/base.rb, line 42
def select_class_name(class_name)
  self.browsing_method = 'hierarchy'
  class_path = class_data_source.path_for_class(class_name)
  select_class_path(class_path)
end
select_class_path(class_path) click to toggle source
# File lib/tk_inspect/class_browser/base.rb, line 52
def select_class_path(class_path)
  self.selected_class_path = class_path
  module_method_data_source.selected_class = selected_class_name
end
selected_class_name() click to toggle source
# File lib/tk_inspect/class_browser/base.rb, line 57
def selected_class_name
  browsing_method.to_s == 'hierarchy' ? self.selected_class_path.last : self.selected_class_path.join('::')
end
show_current_path() click to toggle source
# File lib/tk_inspect/class_browser/base.rb, line 48
def show_current_path
  @main_component.show_current_selection
end