Class: Replyr::ReplyAddress

Inherits:
Object
  • Object
show all
Includes:
AddressBuilder
Defined in:
lib/replyr/reply_address.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from AddressBuilder

class_from_normalized_model_name, #create_token, #ensure_valid_token!, get_parsed_address, #id_from_model, #normalized_model_name, #token_valid?

Constructor Details

#initialize(model, user) ⇒ ReplyAddress

Create a new reply address from a given user and model



9
10
11
12
# File 'lib/replyr/reply_address.rb', line 9

def initialize(model, user)
  @model = model
  @user = user
end

Instance Attribute Details

#modelObject

Returns the value of attribute model.



5
6
7
# File 'lib/replyr/reply_address.rb', line 5

def model
  @model
end

#userObject

Returns the value of attribute user.



5
6
7
# File 'lib/replyr/reply_address.rb', line 5

def user
  @user
end

Class Method Details

.new_from_address(address) ⇒ Object

Create a reply address from a given address string Checks for validity of address and raises an ArgumentError if it’s invalid.



18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/replyr/reply_address.rb', line 18

def self.new_from_address(address)
  parts = AddressBuilder.get_parsed_address(address)

  model_class = AddressBuilder.class_from_normalized_model_name(parts[:model_name])
  model = model_class.find(parts[:model_id])
  user = Replyr.config.user_class.find(parts[:user_id])

  address = new(model, user)
  address.ensure_valid_token!(parts[:token])
  address
rescue
  Replyr.logger.warn "Reply email address invalid."
  nil
end

Instance Method Details

#addressObject Also known as: to_s

Returns the address string (e.g reply-comment-12-56-01ce26dc69094af9246ea7e7ce9970aff2b81cc9@reply.example.com)



42
43
44
45
46
47
48
49
# File 'lib/replyr/reply_address.rb', line 42

def address
  user_id = id_from_model(@user)
  model_id = id_from_model(@model)
  model_name = normalized_model_name(@model)

  local_part = [Replyr.config.reply_prefix, model_name, model_id, user_id, token].join("-")
  "#{local_part}@#{Replyr.config.reply_host}"
end

#tokenObject

Returs the token from this address



35
36
37
# File 'lib/replyr/reply_address.rb', line 35

def token
  create_token(@model, @user)
end