Class: Net::IP::Rule::Collection

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/net/ip/rule/collection.rb

Instance Method Summary collapse

Instance Method Details

#add(rule) ⇒ void

This method returns an undefined value.

Add a rule to the ip rule list

Examples:

Create a rule for 1.2.3.4 to use routing table ‘custom’

rule = Net::IP::Rule.new(:to => '1.2.3.4', :table => 'custom')
Net::IP.rules.add_rule(rule)

Parameters:

  • rule (Rule)

    Rule to add to the list.



23
24
25
26
# File 'lib/net/ip/rule/collection.rb', line 23

def add(rule)
  result = `ip rule add #{rule.to_params}`
  raise result unless $?.success?
end

#delete(rule) ⇒ void

This method returns an undefined value.

Delete a rule from the ip rule list

Examples:

Delete a rule for 1.2.3.4 using routing table ‘custom’

rule = Net::IP::Rule.new(:to => '1.2.3.4', :table => 'custom')
Net::IP.rules.delete_rule(rule)

Parameters:

  • rule (Rule)

    Rule to delete from the list.



34
35
36
37
# File 'lib/net/ip/rule/collection.rb', line 34

def delete(rule)
  result = `ip rule delete #{rule.to_params}`
  raise result unless $?.success?
end

#each {|Rule| ... } ⇒ void

This method returns an undefined value.

Enumerate all rules

Yields:



13
14
15
# File 'lib/net/ip/rule/collection.rb', line 13

def each(&block)
  Parser.parse(`ip rule list`).each {|r| yield(Rule.new(r))}
end