Skip to content

Commit

Permalink
[¡BREAKING!] Removed deprecated interfaces
Browse files Browse the repository at this point in the history
* Index#store and Index#percolate do not allow passing document type and document separately, type is inferred from the document itself
* Model#score method has been removed, use Model#_score
* Dynamic sorting methods have been removed, use `sort { by :field_name }
  • Loading branch information
karmi committed Aug 21, 2011
1 parent 8d592e7 commit a05e4bf
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 98 deletions.
28 changes: 4 additions & 24 deletions lib/tire/index.rb
Expand Up @@ -41,21 +41,8 @@ def mapping
end

def store(*args)
case
when ( args.size === 3 && (args.first.is_a?(String) || args.first.is_a?(Symbol)) )
Tire.warn "Passing the document type as argument in Index#store has been deprecated, " +
"please pass a Hash with _type/type property, or " +
"an object with _type/type/document_type method."
type, document, options = args
when ( args.size === 2 && (args.first.is_a?(String) || args.first.is_a?(Symbol)) )
Tire.warn "Passing the document type as argument in Index#store has been deprecated" +
"please pass a Hash with _type/type property, or " +
"an object with _type/type/document_type method."
type, document = args
else
document, options = args
type = get_type_from_document(document)
end
document, options = args
type = get_type_from_document(document)

if options
percolate = options[:percolate]
Expand Down Expand Up @@ -218,15 +205,8 @@ def unregister_percolator_query(name)
end

def percolate(*args, &block)
if args.size > 1
Tire.warn "Passing the document type as argument in Index#percolate has been deprecated, " +
"please pass a Hash with _type/type property, or " +
"an object with _type/type/document_type method."
type, document = args
else
document = args.pop
type = get_type_from_document(document)
end
document = args.pop
type = get_type_from_document(document)

document = MultiJson.decode convert_document_to_json(document)

Expand Down
5 changes: 0 additions & 5 deletions lib/tire/model/search.rb
Expand Up @@ -107,11 +107,6 @@ def elasticsearch_index

module InstanceMethods

def score
Tire.warn "#{self.class}#score has been deprecated, please use #{self.class}#_score instead."
attributes['_score']
end

def index
self.class.elasticsearch_index
end
Expand Down
3 changes: 0 additions & 3 deletions lib/tire/search.rb
Expand Up @@ -6,9 +6,6 @@ class Search
attr_reader :indices, :url, :results, :response, :json, :query, :facets, :filters, :options

def initialize(indices=nil, options = {}, &block)
Tire.warn "Passing indices as multiple arguments to the `Search.new` method " +
"has been deprecated, please pass them as an Array: " +
"Search.new([#{indices}, #{options}])" if options.is_a?(String)
@indices = Array(indices)
@options = options
@type = @options[:type]
Expand Down
7 changes: 0 additions & 7 deletions lib/tire/search/sort.rb
Expand Up @@ -12,13 +12,6 @@ def by(name, direction=nil)
self
end

def method_missing(id, *args, &block)
Tire.warn "Using methods when sorting has been deprecated, please use the `by` method: " +
"sort { by :#{id}#{ args.empty? ? '' : ', ' + args.first.inspect } }"

by id, args.shift
end

def to_ary
@value
end
Expand Down
85 changes: 26 additions & 59 deletions test/unit/search_sort_test.rb
Expand Up @@ -6,74 +6,41 @@ class SortTest < Test::Unit::TestCase

context "Sort" do

context "with the old interface" do

should "encode simple strings" do
assert_equal [:foo].to_json, Sort.new.foo.to_json
end

should "encode method arguments" do
assert_equal [:foo => 'desc'].to_json, Sort.new.foo('desc').to_json
end

should "encode hash" do
assert_equal [ :foo => { :reverse => true } ].to_json, Sort.new.foo(:reverse => true).to_json
end

should "encode multiple sort fields" do
assert_equal [:foo, :bar].to_json, Sort.new.foo.bar.to_json
end

should "encode fields when passed as a block to constructor with deprecated interface" do
s = Sort.new do
foo
bar 'desc'
_score
end
assert_equal [ :foo, {:bar => 'desc'}, :_score ].to_json, s.to_json
end

should "be serialized to JSON" do
assert_respond_to Sort.new, :to_json
end

context "with the new interface" do

should "be serialized to JSON" do
assert_respond_to Sort.new, :to_json
end

should "encode simple strings" do
assert_equal [:foo].to_json, Sort.new.by(:foo).to_json
end
should "encode simple strings" do
assert_equal [:foo].to_json, Sort.new.by(:foo).to_json
end

should "encode method arguments" do
assert_equal [:foo => 'desc'].to_json, Sort.new.by(:foo, 'desc').to_json
end
should "encode method arguments" do
assert_equal [:foo => 'desc'].to_json, Sort.new.by(:foo, 'desc').to_json
end

should "encode hash" do
assert_equal [ :foo => { :reverse => true } ].to_json, Sort.new.by(:foo, :reverse => true).to_json
end
should "encode hash" do
assert_equal [ :foo => { :reverse => true } ].to_json, Sort.new.by(:foo, :reverse => true).to_json
end

should "encode multiple sort fields in chain" do
assert_equal [:foo, :bar].to_json, Sort.new.by(:foo).by(:bar).to_json
end
should "encode multiple sort fields in chain" do
assert_equal [:foo, :bar].to_json, Sort.new.by(:foo).by(:bar).to_json
end

should "encode fields when passed as a block to constructor" do
s = Sort.new do
by :foo
by :bar, 'desc'
by :_score
end
assert_equal [ :foo, {:bar => 'desc'}, :_score ].to_json, s.to_json
should "encode fields when passed as a block to constructor" do
s = Sort.new do
by :foo
by :bar, 'desc'
by :_score
end
assert_equal [ :foo, {:bar => 'desc'}, :_score ].to_json, s.to_json
end

should "encode fields deeper in json" do
s = Sort.new { by 'author.name' }
assert_equal [ 'author.name' ].to_json, s.to_json

s = Sort.new { by 'author.name', 'desc' }
assert_equal [ {'author.name' => 'desc'} ].to_json, s.to_json
end
should "encode fields deeper in json" do
s = Sort.new { by 'author.name' }
assert_equal [ 'author.name' ].to_json, s.to_json

s = Sort.new { by 'author.name', 'desc' }
assert_equal [ {'author.name' => 'desc'} ].to_json, s.to_json
end

end
Expand Down

0 comments on commit a05e4bf

Please sign in to comment.