Permalink
Browse files

use Rails.root and Rails.env

  • Loading branch information...
1 parent 3a2eb6f commit 19c48137746f18a5c92f5179eea4c6d3d8c335e7 @dcrec1 dcrec1 committed May 19, 2010
Showing with 206 additions and 237 deletions.
  1. +10 −41 lib/acts_as_solr.rb
  2. +196 −196 test/unit/parser_methods_shoulda.rb
View
@@ -1,23 +1,3 @@
-# Copyright (c) 2006 Erik Hatcher, Thiago Jackiw
-#
-# Permission is hereby granted, free of charge, to any person obtaining a copy
-# of this software and associated documentation files (the "Software"), to deal
-# in the Software without restriction, including without limitation the rights
-# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-# copies of the Software, and to permit persons to whom the Software is
-# furnished to do so, subject to the following conditions:
-#
-# The above copyright notice and this permission notice shall be included in all
-# copies or substantial portions of the Software.
-#
-# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
-# SOFTWARE.
-
require 'active_record'
require 'rexml/document'
require 'net/http'
@@ -39,32 +19,21 @@
require File.dirname(__FILE__) + '/acts_as_solr/search_results'
require File.dirname(__FILE__) + '/acts_as_solr/lazy_document'
require File.dirname(__FILE__) + '/acts_as_solr/mongo_mapper'
+
module ActsAsSolr
-
+
class Post
def self.execute(request, core = nil)
- begin
- if File.exists?(RAILS_ROOT+'/config/solr.yml')
- config = YAML::load_file(RAILS_ROOT+'/config/solr.yml')
- url = config[ENV['RAILS_ENV']]['url']
- # for backwards compatibility
- url ||= "http://#{config[ENV['RAILS_ENV']]['host']}:#{config[ENV['RAILS_ENV']]['port']}/#{config[ENV['RAILS_ENV']]['servlet_path']}"
- else
- url = 'http://localhost:8982/solr'
- end
- url += "/" + core if !core.nil?
- connection = Solr::Connection.new(url,
- :username=>config[ENV['RAILS_ENV']]['username'],
- :password=>config[ENV['RAILS_ENV']]['password'])
- return connection.send(request)
- rescue
- raise "Couldn't connect to the Solr server at #{url}. #{$!}"
- false
- end
+ config_file_path = File.join(Rails.root, '/config/solr.yml')
+ config = YAML::load_file(config_file_path)[Rails.env]
+ url = config['url'] + (core.nil? ? '' : "/#{core}")
+ connection = Solr::Connection.new(url,
+ :username => config['username'],
+ :password => config['password'])
+ connection.send request
end
end
-
end
# reopen ActiveRecord and include the acts_as_solr method
-ActiveRecord::Base.extend ActsAsSolr::ActsMethods
+ActiveRecord::Base.extend ActsAsSolr::ActsMethods
Oops, something went wrong.

0 comments on commit 19c4813

Please sign in to comment.