Class: Coppertone::MacroContext

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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',
               options = {})
  @ip_address_wrapper = IPAddressWrapper.new(ip_as_s)
  @sender_identity = SenderIdentity.new(sender)
  @domain = domain || @sender_identity.domain
  @helo_domain = helo_domain
  @hostname = options[:hostname]
end

Instance Attribute Details

#domainObject (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_domainObject (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

#hostnameObject (readonly)

Returns the value of attribute hostname.



19
20
21
# File 'lib/coppertone/macro_context.rb', line 19

def hostname
  @hostname
end

#ip_address_wrapperObject (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_identityObject (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

#rObject



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_hostnameObject



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

#tObject



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)
  options = {}
  options[:hostname] = hostname if hostname
  MacroContext.new(new_domain, c, s, h, options)
end