From 28b21959f39b0e28c450bba54b8696632a0187fa Mon Sep 17 00:00:00 2001 From: Azul Date: Mon, 10 Dec 2012 11:00:24 +0100 Subject: created generic Email class and use it with EmailAliases --- users/app/models/email.rb | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 users/app/models/email.rb (limited to 'users/app/models/email.rb') diff --git a/users/app/models/email.rb b/users/app/models/email.rb new file mode 100644 index 0000000..0988d9f --- /dev/null +++ b/users/app/models/email.rb @@ -0,0 +1,9 @@ +class Email + include CouchRest::Model::Embeddable + + property :email, String + + def to_s + email + end +end -- cgit v1.2.3 From d9fa19106998bc6ac484494334dcf150bb6aa5d5 Mon Sep 17 00:00:00 2001 From: Azul Date: Mon, 10 Dec 2012 20:16:26 +0100 Subject: email format validations --- users/app/models/email.rb | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'users/app/models/email.rb') diff --git a/users/app/models/email.rb b/users/app/models/email.rb index 0988d9f..7c88c51 100644 --- a/users/app/models/email.rb +++ b/users/app/models/email.rb @@ -3,6 +3,11 @@ class Email property :email, String + validates :email_forward, + :format => { :with => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/, :message => "needs to be a valid email address"} + + timestamps! + def to_s email end -- cgit v1.2.3 From 60e8fc3e1309d1c972a7695e3344e63f5d633a06 Mon Sep 17 00:00:00 2001 From: Azul Date: Wed, 12 Dec 2012 15:41:14 +0100 Subject: find users by email and aliases --- users/app/models/email.rb | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'users/app/models/email.rb') diff --git a/users/app/models/email.rb b/users/app/models/email.rb index 7c88c51..45101c1 100644 --- a/users/app/models/email.rb +++ b/users/app/models/email.rb @@ -3,11 +3,9 @@ class Email property :email, String - validates :email_forward, + validates :email, :format => { :with => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/, :message => "needs to be a valid email address"} - timestamps! - def to_s email end -- cgit v1.2.3 From 577c3d8149acbd483120847b994582268f93c0b3 Mon Sep 17 00:00:00 2001 From: Azul Date: Thu, 13 Dec 2012 16:07:31 +0100 Subject: refactor: Email constructor now takes string or hash This allows us to reuse add_email from email_aliases_attributes= --- users/app/models/email.rb | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'users/app/models/email.rb') diff --git a/users/app/models/email.rb b/users/app/models/email.rb index 45101c1..4b01838 100644 --- a/users/app/models/email.rb +++ b/users/app/models/email.rb @@ -6,6 +6,11 @@ class Email validates :email, :format => { :with => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/, :message => "needs to be a valid email address"} + def initialize(attributes = nil, &block) + attributes = {:email => attributes} if attributes.is_a? String + super(attributes, &block) + end + def to_s email end -- cgit v1.2.3