Permalink
Browse files

- keep_ids option, + populate_with does not remove the ids by default…

…, use #clear_ids to remove them from the results.

API, O API
Thinner methods
Make should I
  • Loading branch information...
1 parent 530d479 commit df9b1dd4a1c7256a763f8c6c93e0aaf393f9a140 @floere committed Nov 8, 2011
Showing with 7 additions and 11 deletions.
  1. +3 −3 client/lib/picky-client/convenience.rb
  2. +1 −5 client/spec/picky-client/convenience_spec.rb
  3. +2 −2 history.textile
  4. +1 −1 version.rb
@@ -41,17 +41,18 @@ def total
#
# If you don't pass it a block, it will just use the AR results.
#
+ # Note: Usually, after this the ids are not needed anymore.
+ # Use #clear_ids to remove them.
+ #
# === Parameters
# * model_class: The model to use for the results. Will call #find on the given class.
#
# === Options
# * up_to: Amount of results to populate. All of them by default.
- # * keep_ids: By default, this method removes the ids from the results. Set this to true to keep the ids.
# * The rest of the options are directly passed through to the ModelClass.find(ids, options) method. Default is {}.
#
def populate_with model_class, options = {}, &block
the_ids = ids options.delete(:up_to)
- keep_ids = options.delete :keep_ids
objects = model_class.find the_ids, options
@@ -69,7 +70,6 @@ def populate_with model_class, options = {}, &block
objects.collect! &block if block_given?
amend_ids_with objects
- clear_ids unless keep_ids
objects
end
@@ -109,12 +109,8 @@ def == other
@results.populate_with(ARClass) { |ar_instance| ar_instance.id.to_s }
@results.entries.should == (1..20).map { |id| id.to_s } # "rendering" using to_s
end
- it "removes the ids by default" do
+ it "keeps the ids by default" do
@results.populate_with(ARClass) { |ar_instance| ar_instance.id.to_s }
- @results.ids.should be_empty
- end
- it "keeps the ids with the right option" do
- @results.populate_with(ARClass, :keep_ids => true) { |ar_instance| ar_instance.id.to_s }
@results.ids.should_not be_empty
end
end
View
@@ -1,8 +1,8 @@
h2. Upcoming Version
-h2. Version 3.3.4
+h2. Version 3.4.0
-* hanke: (client) Method @populate_with@ gets the added option of @keep_ids@. Set to true if you don't want the ids to be removed from the (result) hash.
+* hanke: (client) Method @populate_with@ keeps the ids by default. Use @clear_ids@ on the results if you want to remove them.
h2. Version 3.3.3
View
@@ -1,3 +1,3 @@
module Picky
- VERSION = '3.3.4'
+ VERSION = '3.4.0'
end

0 comments on commit df9b1dd

Please sign in to comment.