Module: Tire::Tasks::Import
Instance Method Summary collapse
- #add_pagination_to_klass(klass) ⇒ Object
- #create_index(index, klass) ⇒ Object
- #delete_index(index) ⇒ Object
- #import_model(index, klass, params) ⇒ Object
- #progress_bar(klass, total = nil) ⇒ Object
Instance Method Details
#add_pagination_to_klass(klass) ⇒ Object
25 26 27 28 29 30 31 32 33 |
# 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( = {}) page([:page]).per([:per_page]) end end end unless klass.respond_to?(:paginate) end |
#create_index(index, klass) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 |
# 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 |
#delete_index(index) ⇒ Object
8 9 10 11 |
# File 'lib/tire/tasks.rb', line 8 def delete_index(index) puts "[IMPORT] Deleting index '#{index.name}'" index.delete end |
#import_model(index, klass, params) ⇒ Object
45 46 47 48 49 50 51 52 53 54 |
# File 'lib/tire/tasks.rb', line 45 def import_model(index, klass, params) unless (klass) puts "[IMPORT] Importing '#{klass.to_s}'" end klass.tire.import(params) do |documents| (klass).inc documents.size if (klass) documents end (klass).finish if (klass) end |
#progress_bar(klass, total = nil) ⇒ Object
35 36 37 38 39 40 41 42 43 |
# File 'lib/tire/tasks.rb', line 35 def (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 |