Class: Confirmationcode
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Confirmationcode
- Defined in:
- app/models/confirmationcode.rb
Overview
The Confirmation code is a sort of join table that links mailing lists with addresses, and also stores confirmation status.
Class Method Summary collapse
-
.confirm(mailinglist, address, code) ⇒ Object
Given a
mailinglist
, anaddress
and a confirmation code incode
, it confirms the address in that mailing list if the confirmation code is correct. -
.confirmed?(mailinglist_id, address_id) ⇒ Boolean
Given a
mailinglist_id
and anaddress_id
, returns whether the address has been confirmed for that mailing list or not.
Instance Method Summary collapse
- #code=(_) ⇒ Object
-
#initialize ⇒ Confirmationcode
constructor
Creates a new confirmation code, and then freezes it so that it can’t be modified.
Constructor Details
#initialize ⇒ Confirmationcode
Creates a new confirmation code, and then freezes it so that it can’t be modified.
11 12 13 14 15 |
# File 'app/models/confirmationcode.rb', line 11 def initialize super @attributes["code"]=("%16s" % rand(36**16).to_s(36)).gsub(/ /,"0") @attributes["code"].freeze end |
Class Method Details
.confirm(mailinglist, address, code) ⇒ Object
Given a mailinglist
, an address
and a confirmation code in code
, it confirms the address in that mailing list if the confirmation code is correct.
If the confirmation code is incorrect, returns false.
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'app/models/confirmationcode.rb', line 42 def self.confirm mailinglist, address, code confirmation_record = find(:first, :conditions => [ 'mailinglist_id = ? and address_id = ? and code = ?', mailinglist.id, address.id, code ]) if confirmation_record then confirmation_record.confirmed = true if confirmation_record.save then true end end end |
.confirmed?(mailinglist_id, address_id) ⇒ Boolean
Given a mailinglist_id
and an address_id
, returns whether the address has been confirmed for that mailing list or not.
26 27 28 29 30 31 32 33 34 35 |
# File 'app/models/confirmationcode.rb', line 26 def self.confirmed? mailinglist_id, address_id confirmation_record = find( :first, :conditions => [ 'mailinglist_id = ? and address_id = ?', mailinglist_id, address_id ] ) if confirmation_record then confirmation_record.confirmed else nil end end |
Instance Method Details
#code=(_) ⇒ Object
20 21 22 |
# File 'app/models/confirmationcode.rb', line 20 def code= _ raise TypeError, "can't modify code string" end |