Class: Net::IP::Route

Inherits:
Object
  • Object
show all
Defined in:
lib/net/ip/route.rb,
lib/net/ip/route/parser.rb,
lib/net/ip/route/collection.rb

Overview

Class for working with routing table entries.

Defined Under Namespace

Classes: Collection, Parser

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ Route

Note:

This does NOT add the entry to the routing table. See Net::IP::Route::Collection#add for creating new routes in the routing table.

Create a new route object

Examples:

Create a default route

Net::IP::Route.new(:prefix => 'default', :via => '192.168.0.1')

Create a normal route

Net::IP::Route.new(:prefix => '10.0.0.0/8', :dev => 'eth0')

Parameters:

  • params (Hash) (defaults to: {})


14
15
16
17
18
# File 'lib/net/ip/route.rb', line 14

def initialize(params = {})
  params.each do |k,v|
    instance_variable_set("@#{k}", v)
  end
end

Instance Attribute Details

#prefixObject (readonly)

Returns the value of attribute prefix.



5
6
7
# File 'lib/net/ip/route.rb', line 5

def prefix
  @prefix
end

#viaObject (readonly)

Returns the value of attribute via.



5
6
7
# File 'lib/net/ip/route.rb', line 5

def via
  @via
end

Instance Method Details

#to_paramsObject



20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/net/ip/route.rb', line 20

def to_params
  str = ""
  str << "via #{@via} " if @via
  str << "dev #{@dev} " if @dev
  str << "weight #{@weight}" if @weight
  str << " table #{@table} " if @table
  str << " proto #{@proto} " if @proto
  str << " scope #{@scope} " if @scope
  str << " src #{@src} " if @src
  str << " metric #{@metric} " if @metric
  str << " error #{@error}" if @error
  str
end