Permalink
Browse files

Can be used for non Rails apps

Signed-off-by: Laurent Arnoud <larnoud@af83.com>
  • Loading branch information...
1 parent 371f19e commit 087df42b2f846d4f5c9d276fda3f7c84b5dcd52d Laurent Arnoud committed Mar 16, 2011
Showing with 27 additions and 12 deletions.
  1. +2 −2 lib/mongoid_sphinx.rb
  2. +20 −9 lib/mongoid_sphinx/configuration.rb
  3. +5 −1 lib/mongoid_sphinx/index.rb
View
@@ -6,7 +6,7 @@
require 'mongoid_sphinx/index'
require 'mongoid_sphinx/mongoid/identity'
require 'mongoid_sphinx/mongoid/sphinx'
-require 'mongoid_sphinx/railtie'
+require 'mongoid_sphinx/railtie' if defined?(Rails)
module MongoidSphinx
@@ -52,4 +52,4 @@ def self.sphinx_pid
end
end
-end
+end
@@ -24,17 +24,18 @@ class Configuration
attr_accessor :configuration, :controller
def initialize
+ init_root_env
@configuration = Riddle::Configuration.new
- @configuration.searchd.pid_file = "#{Rails.root}/log/searchd.#{Rails.env}.pid"
- @configuration.searchd.log = "#{Rails.root}/log/searchd.log"
- @configuration.searchd.query_log = "#{Rails.root}/log/searchd.query.log"
+ @configuration.searchd.pid_file = "#{@root}/log/searchd.#{@env}.pid"
+ @configuration.searchd.log = "#{@root}/log/searchd.log"
+ @configuration.searchd.query_log = "#{@root}/log/searchd.query.log"
- @controller = Riddle::Controller.new @configuration, "#{Rails.root}/config/#{Rails.env}.sphinx.conf"
+ @controller = Riddle::Controller.new @configuration, "#{@root}/config/#{@env}.sphinx.conf"
self.address = "127.0.0.1"
self.port = 9312
- self.searchd_file_path = "#{Rails.root}/db/sphinx/#{Rails.env}"
- self.model_directories = ["#{Rails.root}/app/models/"] + Dir.glob("#{Rails.root}/vendor/plugins/*/app/models/")
+ self.searchd_file_path = "#{@root}/db/sphinx/#{@env}"
+ self.model_directories = ["#{@root}/app/models/"] + Dir.glob("#{@root}/vendor/plugins/*/app/models/")
self.indexed_models = []
self.source_options = {
@@ -156,15 +157,25 @@ def indexer_binary_name=(name)
private
def parse_config
- path = "#{Rails.root}/config/sphinx.yml"
+ path = "#{@root}/config/sphinx.yml"
return unless File.exists?(path)
- conf = YAML::load(ERB.new(IO.read(path)).result)[Rails.env]
+ conf = YAML::load(ERB.new(IO.read(path)).result)[@env]
conf.each do |key,value|
self.send("#{key}=", value) if self.respond_to?("#{key}=")
end
end
+ def init_root_env
+ if defined?(Rails)
+ @root = Rails.root
+ @env = Rails.env
+ else
+ @root = Dir.pwd
+ @env = ENV['RACK_ENV'] || 'development'
+ end
+ end
+
end
-end
+end
@@ -7,7 +7,11 @@ def initialize(model)
@model = model
@options = model.index_options
@source = Riddle::Configuration::XMLSource.new( "#{core_name}_0", config.source_options[:type])
- @source.xmlpipe_command = "RAILS_ENV=#{Rails.env} script/rails runner '#{model.to_s}.sphinx_stream'"
+ if defined?(Rails)
+ @source.xmlpipe_command = "RAILS_ENV=#{Rails.env} script/rails runner '#{model.to_s}.sphinx_stream'"
+ else
+ @source.xmlpipe_command = "script/runner '#{model.to_s}.sphinx_stream'"
+ end
end
def core_name

0 comments on commit 087df42

Please sign in to comment.