Class: DnsMock::Server::RecordsDictionaryBuilder
- Inherits:
-
Object
- Object
- DnsMock::Server::RecordsDictionaryBuilder
- Includes:
- Error::Helper
- Defined in:
- lib/dns_mock/server/records_dictionary_builder.rb
Constant Summary collapse
- IP_ADDRESS_PATTERN =
/\A((1\d|[1-9]|2[0-4])?\d|25[0-5])(\.\g<1>){3}\z/.freeze
- TYPE_MAPPER =
DnsMock::AVAILABLE_DNS_RECORD_TYPES.zip( [ [DnsMock::Record::Builder::A, DnsMock::Record::Factory::A, ::Array], [DnsMock::Record::Builder::Aaaa, DnsMock::Record::Factory::Aaaa, ::Array], [DnsMock::Record::Builder::Cname, DnsMock::Record::Factory::Cname, ::String], [DnsMock::Record::Builder::Mx, DnsMock::Record::Factory::Mx, ::Array], [DnsMock::Record::Builder::Ns, DnsMock::Record::Factory::Ns, ::Array], [DnsMock::Record::Builder::Ptr, DnsMock::Record::Factory::Ptr, ::Array], [DnsMock::Record::Builder::Soa, DnsMock::Record::Factory::Soa, ::Array], [DnsMock::Record::Builder::Srv, DnsMock::Record::Factory::Srv, ::Array], [DnsMock::Record::Builder::Txt, DnsMock::Record::Factory::Txt, ::Array] ] ).to_h.freeze
Instance Attribute Summary collapse
-
#records ⇒ Object
readonly
Returns the value of attribute records.
Class Method Summary collapse
Instance Method Summary collapse
- #build(records_to_build) ⇒ Object
-
#initialize(punycode_representer = DnsMock::Representer::Punycode, rdns_lookup_representer = DnsMock::Representer::RdnsLookup) ⇒ RecordsDictionaryBuilder
constructor
A new instance of RecordsDictionaryBuilder.
Methods included from Error::Helper
#raise_record_context_type_error, #raise_record_type_error
Constructor Details
#initialize(punycode_representer = DnsMock::Representer::Punycode, rdns_lookup_representer = DnsMock::Representer::RdnsLookup) ⇒ RecordsDictionaryBuilder
Returns a new instance of RecordsDictionaryBuilder.
29 30 31 32 33 34 35 36 |
# File 'lib/dns_mock/server/records_dictionary_builder.rb', line 29 def initialize( punycode_representer = DnsMock::Representer::Punycode, rdns_lookup_representer = DnsMock::Representer::RdnsLookup ) @punycode_representer = punycode_representer @rdns_lookup_representer = rdns_lookup_representer @records = {} end |
Instance Attribute Details
#records ⇒ Object (readonly)
Returns the value of attribute records.
27 28 29 |
# File 'lib/dns_mock/server/records_dictionary_builder.rb', line 27 def records @records end |
Class Method Details
.call(records_to_build) ⇒ Object
23 24 25 |
# File 'lib/dns_mock/server/records_dictionary_builder.rb', line 23 def self.call(records_to_build) new.build(records_to_build).records end |
Instance Method Details
#build(records_to_build) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/dns_mock/server/records_dictionary_builder.rb', line 38 def build(records_to_build) raise_unless(DnsMock::Error::ArgumentType.new(records_to_build.class), records_to_build.is_a?(::Hash)) records_to_build.each do |hostname, dns_records| raise_unless(DnsMock::Error::RecordHostType.new(hostname, hostname.class), hostname.is_a?(::String)) records[representer(hostname)] = dns_records.each_with_object({}) do |(record_type, records_data), records_instances_by_type| records_instances_by_type[record_type] = build_records_instances_by_type(record_type, records_data) end end self end |