Class: SPF::Query::Record
- Inherits:
-
Object
- Object
- SPF::Query::Record
- Includes:
- Enumerable
- Defined in:
- lib/spf/query/record.rb
Overview
Represents a parsed SPF record.
Instance Attribute Summary collapse
-
#a ⇒ Array<Mechanism>
readonly
Selects all
a:
mechanisms. -
#all ⇒ Mechanism?
readonly
The right-most
all:
mechanism. -
#exists ⇒ Array<Mechanism>
readonly
Selects all
exists:
mechanisms. -
#exp ⇒ Modifier?
readonly
The
exp=
modifier. -
#include ⇒ Array<Mechanism>
readonly
Selects all
include:
mechanisms. -
#ip4 ⇒ Array<Mechanism>
readonly
Selects all
ip4:
mechanisms. -
#ip6 ⇒ Array<Mechanism>
readonly
Selects all
ip6:
mechanisms. -
#mechanisms ⇒ Array<Mechanism>
readonly
All mechanisms within the record.
-
#modifiers ⇒ Array<Modifier>
readonly
All modifiers within the record.
-
#mx ⇒ Array<Mechanism>
readonly
Selects all
mx:
mechanisms. -
#ptr ⇒ Array<Mechanism>
readonly
Selects all
ptr:
mechanisms. -
#redirect ⇒ Modifier?
readonly
The
redirect=
modifier. -
#rules ⇒ Array<Mechanism, Modifier>
readonly
The SPF rules.
-
#version ⇒ :spf1
(also: #v)
readonly
The SPF version of the record.
Class Method Summary collapse
-
.parse(spf) ⇒ Record
Parses an SPF record.
-
.query(domain, resolver = Resolv::DNS.new) ⇒ Record?
Queries the domain for it's SPF record.
Instance Method Summary collapse
-
#each {|rule| ... } ⇒ Enumerator
Enumerates over the rules.
-
#initialize(version, rules = []) ⇒ Record
constructor
Initializes the SPF record.
-
#inspect ⇒ String
Inspects the record.
-
#to_s ⇒ String
Converts the record back to a String.
Constructor Details
#initialize(version, rules = []) ⇒ Record
Initializes the SPF record.
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/spf/query/record.rb', line 96 def initialize(version,rules=[]) @version = version @rules = rules @mechanisms = @rules.select { |term| term.kind_of?(Mechanism) } @modifiers = @rules.select { |term| term.kind_of?(Modifier) } # prefer the last `all:` mechanism @all = @mechanisms.reverse_each.find do |mechanism| mechanism.name == :all end mechanisms_by_name = lambda { |name| @mechanisms.select { |mechanism| mechanism.name == name } } @include = mechanisms_by_name[:include] @a = mechanisms_by_name[:a] @mx = mechanisms_by_name[:mx] @ptr = mechanisms_by_name[:ptr] @ip4 = mechanisms_by_name[:ip4] @ip6 = mechanisms_by_name[:ip6] @exists = mechanisms_by_name[:exists] modifier_by_name = lambda { |name| @modifiers.find { |modifier| modifier.name == name } } @redirect = modifier_by_name[:redirect] @exp = modifier_by_name[:exp] end |
Instance Attribute Details
#a ⇒ Array<Mechanism> (readonly)
Selects all a:
mechanisms.
50 51 52 |
# File 'lib/spf/query/record.rb', line 50 def a @a end |
#all ⇒ Mechanism? (readonly)
The right-most all:
mechanism.
40 41 42 |
# File 'lib/spf/query/record.rb', line 40 def all @all end |
#exists ⇒ Array<Mechanism> (readonly)
Selects all exists:
mechanisms.
75 76 77 |
# File 'lib/spf/query/record.rb', line 75 def exists @exists end |
#exp ⇒ Modifier? (readonly)
The exp=
modifier.
85 86 87 |
# File 'lib/spf/query/record.rb', line 85 def exp @exp end |
#include ⇒ Array<Mechanism> (readonly)
Selects all include:
mechanisms.
45 46 47 |
# File 'lib/spf/query/record.rb', line 45 def include @include end |
#ip4 ⇒ Array<Mechanism> (readonly)
Selects all ip4:
mechanisms.
65 66 67 |
# File 'lib/spf/query/record.rb', line 65 def ip4 @ip4 end |
#ip6 ⇒ Array<Mechanism> (readonly)
Selects all ip6:
mechanisms.
70 71 72 |
# File 'lib/spf/query/record.rb', line 70 def ip6 @ip6 end |
#mechanisms ⇒ Array<Mechanism> (readonly)
All mechanisms within the record.
30 31 32 |
# File 'lib/spf/query/record.rb', line 30 def mechanisms @mechanisms end |
#modifiers ⇒ Array<Modifier> (readonly)
All modifiers within the record.
35 36 37 |
# File 'lib/spf/query/record.rb', line 35 def modifiers @modifiers end |
#mx ⇒ Array<Mechanism> (readonly)
Selects all mx:
mechanisms.
55 56 57 |
# File 'lib/spf/query/record.rb', line 55 def mx @mx end |
#ptr ⇒ Array<Mechanism> (readonly)
Selects all ptr:
mechanisms.
60 61 62 |
# File 'lib/spf/query/record.rb', line 60 def ptr @ptr end |
#redirect ⇒ Modifier? (readonly)
The redirect=
modifier.
80 81 82 |
# File 'lib/spf/query/record.rb', line 80 def redirect @redirect end |
#rules ⇒ Array<Mechanism, Modifier> (readonly)
The SPF rules.
25 26 27 |
# File 'lib/spf/query/record.rb', line 25 def rules @rules end |
#version ⇒ :spf1 (readonly) Also known as: v
The SPF version of the record.
19 20 21 |
# File 'lib/spf/query/record.rb', line 19 def version @version end |
Class Method Details
.parse(spf) ⇒ Record
Parses an SPF record.
146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/spf/query/record.rb', line 146 def self.parse(spf) if spf.include?('spf2.0') raise(SenderIDFound,"Sender ID was found in place of SPF") end begin Parser.parse(spf) rescue Parslet::ParseFailed => error raise(InvalidRecord.new(error.,error.cause)) end end |
Instance Method Details
#each {|rule| ... } ⇒ Enumerator
Enumerates over the rules.
191 192 193 |
# File 'lib/spf/query/record.rb', line 191 def each(&block) @rules.each(&block) end |
#inspect ⇒ String
Inspects the record.
209 210 211 |
# File 'lib/spf/query/record.rb', line 209 def inspect "#<#{self.class}: #{self}>" end |
#to_s ⇒ String
Converts the record back to a String.
200 201 202 |
# File 'lib/spf/query/record.rb', line 200 def to_s "v=#{@version} #{@rules.join(' ')}" end |