Class: PuppetX::Unbound::ValidateAddrs
- Inherits:
-
Object
- Object
- PuppetX::Unbound::ValidateAddrs
- Defined in:
- lib/puppet_x/unbound/validate_addrs.rb
Instance Attribute Summary collapse
-
#ip_list ⇒ Object
readonly
Returns the value of attribute ip_list.
-
#name_list ⇒ Object
readonly
Returns the value of attribute name_list.
Instance Method Summary collapse
-
#initialize(address_list) ⇒ ValidateAddrs
constructor
A new instance of ValidateAddrs.
- #is_ip?(address) ⇒ Boolean
- #validate ⇒ Object
Constructor Details
#initialize(address_list) ⇒ ValidateAddrs
Returns a new instance of ValidateAddrs.
13 14 15 16 17 18 |
# File 'lib/puppet_x/unbound/validate_addrs.rb', line 13 def initialize(address_list) @address_list = Array(address_list).flatten @ip_list = [] @name_list = [] validate() end |
Instance Attribute Details
#ip_list ⇒ Object (readonly)
Returns the value of attribute ip_list.
11 12 13 |
# File 'lib/puppet_x/unbound/validate_addrs.rb', line 11 def ip_list @ip_list end |
#name_list ⇒ Object (readonly)
Returns the value of attribute name_list.
11 12 13 |
# File 'lib/puppet_x/unbound/validate_addrs.rb', line 11 def name_list @name_list end |
Instance Method Details
#is_ip?(address) ⇒ Boolean
46 47 48 49 50 51 52 53 |
# File 'lib/puppet_x/unbound/validate_addrs.rb', line 46 def is_ip?(address) begin IPAddr.new address return true rescue return false end end |
#validate ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/puppet_x/unbound/validate_addrs.rb', line 20 def validate @address_list.each {|a| if a =~ /@.*@/ raise Puppet::ParseError, "Too many @ signs in #{a}" elsif a =~ /@/ addr, port = a.split('@') begin Integer(port) rescue raise Puppet::ParseError, "Specifed port is not numeric in #{port}" end if is_ip?(addr) @ip_list << a else @name_list << a end else if is_ip?(a) @ip_list << a else @name_list << a end end } end |