websolr-rails 2.2.0 → 2.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.2.0
1
+ 2.3.0
data/lib/websolr-rails.rb CHANGED
@@ -6,6 +6,8 @@ if ENV["WEBSOLR_URL"]
6
6
 
7
7
  begin
8
8
  require "sunspot/rails/configuration"
9
+ require "sunspot/rails/searchable"
10
+ require "sunspot/rails/request_lifecycle"
9
11
  module Sunspot #:nodoc:
10
12
  module Rails #:nodoc:
11
13
  class Configuration
@@ -21,6 +23,60 @@ if ENV["WEBSOLR_URL"]
21
23
  end
22
24
  end
23
25
  end
26
+
27
+ module Sunspot #:nodoc:
28
+ module Rails #:nodoc:
29
+ #
30
+ # This module adds an after_filter to ActionController::Base that commits
31
+ # the Sunspot session if any documents have been added, changed, or removed
32
+ # in the course of the request.
33
+ #
34
+ module RequestLifecycle
35
+ class <<self
36
+ def included(base) #:nodoc:
37
+ base.after_filter do
38
+ begin
39
+ if Sunspot::Rails.configuration.auto_commit_after_request?
40
+ Sunspot::Rails.master_session.commit_if_dirty
41
+ elsif Sunspot::Rails.configuration.auto_commit_after_delete_request?
42
+ Sunspot::Rails.master_session.commit_if_delete_dirty
43
+ end
44
+ rescue Exception => e
45
+ ActionController::Base.logger.error e.message
46
+ ActionController::Base.logger.error e.backtrace.join("\n")
47
+ false
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
55
+
56
+
57
+ module Sunspot
58
+ module Rails
59
+ module Searchable
60
+ module InstanceMethods
61
+ %w[index index! remove_from_index remove_from_index!].each do |method|
62
+ new_name = method =~ /!/ ? method.gsub("!", "") + "_with_caught_errors!" : "#{method}_with_caught_errors"
63
+ old_name = new_name.sub("_with_", "_without_")
64
+ define_method(new_name) do
65
+ begin
66
+ send(old_name)
67
+ rescue Exception => e
68
+ logger.error e.message
69
+ logger.error e.backtrace.join("\n")
70
+ false
71
+ end
72
+ end
73
+ alias_method_chain method, :caught_errors
74
+ end
75
+ end
76
+ end
77
+ end
78
+ end
79
+
24
80
  rescue LoadError
25
81
  #ignore
26
82
  end
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{websolr-rails}
8
- s.version = "2.2.0"
8
+ s.version = "2.3.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"]
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.2.0
4
+ version: 2.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kyle Maxwell