Class: Ifconf::Ipv6Config
- Inherits:
-
Object
- Object
- Ifconf::Ipv6Config
- Defined in:
- lib/ifconf/ipv6_config.rb
Overview
Holds an interface’s IPv6 address, prefix length, and scope (global, link, or host).
Instance Attribute Summary collapse
-
#address ⇒ Object
readonly
Returns the value of attribute address.
-
#prefix_length ⇒ Object
readonly
Returns the value of attribute prefix_length.
-
#scope ⇒ Object
readonly
Returns the value of attribute scope.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #global? ⇒ Boolean
- #hash ⇒ Object
- #includes_ip?(ip) ⇒ Boolean
-
#initialize(address, prefix_length, scope) ⇒ Ipv6Config
constructor
A new instance of Ipv6Config.
- #link_local? ⇒ Boolean
- #to_cidr_string ⇒ Object
Constructor Details
#initialize(address, prefix_length, scope) ⇒ Ipv6Config
Returns a new instance of Ipv6Config.
25 26 27 28 29 30 |
# File 'lib/ifconf/ipv6_config.rb', line 25 def initialize(address, prefix_length, scope) @address = address @prefix_length = prefix_length @scope = scope freeze end |
Instance Attribute Details
#address ⇒ Object (readonly)
Returns the value of attribute address.
7 8 9 |
# File 'lib/ifconf/ipv6_config.rb', line 7 def address @address end |
#prefix_length ⇒ Object (readonly)
Returns the value of attribute prefix_length.
7 8 9 |
# File 'lib/ifconf/ipv6_config.rb', line 7 def prefix_length @prefix_length end |
#scope ⇒ Object (readonly)
Returns the value of attribute scope.
7 8 9 |
# File 'lib/ifconf/ipv6_config.rb', line 7 def scope @scope end |
Class Method Details
.build(addr:, prefix:, scope: nil) ⇒ Object
9 10 11 12 13 |
# File 'lib/ifconf/ipv6_config.rb', line 9 def self.build(addr:, prefix:, scope: nil) address = Network::IP.new(addr) scope ||= derive_scope(address) new(address, prefix, scope) end |
.derive_scope(address) ⇒ Object
15 16 17 18 19 20 21 22 23 |
# File 'lib/ifconf/ipv6_config.rb', line 15 def self.derive_scope(address) if address.link_local? :link elsif address.loopback? :host else :global end end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
42 43 44 45 46 47 |
# File 'lib/ifconf/ipv6_config.rb', line 42 def ==(other) other.is_a?(Ipv6Config) && @address == other.address && @prefix_length == other.prefix_length && @scope == other.scope end |
#global? ⇒ Boolean
32 |
# File 'lib/ifconf/ipv6_config.rb', line 32 def global? = @scope == :global |
#hash ⇒ Object
51 |
# File 'lib/ifconf/ipv6_config.rb', line 51 def hash = [@address, @prefix_length, @scope].hash |
#includes_ip?(ip) ⇒ Boolean
35 36 37 38 |
# File 'lib/ifconf/ipv6_config.rb', line 35 def includes_ip?(ip) cidr = Network::IPRange::CIDR.new("#{@address}/#{@prefix_length}") cidr.include?(ip.to_s) end |
#link_local? ⇒ Boolean
33 |
# File 'lib/ifconf/ipv6_config.rb', line 33 def link_local? = @scope == :link |
#to_cidr_string ⇒ Object
40 |
# File 'lib/ifconf/ipv6_config.rb', line 40 def to_cidr_string = "#{@address}/#{@prefix_length}" |