Class: Coppertone::Modifier::Exp
- Inherits:
-
Base
- Object
- Coppertone::Modifier
- Base
- Coppertone::Modifier::Exp
- Defined in:
- lib/coppertone/modifier/exp.rb
Overview
Exp modifier - specifying a message to be returned in case of failure
Constant Summary collapse
- ASCII_REGEXP =
/\A[[:ascii:]]*\z/
Constants inherited from Coppertone::Modifier
Instance Attribute Summary
Attributes inherited from Base
Attributes inherited from Coppertone::Modifier
Class Method Summary collapse
Instance Method Summary collapse
- #evaluate(macro_context, request_context) ⇒ Object
- #lookup_macro_string(target_name, request_context) ⇒ Object
Methods inherited from Base
#==, #context_dependent?, #includes_ptr?, #initialize, #target_name_from_domain_spec
Methods inherited from Coppertone::Modifier
build, build_unknown, class_builder, #initialize, #label, matching_term, register, #to_s
Constructor Details
This class inherits a constructor from Coppertone::Modifier::Base
Class Method Details
.create(attributes) ⇒ Object
7 8 9 |
# File 'lib/coppertone/modifier/exp.rb', line 7 def self.create(attributes) new(attributes) end |
.label ⇒ Object
33 34 35 |
# File 'lib/coppertone/modifier/exp.rb', line 33 def self.label 'exp' end |
Instance Method Details
#evaluate(macro_context, request_context) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/coppertone/modifier/exp.rb', line 12 def evaluate(macro_context, request_context) target_name = target_name_from_domain_spec(macro_context, request_context) return nil unless target_name macro_string = lookup_macro_string(target_name, request_context) return nil unless macro_string = macro_string.(macro_context, request_context) return nil unless ASCII_REGEXP.match() rescue DNSAdapter::Error nil end |
#lookup_macro_string(target_name, request_context) ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/coppertone/modifier/exp.rb', line 25 def lookup_macro_string(target_name, request_context) records = request_context.dns_client.fetch_txt_records(target_name) return nil if records.empty? return nil if records.size > 1 MacroString.new(records.first[:text]) end |