Class: IpNetwork

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
lib/antfarm/ip_network.rb

Overview

IpNetwork class that wraps the ip_networks table in the ANTFARM database.

  • belongs to a layer 3 network

  • belongs to a private network

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#layer3_network_protocol=(value) ⇒ Object (writeonly)

Protocol of the layer 3 network automatically created for this IP network.



37
38
39
# File 'lib/antfarm/ip_network.rb', line 37

def layer3_network_protocol=(value)
  @layer3_network_protocol = value
end

#private_network_description=(value) ⇒ Object (writeonly)

Description of the private network to be created for this IP network if it’s private.



41
42
43
# File 'lib/antfarm/ip_network.rb', line 41

def private_network_description=(value)
  @private_network_description = value
end

Instance Method Details

#address=(ip_addr) ⇒ Object

Overriding the address setter in order to create an instance variable for an Antfarm::IPAddrExt object ip_net. This way the rest of the methods in this class can confidently access the ip address for this network.

the method address= is called by the constructor of this class.



50
51
52
53
# File 'lib/antfarm/ip_network.rb', line 50

def address=(ip_addr) #:nodoc:
  @ip_net = Antfarm::IPAddrExt.new(ip_addr)
  super(@ip_net.to_cidr_string)
end

#to_labelObject

This is for ActiveScaffold



67
68
69
# File 'lib/antfarm/ip_network.rb', line 67

def to_label #:nodoc:
  return address
end

#validateObject

Validate data for requirements before saving network to the database.

Was using validate_on_create, but decided that these restraints should occur on anything saved to the database at any time, including a create and an update.



59
60
61
62
63
64
# File 'lib/antfarm/ip_network.rb', line 59

def validate #:nodoc:
  # Don't save the network if it's a loopback network.
  unless !@ip_net.loopback_address?
    errors.add(:address, "loopback address not allowed")
  end
end