Module: Elasticsearch::Rails2::Naming::InstanceMethods

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 an instance of the ‘Building` model


@bulding.document_type "my-building"


109
110
111
# File 'lib/elasticsearch/rails2/naming.rb', line 109

def document_type name=nil
  @document_type = name || @document_type || self.class.document_type
end

#document_type=(name) ⇒ Object

Set the document type

See Also:



118
119
120
# File 'lib/elasticsearch/rails2/naming.rb', line 118

def document_type=(name)
  @document_type = name
end

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

Get or set the index name for the model instance

Examples:

Set the index name for an instance of the ‘Building` model


@building.index_name "buildings-#{@building.sourceid}"


83
84
85
86
87
88
89
90
91
92
93
# File 'lib/elasticsearch/rails2/naming.rb', line 83

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 || self.class.index_name
  end
end

#index_name=(name) ⇒ Object

Set the index name

See Also:



98
99
100
# File 'lib/elasticsearch/rails2/naming.rb', line 98

def index_name=(name)
  @index_name = name
end