Sha256: b243044cc3af671cf18095b4a3b7fabd8207832995c16d3c64f6a4a7962e7743

Contents?: true

Size: 1.2 KB

Versions: 1

Compression:

Stored size: 1.2 KB

Contents

require 'tire'
require 'elasticsearch_autocomplete/version'
require 'elasticsearch_autocomplete/analyzers'
require 'elasticsearch_autocomplete/model_addition'
require 'elasticsearch_autocomplete/railtie' if Object.const_defined?(:Rails)

module ElasticsearchAutocomplete
  mattr_accessor :defaults
  mattr_accessor :enable_indexing
  self.enable_indexing = true

  def self.default_index_prefix
    Object.const_defined?(:Rails) ? ::Rails.application.class.name.split('::').first.downcase : nil
  end

  self.defaults = {attr: :name, localized: false, mode: :word, index_prefix: default_index_prefix}

  MODES = {
      word: {base: 'ac', word: 'ac_word'},
      phrase: {base: 'ac'},
      full: {base: 'ac', full: 'ac_full'}
  }

  class << self
    def val_to_terms(val, zero=false)
      return [] unless val
      return val if val.is_a?(Array)
      return [true] if val == 'true'
      return [false] if val == 'false'
      a = val.to_s.split(',').map(&:to_i)
      zero ? a : a.reject(&:zero?)
    end

    def without_indexing
      original_setting = enable_indexing
      self.enable_indexing = false
      begin
        yield
      ensure
        self.enable_indexing = original_setting
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
elasticsearch_autocomplete-0.1.5 lib/elasticsearch_autocomplete.rb