websolr-rails 1.4.4 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (167) hide show
  1. data/.gitignore +1 -10
  2. data/LICENSE +17 -16
  3. data/README.rdoc +16 -62
  4. data/Rakefile +2 -60
  5. data/VERSION +1 -1
  6. data/lib/websolr-rails.rb +54 -1
  7. data/lib/websolr.rb +2 -1
  8. metadata +12 -215
  9. data/CHANGELOG +0 -8
  10. data/TESTING_THE_PLUGIN +0 -25
  11. data/bin/websolr +0 -10
  12. data/config/solr.yml +0 -15
  13. data/config/solr_environment.rb +0 -22
  14. data/generate_rdoc.sh +0 -13
  15. data/lib/acts_as_solr.rb +0 -65
  16. data/lib/acts_methods.rb +0 -281
  17. data/lib/class_methods.rb +0 -243
  18. data/lib/common_methods.rb +0 -89
  19. data/lib/deprecation.rb +0 -61
  20. data/lib/instance_methods.rb +0 -181
  21. data/lib/lazy_document.rb +0 -18
  22. data/lib/parser_methods.rb +0 -230
  23. data/lib/search_results.rb +0 -72
  24. data/lib/solr.rb +0 -21
  25. data/lib/solr/connection.rb +0 -190
  26. data/lib/solr/document.rb +0 -78
  27. data/lib/solr/exception.rb +0 -13
  28. data/lib/solr/field.rb +0 -39
  29. data/lib/solr/importer.rb +0 -19
  30. data/lib/solr/importer/array_mapper.rb +0 -26
  31. data/lib/solr/importer/delimited_file_source.rb +0 -38
  32. data/lib/solr/importer/hpricot_mapper.rb +0 -27
  33. data/lib/solr/importer/mapper.rb +0 -51
  34. data/lib/solr/importer/solr_source.rb +0 -43
  35. data/lib/solr/importer/xpath_mapper.rb +0 -35
  36. data/lib/solr/indexer.rb +0 -52
  37. data/lib/solr/request.rb +0 -26
  38. data/lib/solr/request/add_document.rb +0 -63
  39. data/lib/solr/request/base.rb +0 -36
  40. data/lib/solr/request/commit.rb +0 -31
  41. data/lib/solr/request/delete.rb +0 -50
  42. data/lib/solr/request/dismax.rb +0 -46
  43. data/lib/solr/request/index_info.rb +0 -22
  44. data/lib/solr/request/modify_document.rb +0 -51
  45. data/lib/solr/request/optimize.rb +0 -21
  46. data/lib/solr/request/ping.rb +0 -36
  47. data/lib/solr/request/select.rb +0 -56
  48. data/lib/solr/request/spellcheck.rb +0 -30
  49. data/lib/solr/request/standard.rb +0 -402
  50. data/lib/solr/request/update.rb +0 -23
  51. data/lib/solr/response.rb +0 -27
  52. data/lib/solr/response/add_document.rb +0 -17
  53. data/lib/solr/response/base.rb +0 -42
  54. data/lib/solr/response/commit.rb +0 -17
  55. data/lib/solr/response/delete.rb +0 -13
  56. data/lib/solr/response/dismax.rb +0 -8
  57. data/lib/solr/response/index_info.rb +0 -26
  58. data/lib/solr/response/modify_document.rb +0 -17
  59. data/lib/solr/response/optimize.rb +0 -14
  60. data/lib/solr/response/ping.rb +0 -28
  61. data/lib/solr/response/ruby.rb +0 -42
  62. data/lib/solr/response/select.rb +0 -17
  63. data/lib/solr/response/spellcheck.rb +0 -20
  64. data/lib/solr/response/standard.rb +0 -64
  65. data/lib/solr/response/xml.rb +0 -42
  66. data/lib/solr/solrtasks.rb +0 -27
  67. data/lib/solr/util.rb +0 -32
  68. data/lib/solr/xml.rb +0 -44
  69. data/lib/solr_fixtures.rb +0 -13
  70. data/lib/tasks/database.rake +0 -18
  71. data/lib/tasks/solr.rake +0 -94
  72. data/lib/tasks/test.rake +0 -7
  73. data/lib/websolr_controller.rb +0 -233
  74. data/lib/websolr_option_parser.rb +0 -61
  75. data/lib/websolr_rails.rb +0 -1
  76. data/lib/websolr_rails/tasks.rb +0 -4
  77. data/lib/will_paginate_support.rb +0 -12
  78. data/solr/CHANGES.txt +0 -1207
  79. data/solr/LICENSE.txt +0 -712
  80. data/solr/NOTICE.txt +0 -90
  81. data/solr/etc/jetty.xml +0 -205
  82. data/solr/etc/webdefault.xml +0 -379
  83. data/solr/lib/easymock.jar +0 -0
  84. data/solr/lib/jetty-6.1.3.jar +0 -0
  85. data/solr/lib/jetty-util-6.1.3.jar +0 -0
  86. data/solr/lib/jsp-2.1/ant-1.6.5.jar +0 -0
  87. data/solr/lib/jsp-2.1/core-3.1.1.jar +0 -0
  88. data/solr/lib/jsp-2.1/jsp-2.1.jar +0 -0
  89. data/solr/lib/jsp-2.1/jsp-api-2.1.jar +0 -0
  90. data/solr/lib/servlet-api-2.4.jar +0 -0
  91. data/solr/lib/servlet-api-2.5-6.1.3.jar +0 -0
  92. data/solr/lib/xpp3-1.1.3.4.O.jar +0 -0
  93. data/solr/logs/.empty-dir-for-git +0 -0
  94. data/solr/solr/README.txt +0 -52
  95. data/solr/solr/bin/abc +0 -176
  96. data/solr/solr/bin/abo +0 -176
  97. data/solr/solr/bin/backup +0 -108
  98. data/solr/solr/bin/backupcleaner +0 -142
  99. data/solr/solr/bin/commit +0 -128
  100. data/solr/solr/bin/optimize +0 -129
  101. data/solr/solr/bin/readercycle +0 -129
  102. data/solr/solr/bin/rsyncd-disable +0 -77
  103. data/solr/solr/bin/rsyncd-enable +0 -76
  104. data/solr/solr/bin/rsyncd-start +0 -145
  105. data/solr/solr/bin/rsyncd-stop +0 -105
  106. data/solr/solr/bin/scripts-util +0 -83
  107. data/solr/solr/bin/snapcleaner +0 -148
  108. data/solr/solr/bin/snapinstaller +0 -168
  109. data/solr/solr/bin/snappuller +0 -248
  110. data/solr/solr/bin/snappuller-disable +0 -77
  111. data/solr/solr/bin/snappuller-enable +0 -77
  112. data/solr/solr/bin/snapshooter +0 -109
  113. data/solr/solr/conf/admin-extra.html +0 -31
  114. data/solr/solr/conf/protwords.txt +0 -21
  115. data/solr/solr/conf/schema.xml +0 -126
  116. data/solr/solr/conf/scripts.conf +0 -24
  117. data/solr/solr/conf/solrconfig.xml +0 -458
  118. data/solr/solr/conf/stopwords.txt +0 -57
  119. data/solr/solr/conf/synonyms.txt +0 -31
  120. data/solr/solr/conf/xslt/example.xsl +0 -132
  121. data/solr/solr/conf/xslt/example_atom.xsl +0 -63
  122. data/solr/solr/conf/xslt/example_rss.xsl +0 -62
  123. data/solr/start.jar +0 -0
  124. data/solr/tmp/.empty-dir-for-git +0 -0
  125. data/solr/webapps/solr.war +0 -0
  126. data/test/config/solr.yml +0 -2
  127. data/test/db/connections/mysql/connection.rb +0 -10
  128. data/test/db/connections/sqlite/connection.rb +0 -8
  129. data/test/db/migrate/001_create_books.rb +0 -15
  130. data/test/db/migrate/002_create_movies.rb +0 -12
  131. data/test/db/migrate/003_create_categories.rb +0 -11
  132. data/test/db/migrate/004_create_electronics.rb +0 -16
  133. data/test/db/migrate/005_create_authors.rb +0 -12
  134. data/test/db/migrate/006_create_postings.rb +0 -9
  135. data/test/db/migrate/007_create_posts.rb +0 -13
  136. data/test/db/migrate/008_create_gadgets.rb +0 -11
  137. data/test/fixtures/authors.yml +0 -9
  138. data/test/fixtures/books.yml +0 -13
  139. data/test/fixtures/categories.yml +0 -7
  140. data/test/fixtures/db_definitions/mysql.sql +0 -41
  141. data/test/fixtures/electronics.yml +0 -49
  142. data/test/fixtures/movies.yml +0 -9
  143. data/test/fixtures/postings.yml +0 -10
  144. data/test/functional/acts_as_solr_test.rb +0 -413
  145. data/test/functional/association_indexing_test.rb +0 -37
  146. data/test/functional/faceted_search_test.rb +0 -163
  147. data/test/functional/multi_solr_search_test.rb +0 -51
  148. data/test/models/author.rb +0 -10
  149. data/test/models/book.rb +0 -10
  150. data/test/models/category.rb +0 -8
  151. data/test/models/electronic.rb +0 -21
  152. data/test/models/gadget.rb +0 -9
  153. data/test/models/movie.rb +0 -17
  154. data/test/models/novel.rb +0 -2
  155. data/test/models/post.rb +0 -3
  156. data/test/models/posting.rb +0 -11
  157. data/test/test_helper.rb +0 -51
  158. data/test/unit/acts_methods_shoulda.rb +0 -70
  159. data/test/unit/class_methods_shoulda.rb +0 -88
  160. data/test/unit/common_methods_shoulda.rb +0 -112
  161. data/test/unit/instance_methods_shoulda.rb +0 -326
  162. data/test/unit/lazy_document_shoulda.rb +0 -35
  163. data/test/unit/parser_instance.rb +0 -19
  164. data/test/unit/parser_methods_shoulda.rb +0 -278
  165. data/test/unit/solr_instance.rb +0 -46
  166. data/test/unit/test_helper.rb +0 -14
  167. data/websolr-rails.gemspec +0 -243
data/lib/solr/xml.rb DELETED
@@ -1,44 +0,0 @@
1
- # The ASF licenses this file to You under the Apache License, Version 2.0
2
- # (the "License"); you may not use this file except in compliance with
3
- # the License. You may obtain a copy of the License at
4
- #
5
- # http://www.apache.org/licenses/LICENSE-2.0
6
- #
7
- # Unless required by applicable law or agreed to in writing, software
8
- # distributed under the License is distributed on an "AS IS" BASIS,
9
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
- # See the License for the specific language governing permissions and
11
- # limitations under the License.
12
-
13
- module Solr::XML
14
- end
15
-
16
- begin
17
-
18
- # If we can load rubygems and libxml-ruby...
19
- require 'rubygems'
20
- require 'xml/libxml'
21
- raise "acts_as_solr requires libxml-ruby 0.7 or greater" unless XML::Node.public_instance_methods.include?("attributes")
22
-
23
- # then make a few modifications to XML::Node so it can stand in for REXML::Element
24
- class XML::Node
25
- # element.add_element(another_element) should work
26
- alias_method :add_element, :<<
27
-
28
-
29
- # element.text = "blah" should work
30
- def text=(x)
31
- self << x.to_s
32
- end
33
- end
34
-
35
- # And use XML::Node for our XML generation
36
- Solr::XML::Element = XML::Node
37
-
38
- rescue LoadError => e # If we can't load either rubygems or libxml-ruby
39
- puts "Requiring REXML"
40
- # Just use REXML.
41
- require 'rexml/document'
42
- Solr::XML::Element = REXML::Element
43
-
44
- end
data/lib/solr_fixtures.rb DELETED
@@ -1,13 +0,0 @@
1
- module ActsAsSolr
2
-
3
- class SolrFixtures
4
- def self.load(table_names)
5
- [table_names].flatten.map { |n| n.to_s }.each do |table_name|
6
- klass = instance_eval(File.split(table_name.to_s).last.to_s.gsub('_',' ').split(" ").collect{|w| w.capitalize}.to_s.singularize)
7
- klass.rebuild_solr_index if klass.respond_to?(:rebuild_solr_index)
8
- end
9
- ActsAsSolr::Post.execute(Solr::Request::Commit.new)
10
- end
11
- end
12
-
13
- end
@@ -1,18 +0,0 @@
1
- require File.dirname(__FILE__) + '/../solr_fixtures'
2
-
3
- namespace :db do
4
- namespace :fixtures do
5
- desc "Load fixtures into the current environment's database. Load specific fixtures using FIXTURES=x,y"
6
- task :load => :environment do
7
- begin
8
- ActsAsSolr::Post.execute(Solr::Request::Delete.new(:query => "*:*"))
9
- ActsAsSolr::Post.execute(Solr::Request::Commit.new)
10
- (ENV['FIXTURES'] ? ENV['FIXTURES'].split(/,/) : Dir.glob(File.join(RAILS_ROOT, 'test', 'fixtures', '*.{yml,csv}'))).each do |fixture_file|
11
- ActsAsSolr::SolrFixtures.load(File.basename(fixture_file, '.*'))
12
- end
13
- puts "The fixtures loaded have been added to Solr"
14
- rescue
15
- end
16
- end
17
- end
18
- end
data/lib/tasks/solr.rake DELETED
@@ -1,94 +0,0 @@
1
- require 'rubygems'
2
- require 'rake'
3
- require 'net/http'
4
- require 'active_record'
5
-
6
- namespace :solr do
7
-
8
- desc 'Starts Solr. Options accepted: RAILS_ENV=your_env, PORT=XX. Defaults to development if none.'
9
- task :start do
10
- puts "Use: websolr start"
11
- end
12
-
13
- desc 'Stops Solr. Specify the environment by using: RAILS_ENV=your_env. Defaults to development if none.'
14
- task :stop do
15
- puts "Use: websolr stop"
16
- end
17
-
18
- # this task is by Henrik Nyh
19
- # http://henrik.nyh.se/2007/06/rake-task-to-reindex-models-for-acts_as_solr
20
- desc %{Reindexes data for all acts_as_solr models. Clears index first to get rid of orphaned records and optimizes index afterwards. RAILS_ENV=your_env to set environment. ONLY=book,person,magazine to only reindex those models; EXCEPT=book,magazine to exclude those models. START_SERVER=true to solr:start before and solr:stop after. BATCH=123 to post/commit in batches of that size: default is 300. CLEAR=false to not clear the index first; OPTIMIZE=false to not optimize the index afterwards.}
21
- task :reindex => :environment do
22
- require "#{File.dirname(__FILE__)}/../../config/solr_environment.rb"
23
-
24
- includes = env_array_to_constants('ONLY')
25
- if includes.empty?
26
- includes = Dir.glob("#{RAILS_ROOT}/app/models/*.rb").map { |path| File.basename(path, ".rb").camelize.constantize }
27
- end
28
- excludes = env_array_to_constants('EXCEPT')
29
- includes -= excludes
30
-
31
- optimize = env_to_bool('OPTIMIZE', true)
32
- start_server = env_to_bool('START_SERVER', false)
33
- clear_first = env_to_bool('CLEAR', true)
34
- batch_size = ENV['BATCH'].to_i.nonzero? || 300
35
- debug_output = env_to_bool("DEBUG", false)
36
-
37
- RAILS_DEFAULT_LOGGER.level = ActiveSupport::BufferedLogger::INFO unless debug_output
38
-
39
- if start_server
40
- puts "Starting Solr server..."
41
- Rake::Task["solr:start"].invoke
42
- end
43
-
44
- # Disable solr_optimize
45
- module ActsAsSolr::CommonMethods
46
- def blank() end
47
- alias_method :deferred_solr_optimize, :solr_optimize
48
- alias_method :solr_optimize, :blank
49
- end
50
-
51
- models = includes.select { |m| m.respond_to?(:rebuild_solr_index) }
52
- models.each do |model|
53
-
54
- if clear_first
55
- puts "Clearing index for #{model}..."
56
- ActsAsSolr::Post.execute(Solr::Request::Delete.new(:query => "#{model.solr_configuration[:type_field]}:#{model}"))
57
- ActsAsSolr::Post.execute(Solr::Request::Commit.new)
58
- end
59
-
60
- puts "Rebuilding index for #{model}..."
61
- model.rebuild_solr_index(batch_size)
62
-
63
- end
64
-
65
- if models.empty?
66
- puts "There were no models to reindex."
67
- elsif optimize
68
- puts "Optimizing..."
69
- models.last.deferred_solr_optimize
70
- end
71
-
72
- if start_server
73
- puts "Shutting down Solr server..."
74
- Rake::Task["solr:stop"].invoke
75
- end
76
-
77
- end
78
-
79
- def env_array_to_constants(env)
80
- env = ENV[env] || ''
81
- env.split(/\s*,\s*/).map { |m| m.singularize.camelize.constantize }.uniq
82
- end
83
-
84
- def env_to_bool(env, default)
85
- env = ENV[env] || ''
86
- case env
87
- when /^true$/i then true
88
- when /^false$/i then false
89
- else default
90
- end
91
- end
92
-
93
- end
94
-
data/lib/tasks/test.rake DELETED
@@ -1,7 +0,0 @@
1
- require 'active_record'
2
-
3
- namespace :test do
4
- task :migrate do
5
- ActiveRecord::Migrator.migrate("test/db/migrate/", ENV["VERSION"] ? ENV["VERSION"].to_i : nil)
6
- end
7
- end
@@ -1,233 +0,0 @@
1
- require "uri"
2
- require "rubygems"
3
- require "restclient"
4
- require 'rexml/document'
5
- require "fileutils"
6
- require "net/http"
7
- include FileUtils
8
-
9
- SOLR_PATH = "#{File.dirname(File.expand_path(__FILE__))}/../solr" unless defined? SOLR_PATH
10
- SOLR_LOGS_PATH = "#{ENV["PWD"]}/log" unless defined? SOLR_LOGS_PATH
11
- SOLR_PIDS_PATH = "#{ENV["PWD"]}/tmp/pids" unless defined? SOLR_PIDS_PATH
12
- SOLR_DATA_PATH = "#{ENV["PWD"]}/solr/#{ENV['RAILS_ENV']}" unless defined? SOLR_DATA_PATH
13
- SOLR_JVM_OPTIONS = ENV["JAVA_OPTIONS"] || "-Xmx256M"
14
-
15
- mkdir_p SOLR_PATH
16
- mkdir_p SOLR_LOGS_PATH
17
- mkdir_p SOLR_PIDS_PATH
18
- mkdir_p SOLR_DATA_PATH
19
-
20
- class WebsolrController
21
- COMMANDS = %w[add list delete configure local:start local:stop]
22
- SOLR_PORT = 8983
23
-
24
- def initialize(parser)
25
- @options = parser.options
26
- @command = @options.delete(:command)
27
- @parser = parser
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
33
- end
34
-
35
- def die(s)
36
- STDERR.puts s
37
- exit(1)
38
- end
39
-
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
51
- hash.inject(true) do |memo, (key, flag)|
52
- unless @options[key]
53
- STDERR.puts "Please use the #{flag} flag to specify the #{key}."
54
- end
55
- memo && @options[key]
56
- end || exit(1)
57
- end
58
-
59
- def url(url)
60
- URI.join(@base, url).to_s
61
- end
62
-
63
- def check_local_solr_conditions
64
- ENV["RAILS_ENV"] = @options[:rails_env] || ENV["RAILS_ENV"] || "development"
65
- begin
66
- require "config/environment"
67
- rescue LoadError
68
- die("I can't find config/environment.rb. Are we in a rails app?")
69
- end
70
-
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
92
- end
93
-
94
-
95
- uri = URI.parse(ENV["WEBSOLR_URL"])
96
- @port = uri.port
97
- rescue URI::InvalidURIError => e
98
- die(e.message)
99
- end
100
-
101
- def cmd_local_start
102
- check_local_solr_conditions
103
- begin
104
- n = Net::HTTP.new('127.0.0.1', @port)
105
- n.request_head('/').value
106
-
107
- rescue Net::HTTPServerException #responding
108
- puts "Port #{@port} in use" and return
109
-
110
- rescue Errno::ECONNREFUSED #not responding
111
- Dir.chdir(SOLR_PATH) do
112
- pid = fork do
113
- exec "java #{SOLR_JVM_OPTIONS} -Dsolr.data.dir=#{SOLR_DATA_PATH} -Djetty.logs=#{SOLR_LOGS_PATH} -Djetty.port=#{@port} -jar start.jar"
114
- end
115
- sleep(5)
116
- File.open("#{SOLR_PIDS_PATH}/#{ENV['RAILS_ENV']}_pid", "w"){ |f| f << pid}
117
- puts "#{ENV['RAILS_ENV']} Solr started successfully on #{SOLR_PORT}, pid: #{pid}."
118
- end
119
- end
120
- end
121
-
122
- def cmd_local_stop
123
- ENV["RAILS_ENV"] = @options[:rails_env] || ENV["RAILS_ENV"] || "development"
124
- fork do
125
- file_path = "#{SOLR_PIDS_PATH}/#{ENV['RAILS_ENV']}_pid"
126
- if File.exists?(file_path)
127
- File.open(file_path, "r") do |f|
128
- pid = f.readline
129
- Process.kill('TERM', pid.to_i)
130
- end
131
- File.unlink(file_path)
132
- Rake::Task["solr:destroy_index"].invoke if ENV['RAILS_ENV'] == 'test'
133
- puts "Solr shutdown successfully."
134
- else
135
- puts "PID file not found at #{file_path}. Either Solr is not running or no PID file was written."
136
- end
137
- end
138
- end
139
-
140
- def cmd_add
141
- required_options :name => "-n", :auth => true
142
- doc = post "/slices.xml", {:slice => {:name => name}}
143
- puts "#{x doc, '//name'}\t#{x doc, '//base-url'}"
144
- end
145
-
146
- def cmd_delete
147
- required_options :name => "-n", :auth => true
148
- delete "/slices/#{name}/destroy"
149
- puts "done"
150
- end
151
-
152
- def x(doc, path)
153
- REXML::XPath.first(doc, path).text
154
- end
155
-
156
- def cmd_list
157
- required_options :auth => true
158
- doc = get "/slices.xml"
159
- REXML::XPath.each(doc, "//slice") do |node|
160
- puts "#{x node, 'name'}\t#{x node, 'base-url'}"
161
- end
162
- end
163
-
164
- %w[get post delete put].each do |verb|
165
- eval <<-STR
166
- def #{verb}(url, params = {})
167
- str = RestClient.#{verb} url(url), params
168
- return nil if str.strip == ""
169
- REXML::Document.new(StringIO.new str)
170
- rescue RestClient::RequestFailed => e
171
- print_errors REXML::Document.new(StringIO.new e.response.body)
172
- end
173
- STR
174
- end
175
-
176
- def print_errors(doc)
177
- REXML::XPath.each(doc, "//error") do |node|
178
- STDERR.puts "Error: #{node.text}"
179
- end
180
- exit 1
181
- end
182
-
183
- def cmd_configure
184
- required_options :name => "-n", :auth => true
185
- doc = get "/slices.xml"
186
- found = false
187
- REXML::XPath.each(doc, "//slice") do |node|
188
- if x(node, 'name') == self.name
189
- found = true
190
- FileUtils.mkdir_p "config/initializers"
191
- path = "config/initializers/websolr.rb"
192
- puts "Writing #{path}"
193
- File.open(path, "w") do |f|
194
- str = <<-STR
195
- require 'websolr'
196
- case RAILS_ENV
197
- when 'production'
198
- ENV['WEBSOLR_URL'] ||= '#{x node, 'base-url'}'
199
- else
200
- ENV['WEBSOLR_URL'] ||= 'http://localhost:8983/solr'
201
- end
202
- STR
203
- f.puts str
204
- end
205
-
206
- FileUtils.mkdir_p "lib/tasks"
207
- path = "lib/tasks/websolr.rake"
208
- puts "Writing #{path}"
209
- File.open(path, "w") do |f|
210
- f.puts "require 'rubygems'\nrequire 'websolr_rails/tasks'"
211
- end
212
- end
213
- end
214
- unless found
215
- STDERR.puts "Error: Index not found"
216
- exit 1
217
- end
218
- end
219
-
220
- def start
221
- if(COMMANDS.include?(@command))
222
- send("cmd_#{@command.gsub(/\W+/, '_')}")
223
- else
224
- puts @parser
225
- exit(1)
226
- end
227
- end
228
-
229
- def method_missing(method, *a, &b)
230
- return @options[method] if @options[method]
231
- super(method, *a, &b)
232
- end
233
- end
@@ -1,61 +0,0 @@
1
- require 'optparse'
2
-
3
- class WebsolrOptionParser < OptionParser
4
- attr_accessor :options
5
-
6
- def usage
7
- "Usage: #{$0} COMMAND [INDEX_NAME] [options]
8
-
9
- COMMANDs:
10
- local:start - starts the local development server
11
- local:stop - stops the local development server
12
-
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
-
18
- "
19
- end
20
-
21
- def parse!
22
- super
23
- self.options[:command] = ARGV[0]
24
- self.options[:name] ||= ARGV[1]
25
- end
26
-
27
- def initialize
28
- self.options = {}
29
- super do |opts|
30
-
31
- yield opts if block_given?
32
-
33
- opts.banner = usage
34
-
35
- opts.on("-u", "--user=USER", "Your Websolr username") do |u|
36
- options[:user] = u
37
- end
38
-
39
- opts.on("-p", "--password=PASSWORD", "Your Websolr password") do |p|
40
- options[:pass] = p
41
- end
42
-
43
- opts.on("-n", "--name=NAME", "Name of the index") do |p|
44
- options[:name] = p
45
- end
46
-
47
- opts.on("-e", "--rails-env=ENV", "RAILS_ENV") do |p|
48
- options[:rails_env] = p
49
- end
50
-
51
- opts.on("-i", "--invitation=CODE", "Your invitation code") do |p|
52
- options[:invitation_code] = p
53
- end
54
-
55
- opts.on_tail("-h", "--help", "Show this message") do
56
- puts opts
57
- exit
58
- end
59
- end
60
- end
61
- end