Skip to content

Commit 6d739dd

Browse files
committed
[STORE] Added, that document_type can set the document type for repository
Also available as `document_type="foo"`.
1 parent 2fbc3aa commit 6d739dd

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

elasticsearch-persistence/lib/elasticsearch/persistence/repository/naming.rb

+6-2
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,14 @@ def index_name=(name)
1919
@index_name = name
2020
end; alias :index= :index_name=
2121

22-
def document_type
23-
klass ? klass.to_s.underscore : nil
22+
def document_type name=nil
23+
@document_type = name || @document_type || (klass ? klass.to_s.underscore : nil)
2424
end; alias :type :document_type
2525

26+
def document_type=(name)
27+
@document_type = name
28+
end; alias :type= :document_type=
29+
2630
def __get_klass_from_type(type)
2731
klass = type.classify
2832
klass.constantize

elasticsearch-persistence/test/unit/repository_naming_test.rb

+10
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,16 @@ def self.class
104104
subject.klass Foobar
105105
assert_equal 'foobar', subject.type
106106
end
107+
108+
should "be settable" do
109+
subject.document_type = 'foobar'
110+
assert_equal 'foobar', subject.document_type
111+
end
112+
113+
should "be settable by DSL" do
114+
subject.document_type 'foobar'
115+
assert_equal 'foobar', subject.document_type
116+
end
107117
end
108118
end
109119
end

0 commit comments

Comments
 (0)