Class: DnsMock::Record::Factory::Base

Inherits:
Object
  • Object
show all
Extended by:
Error::Helper
Defined in:
lib/dns_mock/record/factory/base.rb

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Error::Helper

raise_record_context_type_error, raise_record_type_error

Constructor Details

#initialize(dns_name = ::Resolv::DNS::Name, punycode_representer = DnsMock::Representer::Punycode, record_data:) ⇒ Base

Returns a new instance of Base.



26
27
28
29
30
31
32
33
34
# File 'lib/dns_mock/record/factory/base.rb', line 26

def initialize(
  dns_name = ::Resolv::DNS::Name,
  punycode_representer = DnsMock::Representer::Punycode,
  record_data:
)
  @dns_name = dns_name
  @punycode_representer = punycode_representer
  @record_data = record_data
end

Class Attribute Details

.target_classObject (readonly)

Returns the value of attribute target_class.



10
11
12
# File 'lib/dns_mock/record/factory/base.rb', line 10

def target_class
  @target_class
end

Class Method Details

.record_type(record_type) ⇒ Object



12
13
14
15
16
# File 'lib/dns_mock/record/factory/base.rb', line 12

def record_type(record_type)
  @target_class = ::Resolv::DNS::Resource::IN.const_get(
    record_type_check(record_type).upcase
  )
end

Instance Method Details

#createObject



38
39
40
41
42
# File 'lib/dns_mock/record/factory/base.rb', line 38

def create
  self.class.target_class.new(*instance_params)
rescue => error
  raise DnsMock::Error::RecordContext.new(error.message, record_type)
end

#instance_paramsObject



36
# File 'lib/dns_mock/record/factory/base.rb', line 36

def instance_params; end