summaryrefslogtreecommitdiff
path: root/users/app
diff options
context:
space:
mode:
authorAzul <azul@leap.se>2013-07-18 11:31:25 +0200
committerAzul <azul@leap.se>2013-07-24 10:55:50 +0200
commit4a071ef1b33525fa2d1052aa7f21b549447fe767 (patch)
treeed293735e0123a3d5d6bc40d78dc2bebd8a64f8d /users/app
parent38e7ba3a7c7a414c5b087f7f32df1a09403fff89 (diff)
move identity creation into user class
It's always based on a user and most default values are based on user properties.
Diffstat (limited to 'users/app')
-rw-r--r--users/app/models/identity.rb7
-rw-r--r--users/app/models/user.rb13
2 files changed, 13 insertions, 7 deletions
diff --git a/users/app/models/identity.rb b/users/app/models/identity.rb
index a081394..9fd0cad 100644
--- a/users/app/models/identity.rb
+++ b/users/app/models/identity.rb
@@ -7,13 +7,6 @@ class Identity < CouchRest::Model::Base
property :address
property :destination
- def initialize(attribs = {}, &block):q
- attribs.reverse_merge! user_id: user.id,
- address: user.main_email_address,
- destination: user.main_email_address
- Identity.new attribs
- end
-
design do
view :by_user_id
end
diff --git a/users/app/models/user.rb b/users/app/models/user.rb
index 413b4ac..dda5a41 100644
--- a/users/app/models/user.rb
+++ b/users/app/models/user.rb
@@ -73,6 +73,19 @@ class User < CouchRest::Model::Base
alias_method :find_by_param, :find
end
+ def create_identity(attribs = {}, &block)
+ build_identity(attribs, &block)
+ identity.save
+ identity
+ end
+
+ def build_identity(attribs = {}, &block)
+ attribs.reverse_merge! user_id: self.id,
+ address: self.email_address,
+ destination: self.email_address
+ Identity.new(attribs, &block)
+ end
+
def to_param
self.id
end