module Elasticsearch::Model::Naming::ClassMethods

Public Instance Methods

document_type(name=nil) click to toggle source

Get or set the document type

@example Set the document type for the `Article` model

class Article
  document_type "my-article"
end

@example Directly set the document type for the `Article` model

Article.document_type "my-article"
# File lib/elasticsearch/model/naming.rb, line 79
def document_type name=nil
  @document_type = name || @document_type || implicit(:document_type)
end
document_type=(name) click to toggle source

Set the document type

@see document_type

# File lib/elasticsearch/model/naming.rb, line 88
def document_type=(name)
  @document_type = name
end
index_name(name=nil, &block) click to toggle source

Get or set the name of the index

@example Set the index name for the `Article` model

class Article
  index_name "articles-#{Rails.env}"
end

@example Set the index name for the `Article` model and re-evaluate it on each call

class Article
  index_name { "articles-#{Time.now.year}" }
end

@example Directly set the index name for the `Article` model

Article.index_name "articles-#{Rails.env}"
# File lib/elasticsearch/model/naming.rb, line 48
def index_name name=nil, &block
  if name || block_given?
    return (@index_name = name || block)
  end

  if @index_name.respond_to?(:call)
    @index_name.call
  else
    @index_name || implicit(:index_name)
  end
end
index_name=(name) click to toggle source

Set the index name

@see index_name

# File lib/elasticsearch/model/naming.rb, line 63
def index_name=(name)
  @index_name = name
end

Private Instance Methods

default_document_type() click to toggle source
# File lib/elasticsearch/model/naming.rb, line 102
def default_document_type; end
default_index_name() click to toggle source
# File lib/elasticsearch/model/naming.rb, line 98
def default_index_name
  self.model_name.collection.gsub(/\//, '-')
end
implicit(prop) click to toggle source
# File lib/elasticsearch/model/naming.rb, line 94
def implicit(prop)
  self.send("default_#{prop}")
end