Class: TkInspect::Inspector::RootComponent

Inherits:
TkComponent::Base
  • Object
show all
Defined in:
lib/tk_inspect/inspector/root_component.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#inspectorObject

Returns the value of attribute inspector.



4
5
6
# File 'lib/tk_inspect/inspector/root_component.rb', line 4

def inspector
  @inspector
end

Instance Method Details

#browse_class(e) ⇒ Object



56
57
58
59
60
# 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) ⇒ Boolean

Returns:

  • (Boolean)


46
47
48
49
50
51
52
53
54
# 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) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# 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) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# 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