Module: Elasticsearch::Rails2::Naming::ClassMethods

Defined in:
lib/elasticsearch/rails2/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 ‘Building` model


class Building
  document_type "my-building"
end

Directly set the document type for the ‘Building` model


Building.document_type "my-building"


60
61
62
# File 'lib/elasticsearch/rails2/naming.rb', line 60

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

#document_type=(name) ⇒ Object

Set the document type

See Also:



69
70
71
# File 'lib/elasticsearch/rails2/naming.rb', line 69

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 ‘Building` model


class Building
  index_name "buildings-#{Rails.env}"
end

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


class Building
  index_name { "buildings-#{Time.now.year}" }
end

Directly set the index name for the ‘Building` model


Building.index_name "buildings-#{Rails.env}"


29
30
31
32
33
34
35
36
37
38
39
# File 'lib/elasticsearch/rails2/naming.rb', line 29

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 || Elasticsearch::Rails2.index_name || "#{self.model_name.collection}_index"
  end
end

#index_name=(name) ⇒ Object

Set the index name

See Also:



44
45
46
# File 'lib/elasticsearch/rails2/naming.rb', line 44

def index_name=(name)
  @index_name = name
end