Class: RecordStore::Record
- Inherits:
-
Object
- Object
- RecordStore::Record
show all
- Includes:
- ActiveModel::Validations
- Defined in:
- lib/record_store/record.rb
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
#fqdn ⇒ Object
Returns the value of attribute fqdn.
8
9
10
|
# File 'lib/record_store/record.rb', line 8
def fqdn
@fqdn
end
|
#id ⇒ Object
Returns the value of attribute id.
8
9
10
|
# File 'lib/record_store/record.rb', line 8
def id
@id
end
|
#ttl ⇒ Object
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
24
25
26
27
28
29
30
31
32
|
# File 'lib/record_store/record.rb', line 20
def self.build_from_yaml_definition(yaml_definition)
record_type = yaml_definition.fetch(:type)
case record_type
when 'ALIAS'
if yaml_definition.key?(:cname)
yaml_definition[:alias] = yaml_definition.delete(:cname)
end
end
Record.const_get(record_type).new(yaml_definition)
end
|
.ensure_ends_with_dot(fqdn) ⇒ Object
76
77
78
|
# File 'lib/record_store/record.rb', line 76
def self.ensure_ends_with_dot(fqdn)
fqdn.end_with?(".") ? fqdn : "#{fqdn}."
end
|
Instance Method Details
#==(other) ⇒ Object
Also known as:
eql?
50
51
52
|
# File 'lib/record_store/record.rb', line 50
def ==(other)
other.class == self.class && other.to_hash == self.to_hash
end
|
#hash ⇒ Object
56
57
58
|
# File 'lib/record_store/record.rb', line 56
def hash
to_hash.hash
end
|
#key ⇒ Object
64
65
66
|
# File 'lib/record_store/record.rb', line 64
def key
"#{type},#{fqdn}"
end
|
#log!(logger = STDOUT) ⇒ Object
34
35
36
|
# File 'lib/record_store/record.rb', line 34
def log!(logger=STDOUT)
logger.puts to_s
end
|
#to_hash ⇒ Object
38
39
40
41
42
43
44
|
# File 'lib/record_store/record.rb', line 38
def to_hash
{
type: type,
fqdn: fqdn,
ttl: ttl
}.merge(rdata)
end
|
#to_json ⇒ Object
60
61
62
|
# File 'lib/record_store/record.rb', line 60
def to_json
{ ttl: ttl, rdata: rdata }
end
|
#type ⇒ Object
46
47
48
|
# File 'lib/record_store/record.rb', line 46
def type
self.class.name.split('::').last
end
|