Sha256: ed3b57e6f97a0851376a09590b9cd44e6fe41e28d2fd0939c46f6b16d669570e
Contents?: true
Size: 1.56 KB
Versions: 8
Compression:
Stored size: 1.56 KB
Contents
module Elastics class Tasks attr_reader :options def initialize(overrides={}) options = Elastics::Utils.env2options *default_options.keys options[:index] = options[:index].split(',') if options[:index] @options = default_options.merge(options).merge(overrides) end def default_options @default_options ||= { :force => false, :index => Conf.variables[:index], :config_file => Conf.config_file } end def create_indices indices.each do |index| delete_index(index) if options[:force] raise ExistingIndexError, "#{index.inspect} already exists. Please use FORCE=1 if you want to delete it first." \ if exist?(index) create(index) end end def delete_indices indices.each { |index| delete_index(index) } end def config_hash @config_hash ||= ( hash = YAML.load(Utils.erb_process(config_path)) Utils.delete_allcaps_keys(hash) ) end private def indices i = options[:index] || config_hash.keys i.is_a?(Array) ? i : [i] end def exist?(index) Elastics.exist?(:index => index) end def config_path @config_path ||= options[:config_file] || Conf.config_file end def delete_index(index) Elastics.delete_index(:index => index) if exist?(index) end def create(index) config_hash[index] = {} unless config_hash.has_key?(index) Elastics.POST "/#{index}", config_hash[index] end end end
Version data entries
8 entries across 8 versions & 1 rubygems