summaryrefslogtreecommitdiff
path: root/users/app/models/identity.rb
diff options
context:
space:
mode:
authorAzul <azul@leap.se>2013-07-19 16:02:02 +0200
committerAzul <azul@leap.se>2013-07-24 10:56:45 +0200
commitd70c5796a2989b7b43f7e287899fb1394ae28280 (patch)
treedaeabe5bdcc2386a201d88d838b4b1e387dd9ee3 /users/app/models/identity.rb
parentc0527cc18788fc60180d9293a546c93e6a77b788 (diff)
separate signup and settings service objects for user
Diffstat (limited to 'users/app/models/identity.rb')
-rw-r--r--users/app/models/identity.rb27
1 files changed, 27 insertions, 0 deletions
diff --git a/users/app/models/identity.rb b/users/app/models/identity.rb
index 73531ec..355f67a 100644
--- a/users/app/models/identity.rb
+++ b/users/app/models/identity.rb
@@ -27,6 +27,33 @@ class Identity < CouchRest::Model::Base
end
+ def self.for(user, attributes = {})
+ find_for(user, attributes) || build_for(user, attributes)
+ end
+
+ def self.find_for(user, attributes = {})
+ attributes.reverse_merge! attributes_from_user(user)
+ find_by_address_and_destination [attributes[:address], attributes[:destination]]
+ end
+
+ def self.build_for(user, attributes = {})
+ attributes.reverse_merge! attributes_from_user(user)
+ Identity.new(attributes)
+ end
+
+ def self.create_for(user, attributes = {})
+ identity = build_for(user, attributes)
+ identity.save
+ identity
+ end
+
+ def self.attributes_from_user(user)
+ { user_id: user.id,
+ address: user.email_address,
+ destination: user.email_address
+ }
+ end
+
def keys
read_attribute('keys') || HashWithIndifferentAccess.new
end