Class: Coppertone::DomainSpec
- Inherits:
-
MacroString
- Object
- MacroString
- Coppertone::DomainSpec
- Defined in:
- lib/coppertone/domain_spec.rb
Overview
A domain spec, as defined in the SPF specification.
Constant Summary collapse
- EXP_ONLY_MACRO_LETTERS =
%w[c r t].freeze
Instance Attribute Summary
Attributes inherited from MacroString
Instance Method Summary collapse
- #ends_in_allowed_term? ⇒ Boolean
- #ends_with_top_label? ⇒ Boolean
-
#initialize(s) ⇒ DomainSpec
constructor
A new instance of DomainSpec.
- #only_allowed_macros? ⇒ Boolean
- #validate_domain_spec_restrictions ⇒ Object
Methods inherited from MacroString
#==, #context_dependent?, #expand, #hash, #includes_ptr?, #macros, #to_s
Constructor Details
#initialize(s) ⇒ DomainSpec
Returns a new instance of DomainSpec.
7 8 9 10 11 12 13 14 |
# File 'lib/coppertone/domain_spec.rb', line 7 def initialize(s) begin super rescue Coppertone::MacroStringParsingError raise Coppertone::DomainSpecParsingError end validate_domain_spec_restrictions end |
Instance Method Details
#ends_in_allowed_term? ⇒ Boolean
28 29 30 31 32 33 34 35 |
# File 'lib/coppertone/domain_spec.rb', line 28 def ends_in_allowed_term? lm = @macros.last return true unless lm return false if lm.is_a?(Coppertone::MacroString::MacroStaticExpand) return true if lm.is_a?(Coppertone::MacroString::MacroExpand) ends_with_top_label? end |
#ends_with_top_label? ⇒ Boolean
37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/coppertone/domain_spec.rb', line 37 def ends_with_top_label? ends_with = @macros.last.to_s ends_with = ends_with[0..-2] if ends_with[-1] == '.' _, match, tail = ends_with.rpartition('.') return false if match.blank? hostname = Coppertone::Utils::DomainUtils.valid_tld?(tail) return false unless hostname true end |
#only_allowed_macros? ⇒ Boolean
23 24 25 26 |
# File 'lib/coppertone/domain_spec.rb', line 23 def only_allowed_macros? @macros.select { |m| m.is_a?(Coppertone::MacroString::MacroExpand) } .none? { |m| EXP_ONLY_MACRO_LETTERS.include?(m.macro_letter) } end |
#validate_domain_spec_restrictions ⇒ Object
16 17 18 19 20 |
# File 'lib/coppertone/domain_spec.rb', line 16 def validate_domain_spec_restrictions return if only_allowed_macros? && ends_in_allowed_term? raise Coppertone::DomainSpecParsingError end |