Commit 76b99ad

mo <mo.khan@gmail.com>
2018-04-27 22:25:57
convert repository to use a key/value interface
1 parent a791339
Changed files (2)
lib/del/connection.rb
@@ -18,7 +18,7 @@ module Del
       client.auth(configuration[:password])
       roster = Jabber::Roster::Helper.new(client, false)
       roster.add_update_callback do |old_item, item|
-        users.upsert(item) if item
+        users.upsert(item['jid'], item.attributes.to_h) if item
       end
       roster.get_roster
       roster.wait_for_roster
lib/del/repository.rb
@@ -1,12 +1,16 @@
 module Del
   class Repository
-    def initialize(storage = Set.new)
+    def initialize(storage = {})
       @storage = storage
     end
 
-    def upsert(item)
-      Del.logger.debug(item)
-      @storage << item
+    def find_by(id)
+      @storage[id]
+    end
+
+    def upsert(id, attributes = {})
+      Del.logger.debug([id, attributes].inspect)
+      @storage[id] = attributes
     end
   end
 end