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

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"


47
48
49
# File 'lib/elasticsearch/model/naming.rb', line 47

def document_type name=nil
  @document_type = name || @document_type || self.model_name.element
end

#document_type=(name) ⇒ Object

Set the document type

See Also:



56
57
58
# File 'lib/elasticsearch/model/naming.rb', line 56

def document_type=(name)
  @document_type = name
end

#index_name(name = nil) ⇒ Object

Get or set the name of the index

TODO: Dynamic names a la Tire – ‘Article.index_name { “articles-#Time.now.year” }`

Examples:

Set the index name for the ‘Article` model


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

Directly set the index name for the ‘Article` model


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


24
25
26
# File 'lib/elasticsearch/model/naming.rb', line 24

def index_name name=nil
  @index_name = name || @index_name || self.model_name.collection.gsub(/\//, '-')
end

#index_name=(name) ⇒ Object

Set the index name

See Also:



31
32
33
# File 'lib/elasticsearch/model/naming.rb', line 31

def index_name=(name)
  @index_name = name
end