Sha256: 1f083a248fb2ea63fc1ec5b7f726e558cdda3088318d5db4de233af5d2afc177
Contents?: true
Size: 1.58 KB
Versions: 6
Compression:
Stored size: 1.58 KB
Contents
module Elastic::Railties module Utils def reindex(_index = nil) logger.info "Reindexing all indices" if _index.nil? indices(_index).each do |index| logger.info "Reindexing index #{index.suffix}" handle_errors { index.reindex } end end def migrate(_index = nil) logger.info "Migrating all indices" if _index.nil? indices(_index).each do |index| logger.info "Migrating index #{index.suffix}" handle_errors { index.mapping.migrate } end end def drop(_index = nil) logger.info "Dropping all indices" if _index.nil? indices(_index).each &:drop end def stats(_index = nil) logger.info "Indices stats" if _index.nil? indices(_index).each do |index| logger.info "Stats for #{index.suffix}:" # TODO. end end private def indices(_index = nil) Dir.glob(indices_paths.join('**/*.rb')).map do |path| path = Pathname.new path path = path.relative_path_from indices_paths path = path.dirname.join(path.basename(path.extname)).to_s next nil if _index && (path != _index && path.camelize != _index) klass = path.camelize.constantize next nil unless klass < Elastic::Type klass end.reject(&:nil?) end def indices_paths Rails.root.join(Elastic::Configuration.indices_path) end def handle_errors yield rescue => exc logger.error exc.message logger.error exc.backtrace.join("\n") end def logger Elastic::Configuration.logger end end end
Version data entries
6 entries across 6 versions & 1 rubygems