websolr-sunspot_rails 1.1.0.1 → 1.1.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.1.0.1
1
+ 1.1.0.2
@@ -90,27 +90,46 @@ if ENV["WEBSOLR_URL"]
90
90
  end
91
91
  end
92
92
 
93
- # This code makes saves go though even though solr is down.
94
- module Sunspot
95
- module Rails
96
- module Searchable
97
- module InstanceMethods
98
- %w[solr_index solr_index! solr_remove_from_index solr_remove_from_index!].each do |method|
99
- new_name = method =~ /!/ ? method.gsub("!", "") + "_with_caught_errors!" : "#{method}_with_caught_errors"
100
- old_name = new_name.sub("_with_", "_without_")
101
- define_method(new_name) do
102
- begin
103
- send(old_name)
104
- rescue Exception => e
105
- logger.error e.message
106
- logger.error e.backtrace.join("\n")
107
- false
108
- end
109
- end
110
- alias_method_chain method, :caught_errors
93
+ #
94
+ # Silently fail instead of raising an exception when an error occurs while writing to Solr.
95
+ # NOTE: does not fail for reads; you should catch those exceptions, for example in a rescue_from statement.
96
+ #
97
+ require 'sunspot/session_proxy/abstract_session_proxy'
98
+ class WebsolrSilentFailSessionProxy < Sunspot::SessionProxy::AbstractSessionProxy
99
+ attr_reader :search_session
100
+
101
+ delegate :new_search, :search, :config,
102
+ :new_more_like_this, :more_like_this,
103
+ :delete_dirty, :delete_dirty?,
104
+ :to => :search_session
105
+
106
+ def initialize(search_session = Sunspot.session)
107
+ @search_session = search_session
108
+ end
109
+
110
+ def rescued_exception(method, e)
111
+ $stderr.puts("Exception in #{method}: #{e.message}")
112
+ end
113
+
114
+ SUPPORTED_METHODS = [
115
+ :batch, :commit, :commit_if_dirty, :commit_if_delete_dirty, :dirty?,
116
+ :index!, :index, :remove!, :remove, :remove_all!, :remove_all,
117
+ :remove_by_id!, :remove_by_id
118
+ ]
119
+
120
+ SUPPORTED_METHODS.each do |method|
121
+ module_eval(<<-RUBY)
122
+ def #{method}(*args, &block)
123
+ begin
124
+ search_session.#{method}(*args, &block)
125
+ rescue => e
126
+ self.rescued_exception(:#{method}, e)
111
127
  end
112
128
  end
113
- end
129
+ RUBY
114
130
  end
115
- end
131
+ end
132
+
133
+ Sunspot.session = WebsolrSilentFailSessionProxy.new(Sunspot.session)
134
+
116
135
  end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{websolr-sunspot_rails}
8
- s.version = "1.1.0.1"
8
+ s.version = "1.1.0.2"
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", "John Barnette", "Mat Brown", "Nick Zadrozny"]
12
- s.date = %q{2010-05-27}
12
+ s.date = %q{2010-06-15}
13
13
  s.description = %q{websolr to sunspot_rails shim}
14
14
  s.email = %q{kyle@kylemaxwell.com}
15
15
  s.extra_rdoc_files = [
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: websolr-sunspot_rails
3
3
  version: !ruby/object:Gem::Version
4
- hash: 85
4
+ hash: 83
5
5
  prerelease: false
6
6
  segments:
7
7
  - 1
8
8
  - 1
9
9
  - 0
10
- - 1
11
- version: 1.1.0.1
10
+ - 2
11
+ version: 1.1.0.2
12
12
  platform: ruby
13
13
  authors:
14
14
  - Kyle Maxwell
@@ -19,7 +19,7 @@ autorequire:
19
19
  bindir: bin
20
20
  cert_chain: []
21
21
 
22
- date: 2010-05-27 00:00:00 -07:00
22
+ date: 2010-06-15 00:00:00 -07:00
23
23
  default_executable:
24
24
  dependencies:
25
25
  - !ruby/object:Gem::Dependency