Module: Elasticsearch::Model::Naming::ClassMethods

Included in:
Proxy::ClassMethodsProxy
Defined in:
lib/elasticsearch/model/naming.rb

Instance Method Summary collapse

Instance Method Details

#document_type(name = nil) ⇒ Object

Get or set the document type

Examples:

Set the document type for the ‘Article` model


class Article
  document_type "my-article"
end

Directly set the document type for the ‘Article` model


Article.document_type "my-article"


79
80
81
# 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) ⇒ Object

Set the document type

See Also:



88
89
90
# File 'lib/elasticsearch/model/naming.rb', line 88

def document_type=(name)
  @document_type = name
end

#index_name(name = nil, &block) ⇒ Object

Get or set the name of the index

Examples:

Set the index name for the ‘Article` model


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

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


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

Directly set the index name for the ‘Article` model


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


48
49
50
51
52
53
54
55
56
57
58
# 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) ⇒ Object

Set the index name

See Also:



63
64
65
# File 'lib/elasticsearch/model/naming.rb', line 63

def index_name=(name)
  @index_name = name
end