Class: SPF::Query::Record
- Inherits:
-
Object
- Object
- SPF::Query::Record
- Includes:
- Enumerable
- Defined in:
- lib/spf/query/record.rb
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.
93 94 95 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 |
# File 'lib/spf/query/record.rb', line 93 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.
47 48 49 |
# File 'lib/spf/query/record.rb', line 47 def a @a end |
#all ⇒ Mechanism? (readonly)
The right-most all: mechanism.
37 38 39 |
# File 'lib/spf/query/record.rb', line 37 def all @all end |
#exists ⇒ Array<Mechanism> (readonly)
Selects all exists: mechanisms.
72 73 74 |
# File 'lib/spf/query/record.rb', line 72 def exists @exists end |
#exp ⇒ Modifier? (readonly)
The exp= modifier.
82 83 84 |
# File 'lib/spf/query/record.rb', line 82 def exp @exp end |
#include ⇒ Array<Mechanism> (readonly)
Selects all include: mechanisms.
42 43 44 |
# File 'lib/spf/query/record.rb', line 42 def include @include end |
#ip4 ⇒ Array<Mechanism> (readonly)
Selects all ip4: mechanisms.
62 63 64 |
# File 'lib/spf/query/record.rb', line 62 def ip4 @ip4 end |
#ip6 ⇒ Array<Mechanism> (readonly)
Selects all ip6: mechanisms.
67 68 69 |
# File 'lib/spf/query/record.rb', line 67 def ip6 @ip6 end |
#mechanisms ⇒ Array<Mechanism> (readonly)
All mechanisms within the record.
27 28 29 |
# File 'lib/spf/query/record.rb', line 27 def mechanisms @mechanisms end |
#modifiers ⇒ Array<Modifier> (readonly)
All modifiers within the record.
32 33 34 |
# File 'lib/spf/query/record.rb', line 32 def modifiers @modifiers end |
#mx ⇒ Array<Mechanism> (readonly)
Selects all mx: mechanisms.
52 53 54 |
# File 'lib/spf/query/record.rb', line 52 def mx @mx end |
#ptr ⇒ Array<Mechanism> (readonly)
Selects all ptr: mechanisms.
57 58 59 |
# File 'lib/spf/query/record.rb', line 57 def ptr @ptr end |
#redirect ⇒ Modifier? (readonly)
The redirect= modifier.
77 78 79 |
# File 'lib/spf/query/record.rb', line 77 def redirect @redirect end |
#rules ⇒ Array<Mechanism, Modifier> (readonly)
The SPF rules.
22 23 24 |
# File 'lib/spf/query/record.rb', line 22 def rules @rules end |
#version ⇒ :spf1 (readonly) Also known as: v
The SPF version of the record.
16 17 18 |
# File 'lib/spf/query/record.rb', line 16 def version @version end |
Class Method Details
.parse(spf) ⇒ Record
Parses an SPF record.
141 142 143 144 145 |
# File 'lib/spf/query/record.rb', line 141 def self.parse(spf) Parser.parse(spf) rescue Parslet::ParseFailed => error raise(InvalidRecord.new(error.,error.cause)) end |
Instance Method Details
#each {|rule| ... } ⇒ Enumerator
Enumerates over the rules.
180 181 182 |
# File 'lib/spf/query/record.rb', line 180 def each(&block) @rules.each(&block) end |
#inspect ⇒ String
Inspects the record.
198 199 200 |
# File 'lib/spf/query/record.rb', line 198 def inspect "#<#{self.class}: #{self}>" end |
#to_s ⇒ String
Converts the record back to a String.
189 190 191 |
# File 'lib/spf/query/record.rb', line 189 def to_s "v=#{@version} #{@rules.join(' ')}" end |