Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Restructured lib files

  • Loading branch information...
commit 9e371de7437958f2c32dab91073216ba569a72cb 1 parent d741056
Michael Richards authored March 27, 2010
76  lib/dm-riak-adapter.rb
... ...
@@ -1,75 +1,5 @@
  1
+$: << File.dirname(__FILE__)
  2
+
1 3
 require 'riak'
2 4
 
3  
-module DataMapper::Adapters
4  
-  class RiakAdapter < AbstractAdapter
5  
-    def initialize(name, options)
6  
-      super
7  
-      @riak = Riak::Client.new(:prefix => options[:prefix] || 'riak')
8  
-      @namespace = options[:namespace] ? options[:namespace] + ':' : ''
9  
-    end
10  
-    
11  
-    def create(resources)
12  
-      objects = objects_for(resources.first.model)
13  
-      
14  
-      resources.each {|r| initialize_serial(r, objects.size.succ)}
15  
-      create_objects(resources)
16  
-    end
17  
-    
18  
-    def read(query)
19  
-      query.filter_records(objects_for(query.model)).each do |object|
20  
-        query.fields.each do |property|
21  
-          object[property.name.to_s] = property.typecast(object[property.name.to_s])
22  
-        end
23  
-      end
24  
-    end
25  
-    
26  
-    def update(attributes, collection)
27  
-      attributes = attributes_as_fields(attributes)
28  
-      
29  
-      objects_for(collection.query.model).each {|r| r.update(attributes)}
30  
-      update_objects(collection)
31  
-    end
32  
-    
33  
-    def delete(collection)
34  
-      delete_objects(collection)
35  
-    end
36  
-    
37  
-    def flush(model)
38  
-      bucket(model).keys.each {|key| bucket(model)[key].delete}
39  
-    end
40  
-    
41  
-    private
42  
-    
43  
-    def bucket(model)
44  
-      @riak.bucket(@namespace + model.storage_name)
45  
-    end
46  
-    
47  
-    def objects_for(model)
48  
-      bucket(model).keys.map {|key| bucket(model)[key].data}
49  
-    end
50  
-    
51  
-    def create_objects(resources)
52  
-      resources.each do |resource|
53  
-        object = bucket(resource.model).new(resource.id.to_s)
54  
-        object.data = resource.attributes(:field)
55  
-        object.store
56  
-      end
57  
-    end
58  
-    
59  
-    def update_objects(resources)
60  
-      resources.each do |resource|
61  
-        object = bucket(resource.model)[resource.id.to_s]
62  
-        object.data = resource.attributes(:field)
63  
-        object.store
64  
-      end
65  
-    end
66  
-    
67  
-    def delete_objects(resources)
68  
-      resources.each do |resource|
69  
-        bucket(resource.model)[resource.id.to_s].delete
70  
-      end
71  
-    end
72  
-  end
73  
-  
74  
-  const_added(:RiakAdapter)
75  
-end
  5
+require 'dm-riak-adapter/adapter'
73  lib/dm-riak-adapter/adapter.rb
... ...
@@ -0,0 +1,73 @@
  1
+module DataMapper::Adapters
  2
+  class RiakAdapter < AbstractAdapter
  3
+    def initialize(name, options)
  4
+      super
  5
+      @riak = Riak::Client.new(:prefix => options[:prefix] || 'riak')
  6
+      @namespace = options[:namespace] ? options[:namespace] + ':' : ''
  7
+    end
  8
+    
  9
+    def create(resources)
  10
+      objects = objects_for(resources.first.model)
  11
+      
  12
+      resources.each {|r| initialize_serial(r, objects.size.succ)}
  13
+      create_objects(resources)
  14
+    end
  15
+    
  16
+    def read(query)
  17
+      query.filter_records(objects_for(query.model)).each do |object|
  18
+        query.fields.each do |property|
  19
+          object[property.name.to_s] = property.typecast(object[property.name.to_s])
  20
+        end
  21
+      end
  22
+    end
  23
+    
  24
+    def update(attributes, collection)
  25
+      attributes = attributes_as_fields(attributes)
  26
+      
  27
+      objects_for(collection.query.model).each {|r| r.update(attributes)}
  28
+      update_objects(collection)
  29
+    end
  30
+    
  31
+    def delete(collection)
  32
+      delete_objects(collection)
  33
+    end
  34
+    
  35
+    def flush(model)
  36
+      bucket(model).keys.each {|key| bucket(model)[key].delete}
  37
+    end
  38
+    
  39
+    private
  40
+    
  41
+    def bucket(model)
  42
+      @riak.bucket(@namespace + model.storage_name)
  43
+    end
  44
+    
  45
+    def objects_for(model)
  46
+      bucket(model).keys.map {|key| bucket(model)[key].data}
  47
+    end
  48
+    
  49
+    def create_objects(resources)
  50
+      resources.each do |resource|
  51
+        object = bucket(resource.model).new(resource.id.to_s)
  52
+        object.data = resource.attributes(:field)
  53
+        object.store
  54
+      end
  55
+    end
  56
+    
  57
+    def update_objects(resources)
  58
+      resources.each do |resource|
  59
+        object = bucket(resource.model)[resource.id.to_s]
  60
+        object.data = resource.attributes(:field)
  61
+        object.store
  62
+      end
  63
+    end
  64
+    
  65
+    def delete_objects(resources)
  66
+      resources.each do |resource|
  67
+        bucket(resource.model)[resource.id.to_s].delete
  68
+      end
  69
+    end
  70
+  end
  71
+  
  72
+  const_added(:RiakAdapter)
  73
+end

0 notes on commit 9e371de

Please sign in to comment.
Something went wrong with that request. Please try again.