rubberband 0.1.5 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -1,5 +1,3 @@
1
1
  source "http://rubygems.org"
2
2
 
3
3
  gemspec
4
-
5
- gem "patron", "~> 0.4.12"
@@ -17,7 +17,15 @@ Copyright 2010-2011 Grant Rodgers. See included LICENSE file.
17
17
 
18
18
  Instantiate a client:
19
19
 
20
- client = ElasticSearch.new('127.0.0.1:9200', :index => "twitter", :type => "tweet")
20
+ client = ElasticSearch.new('127.0.0.1:9200', :index => "twitter", :type => "tweet")
21
+
22
+ Instantiate a client with multiple servers:
23
+
24
+ client = ElasticSearch.new(['127.0.0.1:9200', '127.0.0.1:9201'])
25
+
26
+ Instantiate a client using a Heroku URL (this sets the default index):
27
+
28
+ client = ElasticSearch.new(ENV['ELASTICSEARCH_URL'])
21
29
 
22
30
  API:
23
31
 
@@ -8,7 +8,7 @@ require 'client'
8
8
 
9
9
  module ElasticSearch
10
10
 
11
- def self.new(servers, options={})
12
- ElasticSearch::Client.new(servers, options)
11
+ def self.new(servers_or_url, options={})
12
+ ElasticSearch::Client.new(servers_or_url, options)
13
13
  end
14
14
  end
@@ -1,3 +1,5 @@
1
+ require 'uri'
2
+
1
3
  module ElasticSearch
2
4
  class AbstractClient
3
5
 
@@ -5,12 +7,31 @@ module ElasticSearch
5
7
  :transport => ElasticSearch::Transport::HTTP
6
8
  }.freeze
7
9
 
8
- def initialize(servers, options={})
10
+ def initialize(servers_or_url, options={})
9
11
  @options = DEFAULTS.merge(options)
10
- @server_list = Array(servers)
12
+ @server_list, @default_index, @default_type = extract_server_list_and_defaults(servers_or_url)
11
13
  @current_server = @server_list.first
12
14
  end
13
15
 
16
+ def extract_server_list_and_defaults(servers_or_url)
17
+ default_index = default_type = nil
18
+ servers = Array(servers_or_url).collect do |server|
19
+ uri = URI.parse(server)
20
+ _, default_index, default_type = uri.path.split("/")
21
+ uri.path = "" # is this expected behavior of URI? may be dangerous to rely on
22
+ uri.to_s
23
+ end
24
+ [servers, default_index, default_type]
25
+ end
26
+
27
+ def current_server
28
+ @current_server
29
+ end
30
+
31
+ def servers
32
+ @server_list
33
+ end
34
+
14
35
  def inspect
15
36
  "<#{self.class} @current_server=#{@current_server} @server_list=#{@server_list.inspect} @options=#{@options.inspect}>"
16
37
  end
@@ -55,7 +55,8 @@ module ElasticSearch
55
55
  execute(:alias_index, alias_ops, options)
56
56
  end
57
57
 
58
- def get_aliases(index, options={})
58
+ def get_aliases(index=default_index, options={})
59
+ index, type, options = extract_scope(options)
59
60
  execute(:get_aliases, index, options)
60
61
  end
61
62
 
@@ -83,7 +84,7 @@ module ElasticSearch
83
84
  execute(:update_settings, index, settings, options)
84
85
  end
85
86
 
86
- def get_settings(index, options={})
87
+ def get_settings(index=default_index, options={})
87
88
  execute(:get_settings, index, options)
88
89
  end
89
90
 
@@ -1,3 +1,3 @@
1
1
  module ElasticSearch
2
- VERSION = "0.1.5"
2
+ VERSION = "0.1.6"
3
3
  end
@@ -26,12 +26,11 @@ Gem::Specification.new do |s|
26
26
  ]
27
27
  s.licenses = ["Apache v2"]
28
28
 
29
- s.add_runtime_dependency("patron", [">= 0"])
29
+ s.add_runtime_dependency("patron", ["~> 0.4.12"])
30
30
  s.add_runtime_dependency("yajl-ruby", [">= 0"])
31
31
  s.add_development_dependency("rake", ["~> 0.9.2"])
32
32
  s.add_development_dependency("rspec", ["~> 2.0"])
33
33
  s.add_development_dependency("yard", [">= 0.7.0"])
34
- s.add_development_dependency("bundler", ["~> 1.0.0"])
35
34
  s.add_development_dependency("simplecov", [">= 0.3.8"])
36
35
  s.add_development_dependency("mocha", ["~> 0.9.0"])
37
36
 
@@ -16,11 +16,15 @@ describe "basic ops" do
16
16
 
17
17
  @client.update_mapping({"tweet" => {:properties => {:bar => {:type => "string"}}}})
18
18
  @client.index_mapping(@first_index).should == {@first_index => {"tweet" => { "properties" => { "foo" => {"type" => "string" }, "bar" => { "type" => "string"}}}}}
19
+ # default should also work
20
+ @client.index_mapping.should == {@first_index => {"tweet" => { "properties" => { "foo" => {"type" => "string" }, "bar" => { "type" => "string"}}}}}
19
21
  end
20
22
 
21
23
  it "should get and update settings" do
22
24
  @client.update_settings("index" => {"refresh_interval" => 30})
23
25
  @client.get_settings(@first_index)[@first_index]["settings"].should include("index.refresh_interval" => "30")
26
+ # default should also work
27
+ @client.get_settings[@first_index]["settings"].should include("index.refresh_interval" => "30")
24
28
  end
25
29
 
26
30
  it "should get and update aliases" do
@@ -31,5 +35,9 @@ describe "basic ops" do
31
35
  result = @client.get_aliases(@first_index)
32
36
  result[@first_index]["aliases"].keys.should_not include("#{@first_index}-alias")
33
37
  result[@first_index]["aliases"].keys.should include("#{@first_index}-alias2")
38
+ # default should also work
39
+ result = @client.get_aliases
40
+ result[@first_index]["aliases"].keys.should_not include("#{@first_index}-alias")
41
+ result[@first_index]["aliases"].keys.should include("#{@first_index}-alias2")
34
42
  end
35
43
  end
@@ -9,9 +9,21 @@ describe "connect" do
9
9
  client = ElasticSearch.new(servers)
10
10
  client.nodes_info.should include('cluster_name')
11
11
  end
12
+
12
13
  end
13
14
 
14
15
  context "multiple servers" do
16
+ let(:servers) { ['http://127.0.0.1:9200', 'http://127.0.0.1:9201'] }
17
+
18
+ it 'should set servers array' do
19
+ client = ElasticSearch.new(servers, :auto_discovery => false)
20
+ client.servers.should == servers
21
+ end
22
+
23
+ it 'should choose a server to connect to' do
24
+ client = ElasticSearch.new(servers, :auto_discovery => false)
25
+ servers.should include(client.current_server)
26
+ end
15
27
  end
16
28
 
17
29
  context 'invalid server' do
@@ -29,4 +41,21 @@ describe "connect" do
29
41
  expect { ElasticSearch.new(servers).nodes_info }.to raise_error(ElasticSearch::ConnectionFailed)
30
42
  end
31
43
  end
44
+
45
+ context 'server url with index' do
46
+ let(:servers) { 'http://127.0.0.1:9200/test_index' }
47
+
48
+ it 'should set default_index' do
49
+ client = ElasticSearch.new(servers, :auto_discovery => false)
50
+ client.current_server.should == 'http://127.0.0.1:9200'
51
+ client.default_index.should == 'test_index'
52
+ end
53
+
54
+ it 'should set default_type' do
55
+ client = ElasticSearch.new(servers + "/test_type", :auto_discovery => false)
56
+ client.current_server.should == 'http://127.0.0.1:9200'
57
+ client.default_index.should == 'test_index'
58
+ client.default_type.should == 'test_type'
59
+ end
60
+ end
32
61
  end
metadata CHANGED
@@ -1,156 +1,102 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: rubberband
3
- version: !ruby/object:Gem::Version
4
- hash: 17
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.6
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 1
9
- - 5
10
- version: 0.1.5
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Grant Rodgers
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2011-11-04 00:00:00 Z
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
12
+ date: 2012-02-17 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
21
15
  name: patron
22
- prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: &16575640 !ruby/object:Gem::Requirement
24
17
  none: false
25
- requirements:
26
- - - ">="
27
- - !ruby/object:Gem::Version
28
- hash: 3
29
- segments:
30
- - 0
31
- version: "0"
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 0.4.12
32
22
  type: :runtime
33
- version_requirements: *id001
34
- - !ruby/object:Gem::Dependency
35
- name: yajl-ruby
36
23
  prerelease: false
37
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: *16575640
25
+ - !ruby/object:Gem::Dependency
26
+ name: yajl-ruby
27
+ requirement: &16575000 !ruby/object:Gem::Requirement
38
28
  none: false
39
- requirements:
40
- - - ">="
41
- - !ruby/object:Gem::Version
42
- hash: 3
43
- segments:
44
- - 0
45
- version: "0"
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
46
33
  type: :runtime
47
- version_requirements: *id002
48
- - !ruby/object:Gem::Dependency
49
- name: rake
50
34
  prerelease: false
51
- requirement: &id003 !ruby/object:Gem::Requirement
35
+ version_requirements: *16575000
36
+ - !ruby/object:Gem::Dependency
37
+ name: rake
38
+ requirement: &16574340 !ruby/object:Gem::Requirement
52
39
  none: false
53
- requirements:
40
+ requirements:
54
41
  - - ~>
55
- - !ruby/object:Gem::Version
56
- hash: 63
57
- segments:
58
- - 0
59
- - 9
60
- - 2
42
+ - !ruby/object:Gem::Version
61
43
  version: 0.9.2
62
44
  type: :development
63
- version_requirements: *id003
64
- - !ruby/object:Gem::Dependency
65
- name: rspec
66
45
  prerelease: false
67
- requirement: &id004 !ruby/object:Gem::Requirement
46
+ version_requirements: *16574340
47
+ - !ruby/object:Gem::Dependency
48
+ name: rspec
49
+ requirement: &16573760 !ruby/object:Gem::Requirement
68
50
  none: false
69
- requirements:
51
+ requirements:
70
52
  - - ~>
71
- - !ruby/object:Gem::Version
72
- hash: 3
73
- segments:
74
- - 2
75
- - 0
76
- version: "2.0"
53
+ - !ruby/object:Gem::Version
54
+ version: '2.0'
77
55
  type: :development
78
- version_requirements: *id004
79
- - !ruby/object:Gem::Dependency
80
- name: yard
81
56
  prerelease: false
82
- requirement: &id005 !ruby/object:Gem::Requirement
57
+ version_requirements: *16573760
58
+ - !ruby/object:Gem::Dependency
59
+ name: yard
60
+ requirement: &16573180 !ruby/object:Gem::Requirement
83
61
  none: false
84
- requirements:
85
- - - ">="
86
- - !ruby/object:Gem::Version
87
- hash: 3
88
- segments:
89
- - 0
90
- - 7
91
- - 0
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
92
65
  version: 0.7.0
93
66
  type: :development
94
- version_requirements: *id005
95
- - !ruby/object:Gem::Dependency
96
- name: bundler
97
67
  prerelease: false
98
- requirement: &id006 !ruby/object:Gem::Requirement
99
- none: false
100
- requirements:
101
- - - ~>
102
- - !ruby/object:Gem::Version
103
- hash: 23
104
- segments:
105
- - 1
106
- - 0
107
- - 0
108
- version: 1.0.0
109
- type: :development
110
- version_requirements: *id006
111
- - !ruby/object:Gem::Dependency
68
+ version_requirements: *16573180
69
+ - !ruby/object:Gem::Dependency
112
70
  name: simplecov
113
- prerelease: false
114
- requirement: &id007 !ruby/object:Gem::Requirement
71
+ requirement: &16572580 !ruby/object:Gem::Requirement
115
72
  none: false
116
- requirements:
117
- - - ">="
118
- - !ruby/object:Gem::Version
119
- hash: 3
120
- segments:
121
- - 0
122
- - 3
123
- - 8
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
124
76
  version: 0.3.8
125
77
  type: :development
126
- version_requirements: *id007
127
- - !ruby/object:Gem::Dependency
128
- name: mocha
129
78
  prerelease: false
130
- requirement: &id008 !ruby/object:Gem::Requirement
79
+ version_requirements: *16572580
80
+ - !ruby/object:Gem::Dependency
81
+ name: mocha
82
+ requirement: &16571980 !ruby/object:Gem::Requirement
131
83
  none: false
132
- requirements:
84
+ requirements:
133
85
  - - ~>
134
- - !ruby/object:Gem::Version
135
- hash: 59
136
- segments:
137
- - 0
138
- - 9
139
- - 0
86
+ - !ruby/object:Gem::Version
140
87
  version: 0.9.0
141
88
  type: :development
142
- version_requirements: *id008
89
+ prerelease: false
90
+ version_requirements: *16571980
143
91
  description: An ElasticSearch client with ThriftClient-like failover handling.
144
- email:
92
+ email:
145
93
  - grantr@gmail.com
146
94
  executables: []
147
-
148
95
  extensions: []
149
-
150
- extra_rdoc_files:
96
+ extra_rdoc_files:
151
97
  - LICENSE
152
98
  - README.rdoc
153
- files:
99
+ files:
154
100
  - .autotest
155
101
  - .gitignore
156
102
  - .rspec
@@ -195,39 +141,31 @@ files:
195
141
  - spec/type_spec.rb
196
142
  - vendor/elasticsearch/elasticsearch.thrift
197
143
  homepage: http://github.com/grantr/rubberband
198
- licenses:
144
+ licenses:
199
145
  - Apache v2
200
146
  post_install_message:
201
147
  rdoc_options: []
202
-
203
- require_paths:
148
+ require_paths:
204
149
  - lib
205
- required_ruby_version: !ruby/object:Gem::Requirement
150
+ required_ruby_version: !ruby/object:Gem::Requirement
206
151
  none: false
207
- requirements:
208
- - - ">="
209
- - !ruby/object:Gem::Version
210
- hash: 3
211
- segments:
212
- - 0
213
- version: "0"
214
- required_rubygems_version: !ruby/object:Gem::Requirement
152
+ requirements:
153
+ - - ! '>='
154
+ - !ruby/object:Gem::Version
155
+ version: '0'
156
+ required_rubygems_version: !ruby/object:Gem::Requirement
215
157
  none: false
216
- requirements:
217
- - - ">="
218
- - !ruby/object:Gem::Version
219
- hash: 3
220
- segments:
221
- - 0
222
- version: "0"
158
+ requirements:
159
+ - - ! '>='
160
+ - !ruby/object:Gem::Version
161
+ version: '0'
223
162
  requirements: []
224
-
225
163
  rubyforge_project: rubberband
226
- rubygems_version: 1.8.10
164
+ rubygems_version: 1.8.11
227
165
  signing_key:
228
166
  specification_version: 3
229
167
  summary: An ElasticSearch client with ThriftClient-like failover handling.
230
- test_files:
168
+ test_files:
231
169
  - spec/admin_spec.rb
232
170
  - spec/bulk_spec.rb
233
171
  - spec/connect_spec.rb