Class: Linux::Ip::Route::IpRoute
- Inherits:
-
Object
- Object
- Linux::Ip::Route::IpRoute
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
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
#interfaces ⇒ Object
Returns the value of attribute interfaces.
9
10
11
|
# File 'lib/linux/ip/route.rb', line 9
def interfaces
@interfaces
end
|
#routes ⇒ Object
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_add ⇒ Object
21
22
23
|
# File 'lib/linux/ip/route.rb', line 21
def execute_add
system as_commands("add")
end
|
#execute_del ⇒ Object
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
|
#length ⇒ Object
74
75
76
|
# File 'lib/linux/ip/route.rb', line 74
def length
interfaces.length
end
|