Class: Bind9mgr::ResourceRecord
- Inherits:
-
Object
- Object
- Bind9mgr::ResourceRecord
- Defined in:
- lib/resource_record.rb
Instance Attribute Summary collapse
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#klass ⇒ Object
Returns the value of attribute klass.
-
#owner ⇒ Object
Returns the value of attribute owner.
-
#rdata ⇒ Object
Returns the value of attribute rdata.
-
#ttl ⇒ Object
Returns the value of attribute ttl.
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
-
#gen_rr_string ⇒ Object
Validations.
-
#initialize(owner = nil, ttl = nil, klass = nil, type = nil, rdata = nil) ⇒ ResourceRecord
constructor
A new instance of ResourceRecord.
-
#valid? ⇒ Boolean
Validations.
- #validate_a ⇒ Object
- #validate_cname ⇒ Object
- #validate_mx ⇒ Object
- #validate_soa ⇒ Object
- #validate_txt ⇒ Object
Constructor Details
#initialize(owner = nil, ttl = nil, klass = nil, type = nil, rdata = nil) ⇒ ResourceRecord
Returns a new instance of ResourceRecord.
6 7 8 9 10 11 12 |
# File 'lib/resource_record.rb', line 6 def initialize owner = nil, ttl = nil, klass = nil, type = nil, rdata = nil @owner = owner @ttl = ttl @klass = klass @type = type @rdata = rdata end |
Instance Attribute Details
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
4 5 6 |
# File 'lib/resource_record.rb', line 4 def errors @errors end |
#klass ⇒ Object
Returns the value of attribute klass.
3 4 5 |
# File 'lib/resource_record.rb', line 3 def klass @klass end |
#owner ⇒ Object
Returns the value of attribute owner.
3 4 5 |
# File 'lib/resource_record.rb', line 3 def owner @owner end |
#rdata ⇒ Object
Returns the value of attribute rdata.
3 4 5 |
# File 'lib/resource_record.rb', line 3 def rdata @rdata end |
#ttl ⇒ Object
Returns the value of attribute ttl.
3 4 5 |
# File 'lib/resource_record.rb', line 3 def ttl @ttl end |
#type ⇒ Object
Returns the value of attribute type.
3 4 5 |
# File 'lib/resource_record.rb', line 3 def type @type end |
Instance Method Details
#gen_rr_string ⇒ Object
Validations
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/resource_record.rb', line 60 def gen_rr_string raise MalformedResourceRecord, "Owner:'#{@owner}', ttl:'#{@ttl}', class:'#{klass}', type:'#{type}', rdata:'#{rdata}'" unless self.valid? if @type == 'SOA' cont = '' cont << "#{@owner}\t#{@ttl}\t#{@klass}\t#{@type}\t#{rdata[0]} #{rdata[1]} (\n" cont << "\t#{Time.now.to_i} ; serial\n" cont << "\t#{rdata[3]} ; refresh\n" cont << "\t#{rdata[4]} ; retry\n" cont << "\t#{rdata[5]} ; expire\n" cont << "\t#{rdata[6]} ; minimum\n" cont << ")\n" else "#{@owner}\t#{@ttl}\t#{@klass}\t#{@type}\t#{[@rdata].flatten.join(' ')}\n" end end |
#valid? ⇒ Boolean
Validations
17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/resource_record.rb', line 17 def valid? @errors = [] (@errors << "Base type_and_rdata_shouldnt_be_blank"; return false) unless @type && @rdata (@errors << "Rdata rdata_shouldnt_be_blank_string"; return false) if @rdata.kind_of?(String) && (@rdata.length < 1 || !@rdata.match(/[^\.\;\,]/)) (@errors << "Owner invalid") if @owner && ( !@owner.kind_of?(String) || (@owner == 'localhost') ) (@errors << "Class invalid") if !klass.nil? && !KLASSES.include?( klass ) (@errors << "Type not_supported") unless ALLOWED_TYPES.include?( type ) validate_method_name = "validate_#{@type.downcase}" (self.send validate_method_name) if self.respond_to?(validate_method_name) return @errors.size == 0 end |
#validate_a ⇒ Object
38 39 40 41 |
# File 'lib/resource_record.rb', line 38 def validate_a (@errors << "Rdata should_be_a_string"; return false) unless @rdata.kind_of? String (@errors << "Rdata should_not_be_blank"; return false) if @rdata.length < 1 # TODO DRY it end |
#validate_cname ⇒ Object
43 44 45 46 |
# File 'lib/resource_record.rb', line 43 def validate_cname (@errors << "owner should_be_a_string"; return false) unless @owner.kind_of? String (@errors << "owner should_not_contain_only_digits"; return false) if @owner.match(/^\d+$/) end |
#validate_mx ⇒ Object
48 49 50 51 52 |
# File 'lib/resource_record.rb', line 48 def validate_mx (@errors << "Rdata should_be_an_array"; return false) unless @rdata.kind_of? Array (@errors << "Rdata should_contain_priority"; return false) unless @rdata[0].to_s.match(/^\d+$/) # TODO how about integer value (@errors << "Rdata target_should_not_contain_only_digits"; return false) if @rdata[1].match(/^\d+$/) end |
#validate_soa ⇒ Object
32 33 34 35 36 |
# File 'lib/resource_record.rb', line 32 def validate_soa (@errors << "Rdata should_be_an_array"; return false) unless @rdata.kind_of? Array (@errors << "Rdata should_have_7_elements"; return false) unless @rdata.size == 7 (@errors << "Base a record validation is under construction") unless @rdata[0].match(/\.$/) end |
#validate_txt ⇒ Object
54 55 |
# File 'lib/resource_record.rb', line 54 def validate_txt end |