Class: Net::Record

Inherits:
Object
  • Object
show all
Includes:
Validations
Defined in:
lib/net.rb

Direct Known Subclasses

DHCP::Record, DNS::Record

Constant Summary

Constants included from Validations

Validations::IP_REGEXP, Validations::MAC_REGEXP

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Validations

normalize_ip, normalize_mac, #validate_ip, #validate_mac, #validate_network

Constructor Details

#initialize(opts = {}) ⇒ Record

Returns a new instance of Record

Raises:


8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/net.rb', line 8

def initialize opts = {}
  # set all attributes
  opts.each do |k,v|
    eval("self.#{k}= v") if self.respond_to?("#{k}=")
  end if opts

  raise Net::LeaseConflict.new("#{self.mac}/#{self.ip}") if opts['state']

  self.logger ||= Rails.logger
  raise "Must define a hostname" if hostname.blank?
  raise "Must define a proxy"    if proxy.nil?
end

Instance Attribute Details

#hostnameObject

Returns the value of attribute hostname


6
7
8
# File 'lib/net.rb', line 6

def hostname
  @hostname
end

#loggerObject

Returns the value of attribute logger


6
7
8
# File 'lib/net.rb', line 6

def logger
  @logger
end

#proxyObject

Returns the value of attribute proxy


6
7
8
# File 'lib/net.rb', line 6

def proxy
  @proxy
end

Instance Method Details

#==(other) ⇒ Object

Compares two records by their attributes


36
37
38
39
# File 'lib/net.rb', line 36

def == other
  return false unless other.respond_to? :attrs
  self.attrs == other.attrs
end

#conflicting?Boolean

Do we have conflicting entries?


26
27
28
# File 'lib/net.rb', line 26

def conflicting?
  !conflicts.empty?
end

#inspectObject


21
22
23
# File 'lib/net.rb', line 21

def inspect
  to_s
end

#reload!Object

clears internal cache


31
32
33
# File 'lib/net.rb', line 31

def reload!
  @conflicts = nil
end