class DNSer::Record

Attributes

domain[R]
host[W]

Public Class Methods

new(domain, host, params = {}) click to toggle source
# File lib/dnser/record.rb, line 24
def initialize domain, host, params = {}

  ttl domain.ttl
  priority 0 unless @priority_val

  unless host.is_a? Symbol
    @host = host.dup
  else
    @host = host
  end

  @domain = domain
end

Public Instance Methods

comment(v = nil) click to toggle source
# File lib/dnser/record.rb, line 70
def comment(v = nil)
  @comment = v if v
  @comment || ''
end
full_host() click to toggle source
# File lib/dnser/record.rb, line 53
def full_host
  short_host = host
  if short_host == '@'
    domain.name
  else
    [short_host, domain.name].join('.')
  end
end
host() click to toggle source
# File lib/dnser/record.rb, line 49
def host
  DNSer.config.full_domain ? expand_domain(@host.to_s) : collapse_domain(@host.to_s)
end
prio(*args)
Alias for: priority
priority(*args) click to toggle source
# File lib/dnser/record.rb, line 42
def priority(*args)
  @priority_val = args.first if args.size == 1
  @priority_val
end
Also aliased as: prio
ttl(value) click to toggle source
# File lib/dnser/record.rb, line 38
def ttl(value)
  @ttl = value
end
type() click to toggle source
# File lib/dnser/record.rb, line 62
def type
  raise NotImplementedError
end
value() click to toggle source
# File lib/dnser/record.rb, line 66
def value
  raise NotImplementedError
end

Protected Instance Methods

canonical_host( target_host ) click to toggle source
# File lib/dnser/record.rb, line 103
def canonical_host( target_host )

  case host
    when DNSer::Record
      target_host = target_host.full_host.to_s
    when IPAddr
      target_host = target_host.to_s
    else

      ip = IPAddr.new target_host rescue nil
      return target_host.to_s if ip

      target_host = target_host.to_s
      target_host = target_host + '.' unless target_host.end_with? '.'
  end

  target_host

end
collapse_domain( name ) click to toggle source
# File lib/dnser/record.rb, line 83
def collapse_domain( name )

  name = name.dup

  return name if name == '@'
  return name unless name.end_with?('.')

  name = name + '.' unless name.end_with?('.')

  name.gsub!( domain.name.dup, '')
  name.chop! if name.end_with?('.')

  if name.empty?
    '@'
  else
    name
  end

end
expand_domain( name ) click to toggle source
# File lib/dnser/record.rb, line 77
def expand_domain( name )
  return domain.host if name == '@'
  return [name, domain.host].join('.') unless name.end_with?('.')
  name
end