class Coppertone::Mechanism::DomainSpecOptional

Parent class for mechanisms that use an optional domain spec.

Public Class Methods

create(attributes) click to toggle source
# File lib/coppertone/mechanism/domain_spec_optional.rb, line 7
def self.create(attributes)
  new(attributes)
end
new(attributes) click to toggle source
Calls superclass method Coppertone::Mechanism::new
# File lib/coppertone/mechanism/domain_spec_optional.rb, line 11
def initialize(attributes)
  super(attributes)
  return if attributes.blank?

  raw_domain_spec = trim_domain_spec(attributes)
  @domain_spec = Coppertone::DomainSpec.new(raw_domain_spec)
rescue Coppertone::MacroStringParsingError
  raise Coppertone::InvalidMechanismError
end

Public Instance Methods

generate_target_name(macro_context, request_context) click to toggle source
# File lib/coppertone/mechanism/domain_spec_optional.rb, line 31
def generate_target_name(macro_context, request_context)
  if domain_spec
    target_name_from_domain_spec(macro_context, request_context)
  else
    macro_context.domain
  end
end
handle_invalid_domain(_macro_context, _options) click to toggle source
# File lib/coppertone/mechanism/domain_spec_optional.rb, line 39
def handle_invalid_domain(_macro_context, _options)
  raise RecordParsingError
end
match?(macro_context, request_context) click to toggle source
# File lib/coppertone/mechanism/domain_spec_optional.rb, line 21
def match?(macro_context, request_context)
  request_context.register_dns_lookup_term
  target_name = generate_target_name(macro_context, request_context)
  if target_name
    match_target_name(macro_context, request_context, target_name)
  else
    handle_invalid_domain(macro_context, request_context)
  end
end