Class: EZDyn::RecordType

Inherits:
Object
  • Object
show all
Defined in:
lib/ezdyn/record_type.rb

Overview

Encapsulates the properties of supported record types

Constant Summary collapse

@@types =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, uri_name:, value_key:) ⇒ RecordType

RecordType constructor. In general there is no reason to call this method directly as all known record types are created at file load time. Instead the #find method is the preferred way to fetch a RecordType object.

Parameters:

  • name (Symbol)

    The canonical type of the record.

  • uri_name (String)

    URI path element for the record type.

  • value_key (String)

    Record data value dict key.



27
28
29
30
31
32
# File 'lib/ezdyn/record_type.rb', line 27

def initialize(name:, uri_name:, value_key:)
  EZDyn.debug { "RecordType.new( name: #{name}, uri_name: #{uri_name}, value_key: #{value_key} )" }
  @name =  name
  @uri_name = uri_name
  @value_key = value_key
end

Instance Attribute Details

#uri_nameObject (readonly)

The URI path element that signals this record type.



15
16
17
# File 'lib/ezdyn/record_type.rb', line 15

def uri_name
  @uri_name
end

#value_keyObject (readonly)

The dict key for this record type’s rdata value.



18
19
20
# File 'lib/ezdyn/record_type.rb', line 18

def value_key
  @value_key
end

Class Method Details

.find(to_find) ⇒ EZDyn::RecordType

Converts several possible representations of a RecordType into an appropriate class instance. Pass in a RecordType instance, a String or Symbol of the type name or the String fragment of a REST API URI.

Parameters:

  • to_find (EZDyn::RecordType, String, Symbol)

    Representation of the paramter to be found.

Returns:



42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/ezdyn/record_type.rb', line 42

def self.find(to_find)
  EZDyn.debug { "RecordType#find( [#{to_find.class}] #{to_find} )" }
  if to_find.is_a? RecordType
    return to_find

  else
    return @@types.find { |ctype| ctype.name == to_find.to_s.upcase } ||
             @@types.find { |ctype| ctype.uri_name.downcase == to_find.to_s.downcase }
  end

  EZDyn.debug { "No such RecordType was found" }
end

.valid_type?(t) ⇒ Boolean

Check if a type is valid.

Returns:

  • (Boolean)

    Whether the type given is valid.



10
11
12
# File 'lib/ezdyn/record_type.rb', line 10

def self.valid_type?(t)
  not RecordType.find(t).nil?
end

Instance Method Details

#nameString

Provides an all-caps String representation of the record type, eg ‘A’,‘CNAME’.

Returns:

  • (String)

    The name of the record type.



58
59
60
# File 'lib/ezdyn/record_type.rb', line 58

def name
  @name.to_s.upcase
end

#to_sString

Converts the RecordType to the all-caps String of the record type.

Returns:

  • (String)

    The displayable String representation.



65
66
67
# File 'lib/ezdyn/record_type.rb', line 65

def to_s
  self.name
end