# File lib/tire/tasks.rb, line 25 def add_pagination_to_klass(klass) if defined?(Kaminari) && klass.respond_to?(:page) klass.instance_eval do def paginate(options = {}) page(options[:page]).per(options[:per_page]) end end end unless klass.respond_to?(:paginate) end
# File lib/tire/tasks.rb, line 13 def create_index(index, klass) unless index.exists? mapping = MultiJson.encode(klass.tire.mapping_to_hash, :pretty => Tire::Configuration.pretty) puts "[IMPORT] Creating index '#{index.name}' with mapping:", mapping unless index.create(:mappings => klass.tire.mapping_to_hash, :settings => klass.tire.settings) puts "[ERROR] There has been an error when creating the index -- Elasticsearch returned:", index.response exit(1) end end end
# File lib/tire/tasks.rb, line 8 def delete_index(index) puts "[IMPORT] Deleting index '#{index.name}'" index.delete end
# File lib/tire/tasks.rb, line 45 def import_model(index, klass, params) unless progress_bar(klass) puts "[IMPORT] Importing '#{klass.to_s}'" end klass.tire.import(params) do |documents| progress_bar(klass).inc documents.size if progress_bar(klass) documents end progress_bar(klass).finish if progress_bar(klass) end
# File lib/tire/tasks.rb, line 28 def paginate(options = {}) page(options[:page]).per(options[:per_page]) end
# File lib/tire/tasks.rb, line 35 def progress_bar(klass, total=nil) @progress_bars ||= {} if total @progress_bars[klass.to_s] ||= ANSI::Progressbar.new(klass.to_s, total) else @progress_bars[klass.to_s] end end