Class: Y2Network::Widgets::RoutingTable

Inherits:
CWM::Table
  • Object
show all
Defined in:
src/lib/y2network/widgets/routing_table.rb

Instance Method Summary collapse

Constructor Details

#initialize(routing_table) ⇒ RoutingTable


31
32
33
34
35
# File 'src/lib/y2network/widgets/routing_table.rb', line 31

def initialize(routing_table)
  textdomain "network"

  @routing_table = routing_table
end

Instance Method Details

#add_route(route) ⇒ Object


72
73
74
75
76
# File 'src/lib/y2network/widgets/routing_table.rb', line 72

def add_route(route)
  @routing_table.routes << route

  redraw_table
end

#delete_routeObject

deletes selected route


86
87
88
89
90
# File 'src/lib/y2network/widgets/routing_table.rb', line 86

def delete_route
  @routing_table.routes.delete_at(value)

  redraw_table
end

#headerObject


37
38
39
40
41
42
43
44
# File 'src/lib/y2network/widgets/routing_table.rb', line 37

def header
  [
    _("Destination"),
    _("Gateway"),
    _("Device"),
    Yast::Label.Options.delete("&")
  ]
end

#initObject

TODO: just workaround to make it work with old hash based CWM


61
62
63
64
# File 'src/lib/y2network/widgets/routing_table.rb', line 61

def init
  redraw_table
  disable if Yast::NetworkService.network_manager?
end

#itemsObject


46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'src/lib/y2network/widgets/routing_table.rb', line 46

def items
  @routing_table.routes.map.each_with_index do |route, index|
    [
      index,
      route.to.yield_self do |to|
        to == :default ? "default" : (to.to_s + "/" + to.prefix.to_s)
      end,
      route.gateway.nil? ? "-" : route.gateway.to_s,
      route.interface.nil? ? "-" : route.interface.name,
      route.options.to_s
    ]
  end
end

#redraw_tableObject


92
93
94
# File 'src/lib/y2network/widgets/routing_table.rb', line 92

def redraw_table
  change_items(items)
end

#replace_route(route) ⇒ Object

Replaces selected route with new one


79
80
81
82
83
# File 'src/lib/y2network/widgets/routing_table.rb', line 79

def replace_route(route)
  @routing_table.routes[value] = route

  redraw_table
end

#selected_routeObject


66
67
68
69
70
# File 'src/lib/y2network/widgets/routing_table.rb', line 66

def selected_route
  return nil unless value

  @routing_table.routes[value]
end