Commits

Anonymous committed 78164ad

added remove_link and add_link to ruby api

Comments (0)

Files changed (1)

client_lib/jiak.rb

       do_req(Net::HTTP::Get.new(path(bucket, key)+convert_walk_spec(spec)),
              '200')
     end
+    
+    # Add link to object with 'bucket', 'key', 'tag'. Returns the jiak object.
+    def add_link(object, bucket, key, tag)
+      object['links']<<[bucket, key, tag]
+      object
+    end  
+
+    # Remove links from the object at 'bucket', 'key', and 'tag'.  To match any,
+    # pass the wildcard '_'. This will return the object.
+    def remove_link(object, bucket, key, tag)
+      object['links'].each_with_index do |link, index|
+        if (link[0] == bucket or '_' == bucket) and (link[1] == key or '_' == key) and (link[2] == tag or '_' == tag)
+          object['links'].delete_at(index)
+        end
+      end
+      object
+    end
 
     private
       def convert_walk_spec(spec)