erichummel-sunspot_rails 1.2.1a → 1.2.1b

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,3 @@
1
- require 'erb'
2
-
3
1
  module Sunspot #:nodoc:
4
2
  module Rails #:nodoc:
5
3
  #
@@ -195,10 +193,9 @@ module Sunspot #:nodoc:
195
193
  @data_path ||= user_configuration_from_key('solr', 'data_path') || File.join(::Rails.root, 'solr', 'data', ::Rails.env)
196
194
  end
197
195
 
198
- def pid_dir
199
- @pid_dir ||= user_configuration_from_key('solr', 'pid_dir') || File.join(::Rails.root, 'solr', 'pids', ::Rails.env)
196
+ def pid_path
197
+ @pids_path ||= user_configuration_from_key('solr', 'pid_path') || File.join(::Rails.root, 'solr', 'pids', ::Rails.env)
200
198
  end
201
-
202
199
 
203
200
  #
204
201
  # The solr home directory. Sunspot::Rails expects this directory
@@ -280,8 +277,7 @@ module Sunspot #:nodoc:
280
277
  path = File.join(::Rails.root, 'config', 'sunspot.yml')
281
278
  if File.exist?(path)
282
279
  File.open(path) do |file|
283
- processed = ERB.new(file.read).result
284
- YAML.load(processed)[::Rails.env]
280
+ YAML.load(file)[::Rails.env]
285
281
  end
286
282
  else
287
283
  {}
@@ -11,16 +11,6 @@ module Sunspot
11
11
  ActiveSupport.on_load(:action_controller) do
12
12
  include(Sunspot::Rails::RequestLifecycle)
13
13
  end
14
- require 'sunspot/rails/log_subscriber'
15
- RSolr::Client.module_eval{ include Sunspot::Rails::SolrInstrumentation }
16
- end
17
-
18
- # Expose database runtime to controller for logging.
19
- initializer "sunspot_rails.log_runtime" do |app|
20
- require "sunspot/rails/railties/controller_runtime"
21
- ActiveSupport.on_load(:action_controller) do
22
- include Sunspot::Rails::Railties::ControllerRuntime
23
- end
24
14
  end
25
15
 
26
16
  rake_tasks do
@@ -67,8 +67,8 @@ module Sunspot #:nodoc:
67
67
  extend ClassMethods
68
68
  include InstanceMethods
69
69
 
70
- class_attribute :sunspot_options
71
-
70
+ class_inheritable_hash :sunspot_options
71
+
72
72
  unless options[:auto_index] == false
73
73
  before_save :maybe_mark_for_auto_indexing
74
74
  after_save :maybe_auto_index
@@ -41,7 +41,7 @@ module Sunspot
41
41
  # Directory in which to store PID files
42
42
  #
43
43
  def pid_dir
44
- configuration.pid_dir || File.join(::Rails.root, 'tmp', 'pids')
44
+ File.join(::Rails.root, 'tmp', 'pids')
45
45
  end
46
46
 
47
47
  #
@@ -38,7 +38,7 @@ namespace :sunspot do
38
38
  # $ rake sunspot:reindex[1000,Post] # reindex only the Post model in
39
39
  # # batchs of 1000
40
40
  # $ rake sunspot:reindex[,Post+Author] # reindex Post and Author model
41
- task :reindex, [:batch_size, :models] => [:environment] do |t, args|
41
+ task :reindex, :batch_size, :models, :needs => :environment do |t, args|
42
42
  reindex_options = {:batch_commit => false}
43
43
  case args[:batch_size]
44
44
  when 'false'
@@ -47,9 +47,8 @@ namespace :sunspot do
47
47
  reindex_options[:batch_size] = args[:batch_size].to_i if args[:batch_size].to_i > 0
48
48
  end
49
49
  unless args[:models]
50
- models_path = Rails.root.join('app', 'models')
51
- all_files = Dir.glob(models_path.join('**', '*.rb'))
52
- all_models = all_files.map { |path| path.sub(models_path.to_s, '')[0..-4].camelize.sub(/^::/, '').constantize rescue nil }.compact
50
+ all_files = Dir.glob(Rails.root.join('app', 'models', '*.rb'))
51
+ all_models = all_files.map { |path| File.basename(path, '.rb').camelize.constantize }
53
52
  sunspot_models = all_models.select { |m| m < ActiveRecord::Base and m.searchable? }
54
53
  else
55
54
  sunspot_models = args[:models].split('+').map{|m| m.constantize}
data/lib/sunspot/rails.rb CHANGED
@@ -6,7 +6,6 @@ require File.join(File.dirname(__FILE__), 'rails', 'searchable')
6
6
 
7
7
  module Sunspot #:nodoc:
8
8
  module Rails #:nodoc:
9
- autoload :SolrInstrumentation, File.join(File.dirname(__FILE__), 'rails', 'solr_instrumentation')
10
9
  autoload :StubSessionProxy, File.join(File.dirname(__FILE__), 'rails', 'stub_session_proxy')
11
10
  autoload :Server, File.join(File.dirname(__FILE__), 'rails', 'server')
12
11
  autoload :VERSION, File.join(File.dirname(__FILE__), 'rails', 'version')
@@ -48,9 +47,9 @@ module Sunspot #:nodoc:
48
47
  def slave_config(sunspot_rails_configuration)
49
48
  config = Sunspot::Configuration.build
50
49
  config.solr.url = URI::HTTP.build(
51
- :host => sunspot_rails_configuration.hostname,
52
- :port => sunspot_rails_configuration.port,
53
- :path => sunspot_rails_configuration.path
50
+ :host => configuration.hostname,
51
+ :port => configuration.port,
52
+ :path => configuration.path
54
53
  ).to_s
55
54
  config
56
55
  end
data/lib/sunspot_rails.rb CHANGED
@@ -1,8 +1,3 @@
1
- # This needs to be loaded before sunspot/search/paginated_collection
2
- # or #to_json gets defined in Object breaking delegation to Array via
3
- # method_missing
4
- require 'active_support/core_ext/object/to_json' if Rails::VERSION::MAJOR == 3
5
-
6
1
  require 'sunspot/rails'
7
2
 
8
3
  if Rails::VERSION::MAJOR == 3
@@ -55,9 +55,9 @@ describe Sunspot::Rails::Configuration, "default values without a sunspot.yml" d
55
55
  @config.data_path.should == '/some/path/solr/data/test'
56
56
  end
57
57
 
58
- it "should handle the 'pid_dir' property when not set" do
58
+ it "should handle the 'pid_path' property when not set" do
59
59
  Rails.should_receive(:root).at_least(1).and_return('/some/path')
60
- @config.pid_dir.should == '/some/path/solr/pids/test'
60
+ @config.pid_path.should == '/some/path/solr/pids/test'
61
61
  end
62
62
 
63
63
  it "should handle the 'auto_commit_after_request' propery when not set" do
@@ -99,8 +99,8 @@ describe Sunspot::Rails::Configuration, "user provided sunspot.yml" do
99
99
  @config.data_path.should == '/my_superior_path/data'
100
100
  end
101
101
 
102
- it "should handle the 'pid_dir' property when set" do
103
- @config.pid_dir.should == '/my_superior_path/pids'
102
+ it "should handle the 'pid_path' property when set" do
103
+ @config.pid_path.should == '/my_superior_path/pids'
104
104
  end
105
105
 
106
106
  it "should handle the 'solr_home' property when set" do
data/spec/server_spec.rb CHANGED
@@ -16,7 +16,7 @@ describe Sunspot::Rails::Server do
16
16
  end
17
17
 
18
18
  it "sets the correct Solr PID path" do
19
- @server.pid_path.should == File.join(@server.pid_dir, 'sunspot-solr-test.pid')
19
+ @server.pid_path.should == File.join(Rails.root, 'tmp', 'pids', 'sunspot-solr-test.pid')
20
20
  end
21
21
 
22
22
  it "sets the correct Solr data dir" do
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: erichummel-sunspot_rails
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease: 5
5
- version: 1.2.1a
5
+ version: 1.2.1b
6
6
  platform: ruby
7
7
  authors:
8
8
  - Mat Brown
@@ -21,7 +21,7 @@ cert_chain: []
21
21
  date: 2011-08-17 00:00:00 Z
22
22
  dependencies:
23
23
  - !ruby/object:Gem::Dependency
24
- name: erichummel-sunspot
24
+ name: sunspot
25
25
  prerelease: false
26
26
  requirement: &id001 !ruby/object:Gem::Requirement
27
27
  none: false
@@ -94,13 +94,10 @@ files:
94
94
  - lib/sunspot/rails/adapters.rb
95
95
  - lib/sunspot/rails/configuration.rb
96
96
  - lib/sunspot/rails/init.rb
97
- - lib/sunspot/rails/log_subscriber.rb
98
97
  - lib/sunspot/rails/railtie.rb
99
- - lib/sunspot/rails/railties/controller_runtime.rb
100
98
  - lib/sunspot/rails/request_lifecycle.rb
101
99
  - lib/sunspot/rails/searchable.rb
102
100
  - lib/sunspot/rails/server.rb
103
- - lib/sunspot/rails/solr_instrumentation.rb
104
101
  - lib/sunspot/rails/solr_logging.rb
105
102
  - lib/sunspot/rails/spec_helper.rb
106
103
  - lib/sunspot/rails/stub_session_proxy.rb
@@ -1,33 +0,0 @@
1
- module Sunspot
2
- module Rails
3
- class LogSubscriber < ActiveSupport::LogSubscriber
4
- def self.runtime=(value)
5
- Thread.current["sorl_runtime"] = value
6
- end
7
-
8
- def self.runtime
9
- Thread.current["sorl_runtime"] ||= 0
10
- end
11
-
12
- def self.reset_runtime
13
- rt, self.runtime = runtime, 0
14
- rt
15
- end
16
-
17
- def request(event)
18
- self.class.runtime += event.duration
19
- return unless logger.debug?
20
-
21
- name = '%s (%.1fms)' % ["SOLR Request", event.duration]
22
-
23
- # produces: path=/select parameters={fq: ["type:Tag"], q: rossi, fl: * score, qf: tag_name_text, defType: dismax, start: 0, rows: 20}
24
- parameters = event.payload[:parameters].map { |k, v| "#{k}: #{color(v, BOLD, true)}" }.join(', ')
25
- request = "path=#{event.payload[:path]} parameters={#{parameters}}"
26
-
27
- debug " #{color(name, GREEN, true)} [ #{request} ]"
28
- end
29
- end
30
- end
31
- end
32
-
33
- Sunspot::Rails::LogSubscriber.attach_to :rsolr
@@ -1,36 +0,0 @@
1
- module Sunspot
2
- module Rails
3
- module Railties
4
- module ControllerRuntime
5
- extend ActiveSupport::Concern
6
-
7
- protected
8
-
9
- attr_internal :solr_runtime
10
-
11
- def cleanup_view_runtime
12
- # TODO only if solr is connected? if not call to super
13
-
14
- solr_rt_before_render = Sunspot::Rails::LogSubscriber.reset_runtime
15
- runtime = super
16
- solr_rt_after_render = Sunspot::Rails::LogSubscriber.reset_runtime
17
- self.solr_runtime = solr_rt_before_render + solr_rt_after_render
18
- runtime - solr_rt_after_render
19
- end
20
-
21
- def append_info_to_payload(payload)
22
- super
23
- payload[:solr_runtime] = solr_runtime
24
- end
25
-
26
- module ClassMethods
27
- def log_process_action(payload)
28
- messages, solr_runtime = super, payload[:solr_runtime]
29
- messages << ("Solr: %.1fms" % solr_runtime.to_f) if solr_runtime
30
- messages
31
- end
32
- end
33
- end
34
- end
35
- end
36
- end
@@ -1,21 +0,0 @@
1
- module Sunspot
2
- module Rails
3
- module SolrInstrumentation
4
- extend ActiveSupport::Concern
5
-
6
- included do
7
- alias_method :request_without_as_instrumentation, :request
8
- alias_method :request, :request_with_as_instrumentation
9
- end
10
-
11
- module InstanceMethods
12
- def request_with_as_instrumentation(path, params={}, *extra)
13
- ActiveSupport::Notifications.instrument("request.rsolr",
14
- {:path => path, :parameters => params}) do
15
- request_without_as_instrumentation(path, params, *extra)
16
- end
17
- end
18
- end
19
- end
20
- end
21
- end