websolr-rails 2.1.3 → 2.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/bin/websolr +40 -0
- data/lib/plain_option_parser.rb +80 -0
- data/websolr-rails.gemspec +6 -2
- metadata +7 -5
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.
|
1
|
+
2.2.0
|
data/bin/websolr
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require File.dirname(__FILE__) + "/../lib/plain_option_parser"
|
3
|
+
require "rubygems"
|
4
|
+
require "restclient"
|
5
|
+
|
6
|
+
HOST = "www.websolr.com"
|
7
|
+
|
8
|
+
PWD = File.expand_path(".")
|
9
|
+
controller = PlainOptionParser.new(ARGV) do
|
10
|
+
def die(s)
|
11
|
+
STDERR.puts(s.strip)
|
12
|
+
exit(1)
|
13
|
+
end
|
14
|
+
|
15
|
+
def init_heroku
|
16
|
+
puts "Getting username and password from Heroku config ... "
|
17
|
+
cfg = `heroku config`
|
18
|
+
@user = cfg[/WEBSOLR_USER\s*=>\s*(\S+)/, 1]
|
19
|
+
@pass = cfg[/WEBSOLR_PWD\s*=>\s*(\S+)/, 1]
|
20
|
+
unless @user && @pass
|
21
|
+
die <<-STR
|
22
|
+
Cannot retrieve username and password. Are you inside a Heroku app folder
|
23
|
+
with the Websolr addon enabled?
|
24
|
+
STR
|
25
|
+
end
|
26
|
+
@url = "http://#{@user}:#{@pass}@#{HOST}/users/default_slice_client"
|
27
|
+
end
|
28
|
+
|
29
|
+
desc "shows your heroku-created index"
|
30
|
+
cmd "heroku show client" do
|
31
|
+
init_heroku
|
32
|
+
puts RestClient.get(@url)
|
33
|
+
end
|
34
|
+
|
35
|
+
desc "sets the client to use"
|
36
|
+
cmd "heroku set client", "[sunspot|acts_as_solr]" do |client|
|
37
|
+
init_heroku
|
38
|
+
puts RestClient.post(@url, :client => client)
|
39
|
+
end
|
40
|
+
end.start
|
@@ -0,0 +1,80 @@
|
|
1
|
+
class PlainOptionParser
|
2
|
+
def initialize(args, &block)
|
3
|
+
@commands = []
|
4
|
+
desc "Prints help text for your command"
|
5
|
+
cmd "help" do
|
6
|
+
viable, remaining = commands_for_args(args[1, args.length])
|
7
|
+
if viable.length == 0
|
8
|
+
no_match
|
9
|
+
else
|
10
|
+
pretty_print viable
|
11
|
+
end
|
12
|
+
end
|
13
|
+
@args = args
|
14
|
+
instance_eval(&block)
|
15
|
+
end
|
16
|
+
|
17
|
+
def start
|
18
|
+
viable, remaining = commands_for_args(@args)
|
19
|
+
if viable.length == 1
|
20
|
+
viable[0].last.call(*remaining)
|
21
|
+
exit 0
|
22
|
+
elsif viable.length == 0
|
23
|
+
no_match
|
24
|
+
else
|
25
|
+
usage
|
26
|
+
pretty_print viable
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def desc(string)
|
31
|
+
@desc = string
|
32
|
+
end
|
33
|
+
|
34
|
+
def cmd(name, additional = "", &block)
|
35
|
+
@commands << [name.split(/\s+/), @desc, additional, block]
|
36
|
+
@desc = nil
|
37
|
+
end
|
38
|
+
|
39
|
+
def pretty_print(cmds)
|
40
|
+
mapped = cmds.map do |cmd|
|
41
|
+
name, desc, additional, block = cmd
|
42
|
+
[" #{File.basename($0)} " + name.join(" ") + " #{additional}", " -- #{desc}"]
|
43
|
+
end
|
44
|
+
max = mapped.inject(0) do |memo, entry|
|
45
|
+
memo > entry.first.length ? memo : entry.first.length
|
46
|
+
end
|
47
|
+
mapped.each do |entry|
|
48
|
+
puts entry.first + (" " * (max - entry.first.length)) + entry.last
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
private
|
53
|
+
|
54
|
+
def usage
|
55
|
+
puts "Usage: #{$0} COMMANDS"
|
56
|
+
puts
|
57
|
+
puts "COMMANDS: "
|
58
|
+
end
|
59
|
+
|
60
|
+
def commands_for_args(args)
|
61
|
+
viable = @commands.dup
|
62
|
+
args.each_with_index do |arg, i|
|
63
|
+
@commands.each do |cmd|
|
64
|
+
name, desc, additional, block = cmd
|
65
|
+
viable.delete(cmd) if name[i] != arg
|
66
|
+
end
|
67
|
+
if viable.length == 1
|
68
|
+
return [viable, args[viable[0][0].length, @args.length]]
|
69
|
+
end
|
70
|
+
end
|
71
|
+
return [viable, []]
|
72
|
+
end
|
73
|
+
|
74
|
+
def no_match
|
75
|
+
puts "No matching command found."
|
76
|
+
puts
|
77
|
+
usage
|
78
|
+
pretty_print @commands
|
79
|
+
end
|
80
|
+
end
|
data/websolr-rails.gemspec
CHANGED
@@ -5,13 +5,15 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{websolr-rails}
|
8
|
-
s.version = "2.
|
8
|
+
s.version = "2.2.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Kyle Maxwell"]
|
12
|
-
s.date = %q{2009-10-
|
12
|
+
s.date = %q{2009-10-20}
|
13
|
+
s.default_executable = %q{websolr}
|
13
14
|
s.description = %q{Makes Sunspot and acts_as_solr play with WebSolr}
|
14
15
|
s.email = %q{kyle@kylemaxwell.com}
|
16
|
+
s.executables = ["websolr"]
|
15
17
|
s.extra_rdoc_files = [
|
16
18
|
"LICENSE",
|
17
19
|
"README.rdoc"
|
@@ -23,6 +25,8 @@ Gem::Specification.new do |s|
|
|
23
25
|
"README.rdoc",
|
24
26
|
"Rakefile",
|
25
27
|
"VERSION",
|
28
|
+
"bin/websolr",
|
29
|
+
"lib/plain_option_parser.rb",
|
26
30
|
"lib/websolr-rails.rb",
|
27
31
|
"lib/websolr.rb",
|
28
32
|
"websolr-rails.gemspec"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: websolr-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kyle Maxwell
|
@@ -9,14 +9,14 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-10-
|
13
|
-
default_executable:
|
12
|
+
date: 2009-10-20 00:00:00 -07:00
|
13
|
+
default_executable: websolr
|
14
14
|
dependencies: []
|
15
15
|
|
16
16
|
description: Makes Sunspot and acts_as_solr play with WebSolr
|
17
17
|
email: kyle@kylemaxwell.com
|
18
|
-
executables:
|
19
|
-
|
18
|
+
executables:
|
19
|
+
- websolr
|
20
20
|
extensions: []
|
21
21
|
|
22
22
|
extra_rdoc_files:
|
@@ -29,6 +29,8 @@ files:
|
|
29
29
|
- README.rdoc
|
30
30
|
- Rakefile
|
31
31
|
- VERSION
|
32
|
+
- bin/websolr
|
33
|
+
- lib/plain_option_parser.rb
|
32
34
|
- lib/websolr-rails.rb
|
33
35
|
- lib/websolr.rb
|
34
36
|
- websolr-rails.gemspec
|