esearch 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (102) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +6 -0
  3. data/.travis.yml +2 -5
  4. data/Changelog.md +5 -0
  5. data/Gemfile +1 -1
  6. data/Gemfile.devtools +22 -18
  7. data/config/flay.yml +2 -2
  8. data/config/reek.yml +5 -4
  9. data/config/rubocop.yml +81 -0
  10. data/esearch.gemspec +7 -7
  11. data/lib/esearch.rb +3 -1
  12. data/lib/esearch/cluster.rb +6 -5
  13. data/lib/esearch/command.rb +15 -7
  14. data/lib/esearch/command/cluster.rb +6 -4
  15. data/lib/esearch/command/document.rb +13 -13
  16. data/lib/esearch/command/exist.rb +6 -4
  17. data/lib/esearch/command/index.rb +7 -5
  18. data/lib/esearch/command/search.rb +5 -4
  19. data/lib/esearch/command/status.rb +5 -3
  20. data/lib/esearch/connection.rb +4 -3
  21. data/lib/esearch/document.rb +4 -2
  22. data/lib/esearch/index.rb +4 -2
  23. data/lib/esearch/indices.rb +8 -6
  24. data/lib/esearch/mixin.rb +8 -6
  25. data/lib/esearch/presenter.rb +5 -3
  26. data/lib/esearch/presenter/aspect.rb +5 -3
  27. data/lib/esearch/presenter/aspect/range.rb +11 -9
  28. data/lib/esearch/presenter/aspect/term.rb +6 -4
  29. data/lib/esearch/presenter/cluster.rb +6 -4
  30. data/lib/esearch/presenter/document.rb +12 -10
  31. data/lib/esearch/presenter/facet.rb +9 -9
  32. data/lib/esearch/presenter/hit.rb +9 -8
  33. data/lib/esearch/presenter/hits.rb +8 -7
  34. data/lib/esearch/presenter/index.rb +9 -7
  35. data/lib/esearch/presenter/search.rb +7 -5
  36. data/lib/esearch/presenter/status.rb +6 -4
  37. data/lib/esearch/request.rb +5 -3
  38. data/lib/esearch/type.rb +5 -2
  39. data/spec/integration/esearch/spike_spec.rb +15 -10
  40. data/spec/spec_helper.rb +6 -5
  41. data/spec/support/example_group_methods.rb +2 -0
  42. data/spec/support/ice_nine_config.rb +2 -0
  43. data/spec/unit/esearch/cluster_spec.rb +59 -0
  44. data/spec/unit/esearch/command/class_methods/run_spec.rb +3 -1
  45. data/spec/unit/esearch/command/cluster/health/run_spec.rb +2 -0
  46. data/spec/unit/esearch/command/document/delete/run_spec.rb +3 -1
  47. data/spec/unit/esearch/command/document/get/result_spec.rb +5 -3
  48. data/spec/unit/esearch/command/document/index/create/run_spec.rb +6 -2
  49. data/spec/unit/esearch/command/document/index/run_create_spec.rb +6 -2
  50. data/spec/unit/esearch/command/document/index/run_spec.rb +3 -1
  51. data/spec/unit/esearch/command/document/index/run_update_spec.rb +6 -2
  52. data/spec/unit/esearch/command/document/index/update/run_spec.rb +6 -2
  53. data/spec/unit/esearch/command/exist/result_spec.rb +5 -3
  54. data/spec/unit/esearch/command/index/create/run_spec.rb +2 -0
  55. data/spec/unit/esearch/command/index/delete/run_spec.rb +3 -1
  56. data/spec/unit/esearch/command/index/refresh/run_spec.rb +3 -1
  57. data/spec/unit/esearch/command/result_spec.rb +17 -7
  58. data/spec/unit/esearch/command/search/run_spec.rb +2 -0
  59. data/spec/unit/esearch/command/status/run_spec.rb +3 -1
  60. data/spec/unit/esearch/connection/class_methods/build_spec.rb +2 -0
  61. data/spec/unit/esearch/connection/run_spec.rb +6 -4
  62. data/spec/unit/esearch/document_spec.rb +44 -0
  63. data/spec/unit/esearch/index_spec.rb +42 -0
  64. data/spec/unit/esearch/indices/all_spec.rb +16 -0
  65. data/spec/unit/esearch/indices_spec.rb +18 -0
  66. data/spec/unit/esearch/mixin/document/index_create_spec.rb +2 -0
  67. data/spec/unit/esearch/mixin/document/index_spec.rb +2 -0
  68. data/spec/unit/esearch/mixin/document/index_update_spec.rb +2 -0
  69. data/spec/unit/esearch/mixin/exist/exist_predicate_spec.rb +2 -0
  70. data/spec/unit/esearch/mixin/index/refresh_spec.rb +2 -0
  71. data/spec/unit/esearch/mixin/index/status_spec.rb +2 -0
  72. data/spec/unit/esearch/mixin/search/search_spec.rb +2 -0
  73. data/spec/unit/esearch/presenter/aspect/range/from_spec.rb +2 -0
  74. data/spec/unit/esearch/presenter/aspect/range/to_spec.rb +2 -0
  75. data/spec/unit/esearch/presenter/class_methods/new_spec.rb +2 -0
  76. data/spec/unit/esearch/presenter/facet_spec.rb +60 -0
  77. data/spec/unit/esearch/presenter/hit/fields_spec.rb +2 -0
  78. data/spec/unit/esearch/presenter/hit/source_spec.rb +2 -0
  79. data/spec/unit/esearch/presenter/hits/each_spec.rb +7 -5
  80. data/spec/unit/esearch/presenter/hits/size_spec.rb +5 -3
  81. data/spec/unit/esearch/presenter/search_spec.rb +50 -0
  82. data/spec/unit/esearch/request_spec.rb +96 -0
  83. data/spec/unit/esearch/type_spec.rb +37 -0
  84. metadata +34 -50
  85. data/spec/unit/esearch/cluster/class_methods/connect_spec.rb +0 -16
  86. data/spec/unit/esearch/cluster/health_spec.rb +0 -10
  87. data/spec/unit/esearch/cluster/index_spec.rb +0 -11
  88. data/spec/unit/esearch/cluster/indices_spec.rb +0 -11
  89. data/spec/unit/esearch/cluster/path_spec.rb +0 -11
  90. data/spec/unit/esearch/document/connection_spec.rb +0 -12
  91. data/spec/unit/esearch/document/delete_spec.rb +0 -12
  92. data/spec/unit/esearch/document/get_spec.rb +0 -12
  93. data/spec/unit/esearch/index/create_spec.rb +0 -12
  94. data/spec/unit/esearch/index/delete_spec.rb +0 -11
  95. data/spec/unit/esearch/index/type_spec.rb +0 -12
  96. data/spec/unit/esearch/indices/all/path_spec.rb +0 -12
  97. data/spec/unit/esearch/presenter/facet/build_spec.rb +0 -26
  98. data/spec/unit/esearch/presenter/facet/class_methods/build_spec.rb +0 -26
  99. data/spec/unit/esearch/request/initialize_spec.rb +0 -39
  100. data/spec/unit/esearch/request/run_spec.rb +0 -39
  101. data/spec/unit/esearch/type/connection_spec.rb +0 -15
  102. data/spec/unit/esearch/type/document_spec.rb +0 -12
@@ -1,3 +1,5 @@
1
+ # encoding: UTF-8
2
+
1
3
  module Esearch
2
4
  class Presenter
3
5
 
@@ -15,13 +17,13 @@ module Esearch
15
17
  #
16
18
  # @api private
17
19
  #
18
- def each(&block)
20
+ def each
19
21
  return to_enum unless block_given?
20
22
 
21
23
  hits.each do |hit|
22
24
  yield Hit.new(hit)
23
25
  end
24
-
26
+
25
27
  self
26
28
  end
27
29
 
@@ -34,7 +36,7 @@ module Esearch
34
36
  def size
35
37
  hits.size
36
38
  end
37
-
39
+
38
40
  # Return total amount of hits in the query
39
41
  #
40
42
  # @return [Fixnum]
@@ -54,7 +56,6 @@ module Esearch
54
56
  expose_primitive(:hits)
55
57
  private :hits
56
58
 
57
- end
58
- end
59
- end
60
-
59
+ end # Hits
60
+ end # Presenter
61
+ end # Esearch
@@ -1,3 +1,5 @@
1
+ # encoding: UTF-8
2
+
1
3
  module Esearch
2
4
  class Presenter
3
5
 
@@ -7,17 +9,17 @@ module Esearch
7
9
  # Create operation presenter
8
10
  class Create < self
9
11
  expose_primitive :ok, :ok?
10
- end
12
+ end # Create
11
13
 
12
14
  # Delete operation presenter
13
15
  class Delete < self
14
16
  expose_primitive :ok, :ok?
15
- end
16
-
17
+ end # Delete
18
+
17
19
  # Refresh operation presenter
18
20
  class Refresh < self
19
- end
21
+ end # Referesh
20
22
 
21
- end
22
- end
23
- end
23
+ end # Index
24
+ end # Presenter
25
+ end # Esearch
@@ -1,3 +1,5 @@
1
+ # encoding: UTF-8
2
+
1
3
  module Esearch
2
4
  class Presenter
3
5
  # Presenter for search result
@@ -10,8 +12,8 @@ module Esearch
10
12
  # @api private
11
13
  #
12
14
  def facets
13
- raw.fetch('facets', {}).each_with_object({}) do |(name, body), hash|
14
- hash[name] = Facet.build(body)
15
+ raw.fetch('facets', {}).each_with_object({}) do |(name, body), aggregate|
16
+ aggregate[name] = Facet.build(body)
15
17
  end
16
18
  end
17
19
  memoize :facets
@@ -27,6 +29,6 @@ module Esearch
27
29
  end
28
30
  memoize :hits
29
31
 
30
- end
31
- end
32
- end
32
+ end # Search
33
+ end # Presenter
34
+ end # Esearch
@@ -1,3 +1,5 @@
1
+ # encoding: UTF-8
2
+
1
3
  module Esearch
2
4
  class Presenter
3
5
 
@@ -9,10 +11,10 @@ module Esearch
9
11
 
10
12
  expose_primitive('name')
11
13
 
12
- end
14
+ end # Index
13
15
 
14
16
  expose_tagged_collection('indices', Status::Index)
15
17
 
16
- end
17
- end
18
- end
18
+ end # Status
19
+ end # Presenter
20
+ end # Esearch
@@ -1,3 +1,5 @@
1
+ # encoding: UTF-8
2
+
1
3
  module Esearch
2
4
 
3
5
  # Request used to interface elasticsearch
@@ -75,7 +77,7 @@ module Esearch
75
77
  def run(connection)
76
78
  connection.public_send(verb, path) do |request|
77
79
  request.params = params
78
- request.headers[:content_type]=Command::JSON_CONTENT_TYPE
80
+ request.headers[:content_type] = Command::JSON_CONTENT_TYPE
79
81
  request.body = MultiJson.dump(body)
80
82
  end
81
83
  end
@@ -86,5 +88,5 @@ module Esearch
86
88
  end
87
89
  end
88
90
 
89
- end
90
- end
91
+ end # Request
92
+ end # Esearch
@@ -1,3 +1,5 @@
1
+ # encoding: UTF-8
2
+
1
3
  module Esearch
2
4
  # Interface to a specific elasticsearch type
3
5
  class Type
@@ -36,5 +38,6 @@ module Esearch
36
38
  es_index.path.join(name)
37
39
  end
38
40
  memoize :path
39
- end
40
- end
41
+
42
+ end # Type
43
+ end # Esearch
@@ -1,13 +1,18 @@
1
+ # encoding: UTF-8
2
+
1
3
  require 'spec_helper'
2
4
  require 'logger'
3
5
 
4
6
  describe Esearch do
7
+ before do
8
+ pending
9
+ end
5
10
  let(:uri) { ENV.fetch('ESEARCH_TEST_URI', 'http://localhost:9200') }
6
11
 
7
12
  SINGLE_NODE_SETTINGS = IceNine.deep_freeze(
8
- :settings => {
9
- :number_of_shards => 1,
10
- :number_of_replicas => 0
13
+ settings: {
14
+ number_of_shards: 1,
15
+ number_of_replicas: 0
11
16
  }
12
17
  )
13
18
 
@@ -28,19 +33,19 @@ describe Esearch do
28
33
 
29
34
  indices = cluster.indices(%w(test-a test-b))
30
35
 
31
- result_a = index_a.type('type-a').index({'foo' => 'bar'})
32
- result_b = index_b.type('type-b').index({'foo' => 'baz'})
36
+ result_a = index_a.type('type-a').index('foo' => 'bar')
37
+ result_b = index_b.type('type-b').index('foo' => 'baz')
33
38
 
34
- cluster.health(:wait_for_status => :green, :timeout => '10s')
39
+ cluster.health(wait_for_status: :green, timeout: '10s')
35
40
 
36
41
  indices.refresh
37
42
 
38
- result = index_a.search({:query => { :match_all => {}}})
39
- result.hits.map(&:source).should eql([{'foo' => 'bar'}])
43
+ result = index_a.search(query: { match_all: {} })
44
+ result.hits.map(&:source).should eql([{ 'foo' => 'bar' }])
40
45
 
41
- result = indices.search({:query => { :match_all => {}}})
46
+ result = indices.search(query: { match_all: {} })
42
47
 
43
- result.hits.map(&:source).to_set.should eql([{'foo' => 'bar'}, {'foo' => 'baz'}].to_set)
48
+ result.hits.map(&:source).to_set.should eql([{ 'foo' => 'bar' }, { 'foo' => 'baz' }].to_set)
44
49
 
45
50
  index_a.type('type-a').document(result_a.id).delete
46
51
 
@@ -1,3 +1,5 @@
1
+ # # encoding: UTF-8
2
+
1
3
  # encoding: utf-8
2
4
  require 'esearch'
3
5
  require 'devtools'
@@ -18,11 +20,11 @@ module CommandHelper
18
20
  end
19
21
 
20
22
  def setup_connection
21
- let(:context) { double('Context', :connection => connection, :path => Pathname.new('/foo')) }
22
- let(:connection) { double('Connection') }
23
+ let(:context) { double('Context', connection: connection, path: Pathname.new('/foo')) }
24
+ let(:connection) { double('Connection') }
23
25
 
24
- let(:headers) { {'content-type' => 'application/json; charset=UTF-8'} }
25
- let(:response) { double('Response', :frozen? => true, :status => status, :headers => headers, :body => '{}') }
26
+ let(:headers) { { 'content-type' => 'application/json; charset=UTF-8' } }
27
+ let(:response) { double('Response', :frozen? => true, status: status, headers: headers, body: '{}') }
26
28
 
27
29
  let(:status) { 200 }
28
30
 
@@ -59,7 +61,6 @@ module CommandHelper
59
61
  end
60
62
  end
61
63
 
62
-
63
64
  RSpec.configure do |config|
64
65
  config.include(CommandHelper)
65
66
  end
@@ -1,3 +1,5 @@
1
+ # encoding: UTF-8
2
+
1
3
  module Spec
2
4
  module ExampleGroupMethods
3
5
  def testing_block_passing_broken?
@@ -1,3 +1,5 @@
1
+ # encoding: UTF-8
2
+
1
3
  module IceNine
2
4
  class Freezer
3
5
  class RSpec < NoFreeze
@@ -0,0 +1,59 @@
1
+ # encoding: UTF-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Esearch::Cluster do
6
+ let(:object) { described_class.new(connection) }
7
+
8
+ let(:connection) { double('Connection') }
9
+
10
+ describe '.connect' do
11
+ subject { object.connect(*arguments) }
12
+
13
+ let(:object) { described_class }
14
+
15
+ let(:arguments) { [:foo, :bar] }
16
+
17
+ before do
18
+ Esearch::Connection.should_receive(:build).with(:foo, :bar).and_return(connection)
19
+ end
20
+
21
+ it { should eql(described_class.new(connection)) }
22
+ end
23
+
24
+ describe '#health' do
25
+ subject { object.health }
26
+
27
+ let(:expected_arguments) { [{}] }
28
+
29
+ expect_to_run_command(Esearch::Command::Cluster::Health)
30
+ end
31
+
32
+ describe '#index' do
33
+ subject { object.index(name) }
34
+
35
+ let(:name) { 'foo' }
36
+
37
+ it { should eql(Esearch::Index.new(connection, name)) }
38
+ end
39
+
40
+ describe '#all_indices' do
41
+ subject { object.all_indices }
42
+
43
+ it { should eql(Esearch::Indices::All.new(connection)) }
44
+ end
45
+
46
+ describe '#indices' do
47
+ subject { object.indices(names) }
48
+
49
+ let(:names) { %w(foo bar) }
50
+
51
+ it { should eql(Esearch::Indices.new(connection, names)) }
52
+ end
53
+
54
+ describe '#path' do
55
+ subject { object.path }
56
+
57
+ it { should eql(Pathname.new('/')) }
58
+ end
59
+ end
@@ -1,3 +1,5 @@
1
+ # encoding: UTF-8
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe Esearch::Command, '.run' do
@@ -5,7 +7,7 @@ describe Esearch::Command, '.run' do
5
7
 
6
8
  let(:object) { described_class }
7
9
 
8
- let(:instance) { double('Instance', :result => result) }
10
+ let(:instance) { double('Instance', result: result) }
9
11
  let(:result) { double('Result') }
10
12
  let(:arguments) { [:foo, :bar] }
11
13
 
@@ -1,3 +1,5 @@
1
+ # encoding: UTF-8
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe Esearch::Command::Cluster::Health, '.run' do
@@ -1,3 +1,5 @@
1
+ # encoding: UTF-8
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe Esearch::Command::Document::Delete, '.run' do
@@ -8,6 +10,6 @@ describe Esearch::Command::Document::Delete, '.run' do
8
10
  let(:expected_request) do
9
11
  Esearch::Request.new(:delete, '/foo', {}, {})
10
12
  end
11
-
13
+
12
14
  expect_presenter(Esearch::Presenter::Document::Operation::Delete)
13
15
  end
@@ -1,3 +1,5 @@
1
+ # encoding: UTF-8
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe Esearch::Command::Document::Get, '.run' do
@@ -8,17 +10,17 @@ describe Esearch::Command::Document::Get, '.run' do
8
10
  let(:expected_request) do
9
11
  Esearch::Request.new(:get, '/foo', {}, {})
10
12
  end
11
-
13
+
12
14
  context 'with status 200' do
13
15
  expect_presenter(Esearch::Presenter::Document::Get)
14
16
  end
15
-
17
+
16
18
  context 'with status 404' do
17
19
  expect_result(nil) do
18
20
  let(:status) { 404 }
19
21
  end
20
22
  end
21
-
23
+
22
24
  context 'with status 500' do
23
25
  expect_exception(Esearch::ProtocolError) do
24
26
  let(:status) { 500 }
@@ -1,3 +1,7 @@
1
+ # # encoding: UTF-8
2
+
3
+ # encoding: UTF-8
4
+
1
5
  require 'spec_helper'
2
6
 
3
7
  describe Esearch::Command::Document::Index::Create, '.run' do
@@ -5,10 +9,10 @@ describe Esearch::Command::Document::Index::Create, '.run' do
5
9
 
6
10
  let(:object) { described_class }
7
11
  let(:document) { double('Document') }
8
- let(:options) { { :foo => :bar } }
12
+ let(:options) { { foo: :bar } }
9
13
 
10
14
  let(:expected_request) do
11
- Esearch::Request.new(:post, '/foo', document, { :foo => :bar, :op_type => :create })
15
+ Esearch::Request.new(:post, '/foo', document, foo: :bar, op_type: :create)
12
16
  end
13
17
 
14
18
  expect_presenter(Esearch::Presenter::Document::Operation::Index) do
@@ -1,3 +1,7 @@
1
+ # # encoding: UTF-8
2
+
3
+ # encoding: UTF-8
4
+
1
5
  require 'spec_helper'
2
6
 
3
7
  describe Esearch::Command::Document::Index::Create, '.run' do
@@ -5,10 +9,10 @@ describe Esearch::Command::Document::Index::Create, '.run' do
5
9
 
6
10
  let(:object) { described_class }
7
11
  let(:document) { double('Document') }
8
- let(:options) { { :foo => :bar } }
12
+ let(:options) { { foo: :bar } }
9
13
 
10
14
  let(:expected_request) do
11
- Esearch::Request.new(:post, '/foo', document, { :foo => :bar, :op_type => :create })
15
+ Esearch::Request.new(:post, '/foo', document, foo: :bar, op_type: :create)
12
16
  end
13
17
 
14
18
  expect_presenter(Esearch::Presenter::Document::Operation::Index) do
@@ -1,3 +1,5 @@
1
+ # encoding: UTF-8
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe Esearch::Command::Document::Index, '.run' do
@@ -5,7 +7,7 @@ describe Esearch::Command::Document::Index, '.run' do
5
7
 
6
8
  let(:object) { described_class }
7
9
  let(:document) { double('Document') }
8
- let(:options) { { :foo => :bar } }
10
+ let(:options) { { foo: :bar } }
9
11
 
10
12
  let(:expected_request) do
11
13
  Esearch::Request.new(:post, '/foo', document, options)
@@ -1,3 +1,7 @@
1
+ # # encoding: UTF-8
2
+
3
+ # encoding: UTF-8
4
+
1
5
  require 'spec_helper'
2
6
 
3
7
  describe Esearch::Command::Document::Index::Update, '.run' do
@@ -5,10 +9,10 @@ describe Esearch::Command::Document::Index::Update, '.run' do
5
9
 
6
10
  let(:object) { described_class }
7
11
  let(:document) { double('Document') }
8
- let(:options) { { :foo => :bar } }
12
+ let(:options) { { foo: :bar } }
9
13
 
10
14
  let(:expected_request) do
11
- Esearch::Request.new(:post, '/foo', document, { :foo => :bar, :op_type => :index })
15
+ Esearch::Request.new(:post, '/foo', document, foo: :bar, op_type: :index)
12
16
  end
13
17
 
14
18
  expect_presenter(Esearch::Presenter::Document::Operation::Index)