Skip to content

Commit

Permalink
port Hash#except from Rails trunk
Browse files Browse the repository at this point in the history
git-svn-id: svn://errtheblog.com/svn/plugins/will_paginate@288 1eaa51fe-a21a-0410-9c2e-ae7a00a434c4
  • Loading branch information
mislav committed Jul 10, 2007
1 parent 8e4c901 commit cb62509
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
15 changes: 15 additions & 0 deletions init.rb
Expand Up @@ -9,3 +9,18 @@ class ActiveRecord::Associations::AssociationCollection
include WillPaginate::Finder::ClassMethods
alias_method_chain :method_missing, :paginate
end

unless Hash.instance_methods.include? 'except'
Hash.class_eval do
# Returns a new hash without the given keys.
def except(*keys)
rejected = Set.new(respond_to?(:convert_key) ? keys.map { |key| convert_key(key) } : keys)
reject { |key,| rejected.include?(key) }
end

# Replaces the hash without only the given keys.
def except!(*keys)
replace(except(*keys))
end
end
end
2 changes: 1 addition & 1 deletion lib/will_paginate/finder.rb
Expand Up @@ -95,7 +95,7 @@ def method_missing_with_paginate(method, *args, &block)
total_entries = unless options[:total_entries]
unless args.first.is_a? Array
# count expects (almost) the same options as find
count_options = options.reject { |key, value| key == :count or key == :order }
count_options = options.except :count, :order
# merge the hash found in :count
# this allows you to specify :select, :order, or anything else just for the count query
count_options.update(options.delete(:count)) if options[:count]
Expand Down

0 comments on commit cb62509

Please sign in to comment.