Class: RecordStore::Record

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Validations
Defined in:
lib/record_store/record.rb

Direct Known Subclasses

A, AAAA, ALIAS, CNAME, MX, NS, SPF, SRV, TXT

Defined Under Namespace

Classes: A, AAAA, ALIAS, CNAME, MX, NS, SPF, SRV, TXT

Constant Summary collapse

FQDN_REGEX =
/\A(\*\.)?([a-z0-9_]+(-[a-z0-9]+)*\._?)+[a-z]{2,}\.\Z/i
CNAME_REGEX =
/\A(\*\.)?([a-z0-9]+((-|--)?[a-z0-9]+)*\._?)+[a-z]{2,}\.\Z/i

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(record) ⇒ Record

Returns a new instance of Record.



14
15
16
17
18
# File 'lib/record_store/record.rb', line 14

def initialize(record)
  @fqdn = Record.ensure_ends_with_dot(record.fetch(:fqdn))
  @ttl  = record.fetch(:ttl)
  @id   = record.fetch(:record_id, nil)
end

Instance Attribute Details

#fqdnObject

Returns the value of attribute fqdn.



8
9
10
# File 'lib/record_store/record.rb', line 8

def fqdn
  @fqdn
end

#idObject

Returns the value of attribute id.



8
9
10
# File 'lib/record_store/record.rb', line 8

def id
  @id
end

#ttlObject

Returns the value of attribute ttl.



8
9
10
# File 'lib/record_store/record.rb', line 8

def ttl
  @ttl
end

Class Method Details

.build_from_yaml_definition(yaml_definition) ⇒ Object



20
21
22
23
# File 'lib/record_store/record.rb', line 20

def self.build_from_yaml_definition(yaml_definition)
  record_type = yaml_definition.fetch(:type)
  Record.const_get(record_type).new(yaml_definition)
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?



41
42
43
# File 'lib/record_store/record.rb', line 41

def ==(other)
  other.class == self.class && other.to_hash == self.to_hash
end

#hashObject



47
48
49
# File 'lib/record_store/record.rb', line 47

def hash
  to_hash.hash
end

#keyObject



55
56
57
# File 'lib/record_store/record.rb', line 55

def key
  "#{type},#{fqdn}"
end

#log!(logger = STDOUT) ⇒ Object



25
26
27
# File 'lib/record_store/record.rb', line 25

def log!(logger=STDOUT)
  logger.puts to_s
end

#rdataObject

Raises:

  • (NotImplementedError)


59
60
61
# File 'lib/record_store/record.rb', line 59

def rdata
  raise NotImplementedError
end

#rdata_txtObject

Raises:

  • (NotImplementedError)


63
64
65
# File 'lib/record_store/record.rb', line 63

def rdata_txt
  raise NotImplementedError
end

#to_hashObject



29
30
31
32
33
34
35
# File 'lib/record_store/record.rb', line 29

def to_hash
  {
    type: type,
    fqdn: fqdn,
    ttl: ttl
  }.merge(rdata)
end

#to_jsonObject



51
52
53
# File 'lib/record_store/record.rb', line 51

def to_json
  { ttl: ttl, rdata: rdata }
end

#to_sObject



67
68
69
70
# File 'lib/record_store/record.rb', line 67

def to_s
  rr_type = self.class.name.demodulize
  "[#{rr_type}Record] #{fqdn} #{ttl} IN #{rr_type} #{rdata_txt}"
end

#typeObject



37
38
39
# File 'lib/record_store/record.rb', line 37

def type
  self.class.name.split('::').last
end