class TkInspect::Inspector::RootComponent

Attributes

inspector[RW]

Public Instance Methods

browse_class(e) click to toggle source
# File lib/tk_inspect/inspector/root_component.rb, line 56
def browse_class(e)
  item = @table.selected_item
  return unless item && (class_name = item[:klass])
  inspector.browse_class(class_name)
end
has_sub_items?(path) click to toggle source
# File lib/tk_inspect/inspector/root_component.rb, line 46
def has_sub_items?(path)
  path = [] if path.blank?
  if path.empty?
    return true # At least we have self
  else
    obj = path.last[:real_value]
    obj.children_for_tk_inspect.any?
  end
end
items_for_path(path = nil) click to toggle source
# File lib/tk_inspect/inspector/root_component.rb, line 25
def items_for_path(path = nil)
  path = [] if path.blank?
  if path.empty?
    self_exp = inspector.expression || 'self'
    self_value = eval(self_exp, inspector.inspected_binding)
    res = [{ var: self_exp, value: self_value.value_for_tk_inspect, klass: self_value.class.to_s, real_value: self_value }]
    if inspector.expression.blank?
      vars = inspector.inspected_binding.local_variables.sort.map do |var_name|
        value = inspector.inspected_binding.local_variable_get(var_name)
        res << { var: var_name, value: value.value_for_tk_inspect, klass: value.class.to_s, real_value: value }
      end
    end
    res
  else
    obj = path.last[:real_value]
    obj.children_for_tk_inspect.map do |child_name, child_value|
      { var: child_name, value: child_value.value_for_tk_inspect, klass: child_value.class.to_s, real_value: child_value }
    end
  end
end
render(p, parent_component) click to toggle source
# File lib/tk_inspect/inspector/root_component.rb, line 6
def render(p, parent_component)
  p.vframe(padding: "0 0 0 0", sticky: 'nsew', x_flex: 1, y_flex: 1) do |f|
    @table = f.insert_component(TkComponent::TableViewComponent, self,
                                data_source: self,
                                columns: [
                                  { key: :var, text: 'Variable', anchor: 'w' },
                                  { key: :value, text: 'Value', anchor: 'center' },
                                  { key: :klass, text: 'Class', anchor: 'center' }
                                ],
                                nested: true,
                                lazy: true,
                                sticky: 'nsew', x_flex: 1, y_flex: 1)
    f.hframe(sticky: 'se', padding: '8', x_flex: 1) do |hf|
      hf.button(text: "Browse selected class", on_click: :browse_class)
      hf.button(text: "Refresh", on_click: ->(e) { regenerate })
    end
  end
end