Skip to content

Commit

Permalink
[ACTIVEMODEL] Added injection of the paginate method when missing (…
Browse files Browse the repository at this point in the history
…Kaminari)

The `paginate` method, needed for the import task, is injected in the class being imported
when the class implements Kaminari pagination, so the import Rake task works out of the box.

Closes karmi#191. Also see: karmi#48, karmi#108.
  • Loading branch information
chromeragnarok authored and karmi committed Jan 7, 2012
1 parent 4e2466c commit 3925c24
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions lib/tire/tasks.rb
Expand Up @@ -67,6 +67,19 @@ def elapsed_to_human(elapsed)

STDOUT.puts '-'*tty_cols
elapsed = Benchmark.realtime do

# Add Kaminari-powered "paginate" method
#
if defined?(Kaminari) && klass.respond_to?(:page)
klass.instance_eval do
def paginate(options = {})
page(options[:page]).per(options[:per_page]).to_a
end
end
end unless klass.respond_to?(:paginate)

# Import the documents
#
index.import(klass, 'paginate', params) do |documents|

if total
Expand Down

0 comments on commit 3925c24

Please sign in to comment.