onemorecloud-websolr-rails 1.4.0 → 1.4.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +3 -0
- data/VERSION +1 -1
- data/lib/websolr_controller.rb +50 -27
- data/lib/websolr_option_parser.rb +6 -6
- data/websolr-rails.gemspec +1 -1
- metadata +1 -1
data/CHANGELOG
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.4.
|
1
|
+
1.4.1
|
data/lib/websolr_controller.rb
CHANGED
@@ -18,16 +18,18 @@ mkdir_p SOLR_PIDS_PATH
|
|
18
18
|
mkdir_p SOLR_DATA_PATH
|
19
19
|
|
20
20
|
class WebsolrController
|
21
|
-
COMMANDS = %w[add list delete configure start stop]
|
21
|
+
COMMANDS = %w[add list delete configure local:start local:stop]
|
22
22
|
SOLR_PORT = 8983
|
23
23
|
|
24
24
|
def initialize(parser)
|
25
25
|
@options = parser.options
|
26
26
|
@command = @options.delete(:command)
|
27
27
|
@parser = parser
|
28
|
-
@user = @options[:user]
|
29
|
-
@pass = @options[:pass]
|
30
|
-
|
28
|
+
@user = @options[:user] ||= ENV["WEBSOLR_USER"]
|
29
|
+
@pass = @options[:pass] ||= ENV["WEBSOLR_PWD"]
|
30
|
+
if @user && @pass
|
31
|
+
@base = "http://#{URI::escape @user}:#{URI::escape @pass}@websolr.com"
|
32
|
+
end
|
31
33
|
end
|
32
34
|
|
33
35
|
def die(s)
|
@@ -36,6 +38,16 @@ class WebsolrController
|
|
36
38
|
end
|
37
39
|
|
38
40
|
def required_options(hash)
|
41
|
+
hash = hash.dup
|
42
|
+
if hash.delete(:auth) && (!@user || !@pass)
|
43
|
+
die <<-STR
|
44
|
+
|
45
|
+
You need to specify your username and password, either on the command
|
46
|
+
line with the -u and -p flags, or in the WEBSOLR_USER and WEBSOLR_PWD
|
47
|
+
environment variables.
|
48
|
+
|
49
|
+
STR
|
50
|
+
end
|
39
51
|
hash.inject(true) do |memo, (key, flag)|
|
40
52
|
unless @options[key]
|
41
53
|
STDERR.puts "Please use the #{flag} flag to specify the #{key}."
|
@@ -56,16 +68,37 @@ class WebsolrController
|
|
56
68
|
die("I can't find config/environment.rb. Are we in a rails app?")
|
57
69
|
end
|
58
70
|
|
59
|
-
unless
|
60
|
-
|
71
|
+
unless ENV["WEBSOLR_URL"]
|
72
|
+
ENV["WEBSOLR_URL"] = "http://localhost:8983/solr"
|
73
|
+
puts <<-STR
|
74
|
+
|
75
|
+
You haven't configured your app. You might want to do that. I
|
76
|
+
assume you just want a quick development server, so I'll start
|
77
|
+
one up for you at http://localhost:8983/solr.
|
78
|
+
|
79
|
+
You should let Rails know about it by setting the WEBSOLR_URL, i.e:
|
80
|
+
|
81
|
+
> ./script/server WEBSOLR_URL=http://localhost:8983/solr
|
82
|
+
|
83
|
+
If you want to set up a full environment, run websolr configure.
|
84
|
+
|
85
|
+
STR
|
86
|
+
puts "Is this what you want? [yes]"
|
87
|
+
if STDIN.gets.strip =~/^(yes)?$/i
|
88
|
+
puts "Continuing...."
|
89
|
+
else
|
90
|
+
die "Aborted."
|
91
|
+
end
|
61
92
|
end
|
62
|
-
|
93
|
+
|
94
|
+
|
95
|
+
uri = URI.parse(ENV["WEBSOLR_URL"])
|
63
96
|
@port = uri.port
|
64
97
|
rescue URI::InvalidURIError => e
|
65
98
|
die(e.message)
|
66
99
|
end
|
67
100
|
|
68
|
-
def
|
101
|
+
def cmd_local_start
|
69
102
|
check_local_solr_conditions
|
70
103
|
begin
|
71
104
|
n = Net::HTTP.new('127.0.0.1', @port)
|
@@ -86,7 +119,7 @@ class WebsolrController
|
|
86
119
|
end
|
87
120
|
end
|
88
121
|
|
89
|
-
def
|
122
|
+
def cmd_local_stop
|
90
123
|
ENV["RAILS_ENV"] = @options[:rails_env] || ENV["RAILS_ENV"] || "development"
|
91
124
|
fork do
|
92
125
|
file_path = "#{SOLR_PIDS_PATH}/#{ENV['RAILS_ENV']}_pid"
|
@@ -105,13 +138,13 @@ class WebsolrController
|
|
105
138
|
end
|
106
139
|
|
107
140
|
def cmd_add
|
108
|
-
required_options :name => "-n"
|
141
|
+
required_options :name => "-n", :auth => true
|
109
142
|
doc = post "/slices.xml", {:slice => {:name => name}}
|
110
143
|
puts "#{x doc, '//name'}\t#{x doc, '//base-url'}"
|
111
144
|
end
|
112
145
|
|
113
146
|
def cmd_delete
|
114
|
-
required_options :name => "-n"
|
147
|
+
required_options :name => "-n", :auth => true
|
115
148
|
delete "/slices/#{name}/destroy"
|
116
149
|
puts "done"
|
117
150
|
end
|
@@ -121,6 +154,7 @@ class WebsolrController
|
|
121
154
|
end
|
122
155
|
|
123
156
|
def cmd_list
|
157
|
+
required_options :auth => true
|
124
158
|
doc = get "/slices.xml"
|
125
159
|
REXML::XPath.each(doc, "//slice") do |node|
|
126
160
|
puts "#{x node, 'name'}\t#{x node, 'base-url'}"
|
@@ -147,7 +181,7 @@ class WebsolrController
|
|
147
181
|
end
|
148
182
|
|
149
183
|
def cmd_configure
|
150
|
-
required_options :name => "-n"
|
184
|
+
required_options :name => "-n", :auth => true
|
151
185
|
doc = get "/slices.xml"
|
152
186
|
found = false
|
153
187
|
REXML::XPath.each(doc, "//slice") do |node|
|
@@ -163,7 +197,7 @@ case RAILS_ENV
|
|
163
197
|
when 'production'
|
164
198
|
ENV['WEBSOLR_URL'] ||= '#{x node, 'base-url'}'
|
165
199
|
else
|
166
|
-
ENV['WEBSOLR_URL'] ||= 'http://localhost:8983'
|
200
|
+
ENV['WEBSOLR_URL'] ||= 'http://localhost:8983/solr'
|
167
201
|
end
|
168
202
|
STR
|
169
203
|
f.puts str
|
@@ -184,21 +218,10 @@ STR
|
|
184
218
|
end
|
185
219
|
|
186
220
|
def start
|
187
|
-
if
|
188
|
-
|
189
|
-
send("cmd_#{@command}")
|
190
|
-
else
|
191
|
-
puts @parser
|
192
|
-
exit(1)
|
193
|
-
end
|
221
|
+
if(COMMANDS.include?(@command))
|
222
|
+
send("cmd_#{@command.gsub(/\W+/, '_')}")
|
194
223
|
else
|
195
|
-
puts
|
196
|
-
|
197
|
-
You need to specify your username and password, either on the command
|
198
|
-
line with the -u and -p flags, or in the WEBSOLR_USER and WEBSOLR_PWD
|
199
|
-
environment variables.
|
200
|
-
|
201
|
-
STR
|
224
|
+
puts @parser
|
202
225
|
exit(1)
|
203
226
|
end
|
204
227
|
end
|
@@ -7,13 +7,13 @@ class WebsolrOptionParser < OptionParser
|
|
7
7
|
"Usage: #{$0} COMMAND [INDEX_NAME] [options]
|
8
8
|
|
9
9
|
COMMANDs:
|
10
|
-
start
|
11
|
-
stop
|
10
|
+
local:start - starts the local development server
|
11
|
+
local:stop - stops the local development server
|
12
12
|
|
13
|
-
add
|
14
|
-
list
|
15
|
-
delete
|
16
|
-
configure
|
13
|
+
add - creates a new index
|
14
|
+
list - shows your indexes
|
15
|
+
delete - deletes an index
|
16
|
+
configure - adds websolr to your current Rails app
|
17
17
|
|
18
18
|
"
|
19
19
|
end
|
data/websolr-rails.gemspec
CHANGED