lib/elasticsearch/model/naming.rb in elasticsearch-model-0.1.9 vs lib/elasticsearch/model/naming.rb in elasticsearch-model-2.0.0

- old
+ new

@@ -32,11 +32,11 @@ end if @index_name.respond_to?(:call) @index_name.call else - @index_name || self.model_name.collection.gsub(/\//, '-') + @index_name || implicit(:index_name) end end # Set the index name # @@ -56,20 +56,44 @@ # @example Directly set the document type for the `Article` model # # Article.document_type "my-article" # def document_type name=nil - @document_type = name || @document_type || self.model_name.element + @document_type = name || @document_type || implicit(:document_type) end # Set the document type # # @see document_type # def document_type=(name) @document_type = name end + + private + + def implicit(prop) + value = nil + + if Elasticsearch::Model.settings[:inheritance_enabled] + self.ancestors.each do |klass| + next if klass == self + break if value = klass.respond_to?(prop) && klass.send(prop) + end + end + + value || self.send("default_#{prop}") + end + + def default_index_name + self.model_name.collection.gsub(/\//, '-') + end + + def default_document_type + self.model_name.element + end + end module InstanceMethods # Get or set the index name for the model instance