Get or set the document type for this model, based on arguments.
By default, uses ActiveSupport inflection, so a class named `Article` will be stored as the `article` type.
To get the document type:
Article.document_type
To set the document type:
Article.document_type 'my-custom-type'
# File lib/tire/model/naming.rb, line 76 def document_type name=nil @document_type = name if name @document_type || klass.model_name.to_s.underscore end
Get or set the index name for this model, based on arguments.
By default, uses ActiveSupport inflection, so a class named `Article` will be stored in the `articles` index.
To get the index name:
Article.index_name
To set the index name:
Article.index_name 'my-custom-name'
You can also use a block for defining the index name, which is evaluated in the class context:
Article.index_name { "articles-#{Time.now.year}" } Article.index_name { "articles-#{Rails.env}" }
# File lib/tire/model/naming.rb, line 30 def index_name name=nil, &block @index_name = name if name @index_name = block if block_given? # TODO: Try to get index_name from ancestor classes @index_name || [index_prefix, klass.model_name.plural].compact.join('_') end
# File lib/tire/model/naming.rb, line 53 def index_prefix(*args) # Uses class or instance variable depending on the context if args.size > 0 value = args.pop self.is_a?(Module) ? ( @@__index_prefix__ = value ) : ( @__index_prefix__ = value ) end self.is_a?(Module) ? ( @@__index_prefix__ || nil ) : ( @__index_prefix__ || @@__index_prefix__ || nil ) end