Class: Linux::Ip::Route::IpRoute

Inherits:
Object
  • Object
show all
Defined in:
lib/linux/ip/route.rb

Defined Under Namespace

Classes: IfaceRoute, Options, ViaRoute

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeIpRoute

Returns a new instance of IpRoute.



10
11
12
13
# File 'lib/linux/ip/route.rb', line 10

def initialize
  @interfaces = {}
  @routes = []
end

Instance Attribute Details

#interfacesObject (readonly)

Returns the value of attribute interfaces.



9
10
11
# File 'lib/linux/ip/route.rb', line 9

def interfaces
  @interfaces
end

#routesObject (readonly)

Returns the value of attribute routes.



9
10
11
# File 'lib/linux/ip/route.rb', line 9

def routes
  @routes
end

Instance Method Details

#add_dev(dev, dst, options) ⇒ Object



67
68
69
70
71
72
# File 'lib/linux/ip/route.rb', line 67

def add_dev(dev, dst, options)
  @interfaces[dev] ||= []
  route = IfaceRoute.new(dst, dev, Options.new(options))
  @interfaces[dev] << route
  @routes << route
end

#add_via(dev, dst, via, options = "") ⇒ Object



49
50
51
52
53
54
# File 'lib/linux/ip/route.rb', line 49

def add_via(dev, dst, via, options = "")
  @interfaces[dev] ||= []
  route = ViaRoute.new(dst, via, dev, Options.new(options))
  @interfaces[dev] << route
  @routes << route
end

#as_commands(direction = 'add') ⇒ Object



15
16
17
18
19
# File 'lib/linux/ip/route.rb', line 15

def as_commands(direction = 'add')
  @routes.map do |route|
    route.as_commands(direction)
  end.flatten.compact.join("\n")
end

#execute_addObject



21
22
23
# File 'lib/linux/ip/route.rb', line 21

def execute_add
  system as_commands("add")
end

#execute_delObject



24
25
26
# File 'lib/linux/ip/route.rb', line 24

def execute_del
  system as_commands("del")
end

#find(name) ⇒ Object



77
78
79
# File 'lib/linux/ip/route.rb', line 77

def find(name)
  interfaces.find { |i| i.name == name }
end

#lengthObject



74
75
76
# File 'lib/linux/ip/route.rb', line 74

def length
  interfaces.length
end