Class: Coppertone::MacroContext
- Inherits:
-
Object
- Object
- Coppertone::MacroContext
- Defined in:
- lib/coppertone/macro_context.rb
Overview
A context used to evaluate MacroStrings. Responds to all of the macro letter directives except āpā.
Constant Summary collapse
- UNKNOWN_HOSTNAME =
'unknown'.freeze
- RESERVED_REGEXP =
Regexp.new("[^#{URI::PATTERN::UNRESERVED}]")
Instance Attribute Summary collapse
-
#domain ⇒ Object
(also: #d)
readonly
Returns the value of attribute domain.
-
#helo_domain ⇒ Object
(also: #h)
readonly
Returns the value of attribute helo_domain.
-
#hostname ⇒ Object
readonly
Returns the value of attribute hostname.
-
#ip_address_wrapper ⇒ Object
readonly
Returns the value of attribute ip_address_wrapper.
-
#sender_identity ⇒ Object
readonly
Returns the value of attribute sender_identity.
Instance Method Summary collapse
-
#initialize(domain, ip_as_s, sender, helo_domain = 'unknown', options = {}) ⇒ MacroContext
constructor
A new instance of MacroContext.
- #r ⇒ Object
- #raw_hostname ⇒ Object
- #t ⇒ Object
-
#with_domain(new_domain) ⇒ Object
Generates a new MacroContext with all the same info, but a new domain.
Constructor Details
#initialize(domain, ip_as_s, sender, helo_domain = 'unknown', options = {}) ⇒ MacroContext
Returns a new instance of MacroContext.
20 21 22 23 24 25 26 27 |
# File 'lib/coppertone/macro_context.rb', line 20 def initialize(domain, ip_as_s, sender, helo_domain = 'unknown', = {}) @ip_address_wrapper = IPAddressWrapper.new(ip_as_s) @sender_identity = SenderIdentity.new(sender) @domain = domain || @sender_identity.domain @helo_domain = helo_domain @hostname = [:hostname] end |
Instance Attribute Details
#domain ⇒ Object (readonly) Also known as: d
Returns the value of attribute domain.
10 11 12 |
# File 'lib/coppertone/macro_context.rb', line 10 def domain @domain end |
#helo_domain ⇒ Object (readonly) Also known as: h
Returns the value of attribute helo_domain.
10 11 12 |
# File 'lib/coppertone/macro_context.rb', line 10 def helo_domain @helo_domain end |
#hostname ⇒ Object (readonly)
Returns the value of attribute hostname.
19 20 21 |
# File 'lib/coppertone/macro_context.rb', line 19 def hostname @hostname end |
#ip_address_wrapper ⇒ Object (readonly)
Returns the value of attribute ip_address_wrapper.
10 11 12 |
# File 'lib/coppertone/macro_context.rb', line 10 def ip_address_wrapper @ip_address_wrapper end |
#sender_identity ⇒ Object (readonly)
Returns the value of attribute sender_identity.
10 11 12 |
# File 'lib/coppertone/macro_context.rb', line 10 def sender_identity @sender_identity end |
Instance Method Details
#r ⇒ Object
30 31 32 33 |
# File 'lib/coppertone/macro_context.rb', line 30 def r valid = Coppertone::Utils::DomainUtils.valid?(raw_hostname) valid ? raw_hostname : UNKNOWN_HOSTNAME end |
#raw_hostname ⇒ Object
47 48 49 50 51 52 |
# File 'lib/coppertone/macro_context.rb', line 47 def raw_hostname @raw_hostname ||= begin hostname || Coppertone.config.hostname || Coppertone::Utils::HostUtils.hostname end end |
#t ⇒ Object
35 36 37 |
# File 'lib/coppertone/macro_context.rb', line 35 def t Time.now.to_i end |
#with_domain(new_domain) ⇒ Object
Generates a new MacroContext with all the same info, but a new domain
56 57 58 59 60 |
# File 'lib/coppertone/macro_context.rb', line 56 def with_domain(new_domain) = {} [:hostname] = hostname if hostname MacroContext.new(new_domain, c, s, h, ) end |