Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Changing Query#update to #amend.

Update is a term actually used by mongo that I would like to support in plucky. This breaks backwards compatibility so I'll bump version accordingly on next release.
  • Loading branch information...
commit 3696d547ef624789b17441e05f8d3b9b690d065b 1 parent 83ad596
John Nunemaker authored April 23, 2011
16  lib/plucky/query.rb
@@ -42,7 +42,7 @@ def per_page(limit=nil)
42 42
     def paginate(opts={})
43 43
       page          = opts.delete(:page)
44 44
       limit         = opts.delete(:per_page) || per_page
45  
-      query         = clone.update(opts)
  45
+      query         = clone.amend(opts)
46 46
       total         = query.count
47 47
       paginator     = Pagination::Paginator.new(total, page, limit)
48 48
       query[:limit] = paginator.limit
@@ -54,12 +54,12 @@ def paginate(opts={})
54 54
     end
55 55
 
56 56
     def find_each(opts={})
57  
-      query = clone.update(opts)
  57
+      query = clone.amend(opts)
58 58
       query.collection.find(query.criteria.to_hash, query.options.to_hash)
59 59
     end
60 60
 
61 61
     def find_one(opts={})
62  
-      query = clone.update(opts)
  62
+      query = clone.amend(opts)
63 63
       query.collection.find_one(query.criteria.to_hash, query.options.to_hash)
64 64
     end
65 65
 
@@ -81,7 +81,7 @@ def first(opts={})
81 81
     end
82 82
 
83 83
     def last(opts={})
84  
-      clone.update(opts).reverse.find_one
  84
+      clone.amend(opts).reverse.find_one
85 85
     end
86 86
 
87 87
     def each
@@ -89,7 +89,7 @@ def each
89 89
     end
90 90
 
91 91
     def remove(opts={})
92  
-      query = clone.update(opts)
  92
+      query = clone.amend(opts)
93 93
       query.collection.remove(query.criteria.to_hash)
94 94
     end
95 95
 
@@ -102,11 +102,11 @@ def size
102 102
     end
103 103
 
104 104
     def distinct(key, opts = {})
105  
-      query = clone.update(opts)
  105
+      query = clone.amend(opts)
106 106
       query.collection.distinct(key, query.criteria.to_hash)
107 107
     end
108 108
 
109  
-    def update(opts={})
  109
+    def amend(opts={})
110 110
       opts.each { |key, value| self[key] = value }
111 111
       self
112 112
     end
@@ -185,7 +185,7 @@ def []=(key, value)
185 185
     def merge(other)
186 186
       merged_criteria = criteria.merge(other.criteria).to_hash
187 187
       merged_options  = options.merge(other.options).to_hash
188  
-      clone.update(merged_criteria).update(merged_options)
  188
+      clone.amend(merged_criteria).amend(merged_options)
189 189
     end
190 190
 
191 191
     def to_hash
8  test/plucky/test_query.rb
@@ -506,15 +506,15 @@ class QueryTest < Test::Unit::TestCase
506 506
       end
507 507
     end
508 508
 
509  
-    context "#update" do
  509
+    context "#amend" do
510 510
       should "normalize and update options" do
511  
-        Query.new(@collection).update(:order => :age.desc).options[:sort].should == [['age', -1]]
  511
+        Query.new(@collection).amend(:order => :age.desc).options[:sort].should == [['age', -1]]
512 512
       end
513 513
 
514 514
       should "work with simple stuff" do
515 515
         Query.new(@collection).
516  
-          update(:foo => 'bar').
517  
-          update(:baz => 'wick').
  516
+          amend(:foo => 'bar').
  517
+          amend(:baz => 'wick').
518 518
           criteria.should == CriteriaHash.new(:foo => 'bar', :baz => 'wick')
519 519
       end
520 520
     end

0 notes on commit 3696d54

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