ebeigarts-thinking-sphinx 1.1.21

Sign up to get free protection for your applications and to get access to all the features.
Files changed (91) hide show
  1. data/LICENCE +20 -0
  2. data/README.textile +143 -0
  3. data/lib/thinking_sphinx.rb +217 -0
  4. data/lib/thinking_sphinx/active_record.rb +278 -0
  5. data/lib/thinking_sphinx/active_record/attribute_updates.rb +48 -0
  6. data/lib/thinking_sphinx/active_record/delta.rb +87 -0
  7. data/lib/thinking_sphinx/active_record/has_many_association.rb +29 -0
  8. data/lib/thinking_sphinx/active_record/search.rb +57 -0
  9. data/lib/thinking_sphinx/adapters/abstract_adapter.rb +53 -0
  10. data/lib/thinking_sphinx/adapters/mysql_adapter.rb +54 -0
  11. data/lib/thinking_sphinx/adapters/postgresql_adapter.rb +135 -0
  12. data/lib/thinking_sphinx/association.rb +164 -0
  13. data/lib/thinking_sphinx/attribute.rb +269 -0
  14. data/lib/thinking_sphinx/class_facet.rb +15 -0
  15. data/lib/thinking_sphinx/collection.rb +148 -0
  16. data/lib/thinking_sphinx/configuration.rb +275 -0
  17. data/lib/thinking_sphinx/core/string.rb +15 -0
  18. data/lib/thinking_sphinx/deltas.rb +30 -0
  19. data/lib/thinking_sphinx/deltas/datetime_delta.rb +50 -0
  20. data/lib/thinking_sphinx/deltas/default_delta.rb +68 -0
  21. data/lib/thinking_sphinx/deltas/delayed_delta.rb +27 -0
  22. data/lib/thinking_sphinx/deltas/delayed_delta/delta_job.rb +24 -0
  23. data/lib/thinking_sphinx/deltas/delayed_delta/flag_as_deleted_job.rb +27 -0
  24. data/lib/thinking_sphinx/deltas/delayed_delta/job.rb +26 -0
  25. data/lib/thinking_sphinx/deploy/capistrano.rb +82 -0
  26. data/lib/thinking_sphinx/facet.rb +108 -0
  27. data/lib/thinking_sphinx/facet_collection.rb +59 -0
  28. data/lib/thinking_sphinx/field.rb +82 -0
  29. data/lib/thinking_sphinx/index.rb +99 -0
  30. data/lib/thinking_sphinx/index/builder.rb +287 -0
  31. data/lib/thinking_sphinx/index/faux_column.rb +110 -0
  32. data/lib/thinking_sphinx/property.rb +160 -0
  33. data/lib/thinking_sphinx/rails_additions.rb +136 -0
  34. data/lib/thinking_sphinx/search.rb +727 -0
  35. data/lib/thinking_sphinx/search/facets.rb +104 -0
  36. data/lib/thinking_sphinx/source.rb +175 -0
  37. data/lib/thinking_sphinx/source/internal_properties.rb +46 -0
  38. data/lib/thinking_sphinx/source/sql.rb +126 -0
  39. data/lib/thinking_sphinx/tasks.rb +245 -0
  40. data/rails/init.rb +14 -0
  41. data/spec/unit/thinking_sphinx/active_record/delta_spec.rb +136 -0
  42. data/spec/unit/thinking_sphinx/active_record/has_many_association_spec.rb +53 -0
  43. data/spec/unit/thinking_sphinx/active_record/search_spec.rb +107 -0
  44. data/spec/unit/thinking_sphinx/active_record_spec.rb +329 -0
  45. data/spec/unit/thinking_sphinx/association_spec.rb +246 -0
  46. data/spec/unit/thinking_sphinx/attribute_spec.rb +338 -0
  47. data/spec/unit/thinking_sphinx/collection_spec.rb +15 -0
  48. data/spec/unit/thinking_sphinx/configuration_spec.rb +222 -0
  49. data/spec/unit/thinking_sphinx/core/string_spec.rb +9 -0
  50. data/spec/unit/thinking_sphinx/facet_collection_spec.rb +64 -0
  51. data/spec/unit/thinking_sphinx/facet_spec.rb +302 -0
  52. data/spec/unit/thinking_sphinx/field_spec.rb +154 -0
  53. data/spec/unit/thinking_sphinx/index/builder_spec.rb +355 -0
  54. data/spec/unit/thinking_sphinx/index/faux_column_spec.rb +30 -0
  55. data/spec/unit/thinking_sphinx/index_spec.rb +45 -0
  56. data/spec/unit/thinking_sphinx/rails_additions_spec.rb +191 -0
  57. data/spec/unit/thinking_sphinx/search_spec.rb +228 -0
  58. data/spec/unit/thinking_sphinx/source_spec.rb +217 -0
  59. data/spec/unit/thinking_sphinx_spec.rb +151 -0
  60. data/tasks/distribution.rb +67 -0
  61. data/tasks/rails.rake +1 -0
  62. data/tasks/testing.rb +100 -0
  63. data/vendor/after_commit/LICENSE +20 -0
  64. data/vendor/after_commit/README +16 -0
  65. data/vendor/after_commit/Rakefile +22 -0
  66. data/vendor/after_commit/init.rb +8 -0
  67. data/vendor/after_commit/lib/after_commit.rb +45 -0
  68. data/vendor/after_commit/lib/after_commit/active_record.rb +114 -0
  69. data/vendor/after_commit/lib/after_commit/connection_adapters.rb +103 -0
  70. data/vendor/after_commit/test/after_commit_test.rb +53 -0
  71. data/vendor/delayed_job/lib/delayed/job.rb +251 -0
  72. data/vendor/delayed_job/lib/delayed/message_sending.rb +7 -0
  73. data/vendor/delayed_job/lib/delayed/performable_method.rb +55 -0
  74. data/vendor/delayed_job/lib/delayed/worker.rb +54 -0
  75. data/vendor/riddle/lib/riddle.rb +30 -0
  76. data/vendor/riddle/lib/riddle/client.rb +619 -0
  77. data/vendor/riddle/lib/riddle/client/filter.rb +53 -0
  78. data/vendor/riddle/lib/riddle/client/message.rb +65 -0
  79. data/vendor/riddle/lib/riddle/client/response.rb +84 -0
  80. data/vendor/riddle/lib/riddle/configuration.rb +33 -0
  81. data/vendor/riddle/lib/riddle/configuration/distributed_index.rb +48 -0
  82. data/vendor/riddle/lib/riddle/configuration/index.rb +142 -0
  83. data/vendor/riddle/lib/riddle/configuration/indexer.rb +19 -0
  84. data/vendor/riddle/lib/riddle/configuration/remote_index.rb +17 -0
  85. data/vendor/riddle/lib/riddle/configuration/searchd.rb +25 -0
  86. data/vendor/riddle/lib/riddle/configuration/section.rb +43 -0
  87. data/vendor/riddle/lib/riddle/configuration/source.rb +23 -0
  88. data/vendor/riddle/lib/riddle/configuration/sql_source.rb +34 -0
  89. data/vendor/riddle/lib/riddle/configuration/xml_source.rb +28 -0
  90. data/vendor/riddle/lib/riddle/controller.rb +44 -0
  91. metadata +191 -0
@@ -0,0 +1,67 @@
1
+ require 'rake/rdoctask'
2
+ require 'rake/gempackagetask'
3
+
4
+ $LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
5
+ require 'thinking_sphinx'
6
+
7
+ desc 'Generate documentation'
8
+ Rake::RDocTask.new(:rdoc) do |rdoc|
9
+ rdoc.rdoc_dir = 'rdoc'
10
+ rdoc.title = 'Thinking Sphinx - ActiveRecord Sphinx Plugin'
11
+ rdoc.options << '--line-numbers' << '--inline-source'
12
+ rdoc.rdoc_files.include('README')
13
+ rdoc.rdoc_files.include('lib/**/*.rb')
14
+ end
15
+
16
+ spec = Gem::Specification.new do |s|
17
+ s.name = "thinking-sphinx"
18
+ s.version = ThinkingSphinx::Version::String
19
+ s.summary = "A concise and easy-to-use Ruby library that connects ActiveRecord to the Sphinx search daemon, managing configuration, indexing and searching."
20
+ s.description = "A concise and easy-to-use Ruby library that connects ActiveRecord to the Sphinx search daemon, managing configuration, indexing and searching."
21
+ s.author = "Pat Allan"
22
+ s.email = "pat@freelancing-gods.com"
23
+ s.homepage = "http://ts.freelancing-gods.com"
24
+ s.has_rdoc = true
25
+ s.rdoc_options << "--title" << "Thinking Sphinx -- Rails/Merb Sphinx Plugin" <<
26
+ "--line-numbers"
27
+ s.rubyforge_project = "thinking-sphinx"
28
+ s.test_files = FileList["spec/**/*_spec.rb"]
29
+ s.files = FileList[
30
+ "rails/*.rb",
31
+ "lib/**/*.rb",
32
+ "LICENCE",
33
+ "README.textile",
34
+ "tasks/**/*.rb",
35
+ "tasks/**/*.rake",
36
+ "vendor/**/*"
37
+ ]
38
+ s.post_install_message = <<-MESSAGE
39
+ With the release of Thinking Sphinx 1.1.18, there is one important change to
40
+ note: previously, the default morphology for indexing was 'stem_en'. The new
41
+ default is nil, to avoid any unexpected behavior. If you wish to keep the old
42
+ value though, you will need to add the following settings to your
43
+ config/sphinx.yml file:
44
+
45
+ development:
46
+ morphology: stem_en
47
+ test:
48
+ morphology: stem_en
49
+ production:
50
+ morphology: stem_en
51
+
52
+ To understand morphologies/stemmers better, visit the following link:
53
+ http://www.sphinxsearch.com/docs/manual-0.9.8.html#conf-morphology
54
+
55
+ MESSAGE
56
+ end
57
+
58
+ Rake::GemPackageTask.new(spec) do |p|
59
+ p.gem_spec = spec
60
+ p.need_tar = true
61
+ p.need_zip = true
62
+ end
63
+
64
+ desc "Build gemspec file"
65
+ task :build do
66
+ File.open('thinking-sphinx.gemspec', 'w') { |f| f.write spec.to_ruby }
67
+ end
data/tasks/rails.rake ADDED
@@ -0,0 +1 @@
1
+ require File.join(File.dirname(__FILE__), '/../lib/thinking_sphinx/tasks')
data/tasks/testing.rb ADDED
@@ -0,0 +1,100 @@
1
+ require 'rubygems'
2
+ require 'spec/rake/spectask'
3
+ require 'cucumber/rake/task'
4
+
5
+ desc "Run the specs under spec"
6
+ Spec::Rake::SpecTask.new do |t|
7
+ t.spec_files = FileList['spec/**/*_spec.rb']
8
+ t.spec_opts << "-c"
9
+ end
10
+
11
+ desc "Run all feature-set configurations"
12
+ task :features do |t|
13
+ puts "rake features:mysql"
14
+ system "rake features:mysql"
15
+ puts "rake features:postgresql"
16
+ system "rake features:postgresql"
17
+ end
18
+
19
+ namespace :features do
20
+ def add_task(name, description)
21
+ Cucumber::Rake::Task.new(name, description) do |t|
22
+ t.cucumber_opts = "--format pretty"
23
+ t.profile = name
24
+ end
25
+ end
26
+
27
+ add_task :mysql, "Run feature-set against MySQL"
28
+ add_task :postgresql, "Run feature-set against PostgreSQL"
29
+ add_task :oracle, "Run feature-set against Oracle"
30
+ add_task :sqlite3, "Run feature-set against SQLite3"
31
+ end
32
+
33
+ desc "Generate RCov reports"
34
+ Spec::Rake::SpecTask.new(:rcov) do |t|
35
+ t.libs << 'lib'
36
+ t.spec_files = FileList['spec/**/*_spec.rb']
37
+ t.rcov = true
38
+ t.rcov_opts = ['--exclude', 'spec', '--exclude', 'gems', '--exclude', 'riddle']
39
+ end
40
+
41
+ namespace :rcov do
42
+ def add_task(name, description)
43
+ Cucumber::Rake::Task.new(name, description) do |t|
44
+ t.cucumber_opts = "--format pretty"
45
+ t.profile = name
46
+ t.rcov = true
47
+ t.rcov_opts = [
48
+ '--exclude', 'spec',
49
+ '--exclude', 'gems',
50
+ '--exclude', 'riddle',
51
+ '--exclude', 'features'
52
+ ]
53
+ end
54
+ end
55
+
56
+ add_task :mysql, "Run feature-set against MySQL with rcov"
57
+ add_task :postgresql, "Run feature-set against PostgreSQL with rcov"
58
+ add_task :oracle, "Run feature-set against Oracle with rcov"
59
+ add_task :sqlite3, "Run feature-set against SQLite3 with rcov"
60
+ end
61
+
62
+ desc "Build cucumber.yml file"
63
+ task :cucumber_defaults do
64
+ default_requires = %w(
65
+ --require features/support/env.rb
66
+ --require features/support/db/mysql.rb
67
+ --require features/support/db/active_record.rb
68
+ --require features/support/post_database.rb
69
+ ).join(" ")
70
+
71
+ step_definitions = FileList["features/step_definitions/**.rb"].collect { |path|
72
+ "--require #{path}"
73
+ }.join(" ")
74
+
75
+ features = FileList["features/*.feature"].join(" ")
76
+
77
+ File.open('cucumber.yml', 'w') { |f|
78
+ f.write "default: \"#{default_requires} #{step_definitions}\"\n\n"
79
+ f.write "mysql: \"#{default_requires} #{step_definitions} #{features}\"\n\n"
80
+ f.write "postgresql: \"#{default_requires.gsub(/mysql/, 'postgresql')} #{step_definitions} #{features}\"\n\n"
81
+ f.write "oracle: \"#{default_requires.gsub(/mysql/, 'oracle')} #{step_definitions} #{features}\"\n\n"
82
+ f.write "sqlite3: \"#{default_requires.gsub(/mysql/, 'sqlite3')} #{step_definitions} #{features}\"\n\n"
83
+ }
84
+ end
85
+
86
+ namespace :thinking_sphinx do
87
+ # "Append testing enviroment settings to app_env task for xmlpipe support"
88
+ task :app_env do
89
+ # Establish DB connection
90
+ if ENV['DATABASE']
91
+ database = ENV['DATABASE'].to_s.sub(/jdbc|_enhanced/, '')
92
+ require "features/support/db/#{database}"
93
+ require "features/support/db/active_record"
94
+ # Load Models
95
+ Dir["features/support/models/*.rb"].sort.each do |file|
96
+ require file.gsub(/\.rb$/, '')
97
+ end
98
+ end
99
+ end
100
+ end
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2008 Nick Muerdter
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,16 @@
1
+ after_commit
2
+ ===========
3
+
4
+ A Ruby on Rails plugin to add after_commit callbacks. The callbacks that are provided can be used
5
+ to trigger events that run only after the entire transaction is complete. This is beneficial
6
+ in situations where you are doing asynchronous processing and need committed objects.
7
+
8
+ The following callbacks are provided:
9
+
10
+ * (1) after_commit
11
+ * (2) after_commit_on_create
12
+ * (3) after_commit_on_update
13
+ * (4) after_commit_on_destroy
14
+
15
+ The after_commit callback is run for any object that has just been committed. You can obtain finer
16
+ callback control by using the additional <tt>after_commit_on_*</tt> callbacks.
@@ -0,0 +1,22 @@
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+ require 'rake/rdoctask'
4
+
5
+ desc 'Default: run unit tests.'
6
+ task :default => :test
7
+
8
+ desc 'Test the after_commit plugin.'
9
+ Rake::TestTask.new(:test) do |t|
10
+ t.libs << 'lib'
11
+ t.pattern = 'test/**/*_test.rb'
12
+ t.verbose = true
13
+ end
14
+
15
+ desc 'Generate documentation for the after_commit plugin.'
16
+ Rake::RDocTask.new(:rdoc) do |rdoc|
17
+ rdoc.rdoc_dir = 'rdoc'
18
+ rdoc.title = 'AfterCommit'
19
+ rdoc.options << '--line-numbers' << '--inline-source'
20
+ rdoc.rdoc_files.include('README')
21
+ rdoc.rdoc_files.include('lib/**/*.rb')
22
+ end
@@ -0,0 +1,8 @@
1
+ ActiveRecord::Base.send(:include, AfterCommit::ActiveRecord)
2
+
3
+ Object.subclasses_of(ActiveRecord::ConnectionAdapters::AbstractAdapter).each do |klass|
4
+ klass.send(:include, AfterCommit::ConnectionAdapters)
5
+ end
6
+ if defined?(JRUBY_VERSION) and defined?(JdbcSpec::MySQL)
7
+ JdbcSpec::MySQL.send :include, AfterCommit::ConnectionAdapters
8
+ end
@@ -0,0 +1,45 @@
1
+ require 'after_commit/active_record'
2
+ require 'after_commit/connection_adapters'
3
+
4
+ module AfterCommit
5
+ def self.committed_records
6
+ @@committed_records ||= []
7
+ end
8
+
9
+ def self.committed_records=(committed_records)
10
+ @@committed_records = committed_records
11
+ end
12
+
13
+ def self.committed_records_on_create
14
+ @@committed_records_on_create ||= []
15
+ end
16
+
17
+ def self.committed_records_on_create=(committed_records)
18
+ @@committed_records_on_create = committed_records
19
+ end
20
+
21
+ def self.committed_records_on_update
22
+ @@committed_records_on_update ||= []
23
+ end
24
+
25
+ def self.committed_records_on_update=(committed_records)
26
+ @@committed_records_on_update = committed_records
27
+ end
28
+
29
+ def self.committed_records_on_destroy
30
+ @@committed_records_on_destroy ||= []
31
+ end
32
+
33
+ def self.committed_records_on_destroy=(committed_records)
34
+ @@committed_records_on_destroy = committed_records
35
+ end
36
+ end
37
+
38
+ ActiveRecord::Base.send(:include, AfterCommit::ActiveRecord)
39
+
40
+ Object.subclasses_of(ActiveRecord::ConnectionAdapters::AbstractAdapter).each do |klass|
41
+ klass.send(:include, AfterCommit::ConnectionAdapters)
42
+ end
43
+ if defined?(JRUBY_VERSION) and defined?(JdbcSpec::MySQL)
44
+ JdbcSpec::MySQL.send :include, AfterCommit::ConnectionAdapters
45
+ end
@@ -0,0 +1,114 @@
1
+ module AfterCommit
2
+ module ActiveRecord
3
+ # Based on the code found in Thinking Sphinx:
4
+ # http://ts.freelancing-gods.com/ which was based on code written by Eli
5
+ # Miller:
6
+ # http://elimiller.blogspot.com/2007/06/proper-cache-expiry-with-aftercommit.html
7
+ # with slight modification from Joost Hietbrink. And now me! Whew.
8
+ def self.included(base)
9
+ base.class_eval do
10
+ # The define_callbacks method was added post Rails 2.0.2 - if it
11
+ # doesn't exist, we define the callback manually
12
+ if respond_to?(:define_callbacks)
13
+ define_callbacks :after_commit,
14
+ :after_commit_on_create,
15
+ :after_commit_on_update,
16
+ :after_commit_on_destroy
17
+ else
18
+ class << self
19
+ # Handle after_commit callbacks - call all the registered callbacks.
20
+ def after_commit(*callbacks, &block)
21
+ callbacks << block if block_given?
22
+ write_inheritable_array(:after_commit, callbacks)
23
+ end
24
+
25
+ def after_commit_on_create(*callbacks, &block)
26
+ callbacks << block if block_given?
27
+ write_inheritable_array(:after_commit_on_create, callbacks)
28
+ end
29
+
30
+ def after_commit_on_update(*callbacks, &block)
31
+ callbacks << block if block_given?
32
+ write_inheritable_array(:after_commit_on_update, callbacks)
33
+ end
34
+
35
+ def after_commit_on_destroy(*callbacks, &block)
36
+ callbacks << block if block_given?
37
+ write_inheritable_array(:after_commit_on_destroy, callbacks)
38
+ end
39
+ end
40
+ end
41
+
42
+ after_save :add_committed_record
43
+ after_create :add_committed_record_on_create
44
+ after_update :add_committed_record_on_update
45
+ after_destroy :add_committed_record_on_destroy
46
+
47
+ # We need to keep track of records that have been saved or destroyed
48
+ # within this transaction.
49
+ def add_committed_record
50
+ AfterCommit.committed_records << self
51
+ end
52
+
53
+ def add_committed_record_on_create
54
+ AfterCommit.committed_records_on_create << self
55
+ end
56
+
57
+ def add_committed_record_on_update
58
+ AfterCommit.committed_records_on_update << self
59
+ end
60
+
61
+ def add_committed_record_on_destroy
62
+ AfterCommit.committed_records << self
63
+ AfterCommit.committed_records_on_destroy << self
64
+ end
65
+
66
+ def after_commit
67
+ # Deliberately blank.
68
+ end
69
+
70
+ # Wraps a call to the private callback method so that the the
71
+ # after_commit callback can be made from the ConnectionAdapters when
72
+ # the commit for the transaction has finally succeeded.
73
+ def after_commit_callback
74
+ call_after_commit_callback :after_commit
75
+ end
76
+
77
+ def after_commit_on_create_callback
78
+ call_after_commit_callback :after_commit_on_create
79
+ end
80
+
81
+ def after_commit_on_update_callback
82
+ call_after_commit_callback :after_commit_on_update
83
+ end
84
+
85
+ def after_commit_on_destroy_callback
86
+ call_after_commit_callback :after_commit_on_destroy
87
+ end
88
+
89
+ private
90
+
91
+ def call_after_commit_callback(call)
92
+ if can_call_after_commit call
93
+ callback call
94
+ clear_after_commit_call call
95
+ end
96
+ end
97
+
98
+ def can_call_after_commit(call)
99
+ @calls ||= {}
100
+ @calls[call] ||= false
101
+ if @calls[call]
102
+ return false
103
+ else
104
+ @calls[call] = true
105
+ end
106
+ end
107
+
108
+ def clear_after_commit_call(call)
109
+ @calls[call] = false
110
+ end
111
+ end
112
+ end
113
+ end
114
+ end
@@ -0,0 +1,103 @@
1
+ module AfterCommit
2
+ module ConnectionAdapters
3
+ def self.included(base)
4
+ base.class_eval do
5
+ # The commit_db_transaction method gets called when the outermost
6
+ # transaction finishes and everything inside commits. We want to
7
+ # override it so that after this happens, any records that were saved
8
+ # or destroyed within this transaction now get their after_commit
9
+ # callback fired.
10
+ def commit_db_transaction_with_callback
11
+ commit_db_transaction_without_callback
12
+ trigger_after_commit_callbacks
13
+ trigger_after_commit_on_create_callbacks
14
+ trigger_after_commit_on_update_callbacks
15
+ trigger_after_commit_on_destroy_callbacks
16
+ end
17
+ alias_method_chain :commit_db_transaction, :callback
18
+
19
+ # In the event the transaction fails and rolls back, nothing inside
20
+ # should recieve the after_commit callback.
21
+ def rollback_db_transaction_with_callback
22
+ rollback_db_transaction_without_callback
23
+
24
+ AfterCommit.committed_records = []
25
+ AfterCommit.committed_records_on_create = []
26
+ AfterCommit.committed_records_on_update = []
27
+ AfterCommit.committed_records_on_destroy = []
28
+ end
29
+ alias_method_chain :rollback_db_transaction, :callback
30
+
31
+ protected
32
+ def trigger_after_commit_callbacks
33
+ # Trigger the after_commit callback for each of the committed
34
+ # records.
35
+ if AfterCommit.committed_records.any?
36
+ AfterCommit.committed_records.each do |record|
37
+ begin
38
+ record.after_commit_callback
39
+ rescue
40
+ end
41
+ end
42
+ end
43
+
44
+ # Make sure we clear out our list of committed records now that we've
45
+ # triggered the callbacks for each one.
46
+ AfterCommit.committed_records = []
47
+ end
48
+
49
+ def trigger_after_commit_on_create_callbacks
50
+ # Trigger the after_commit_on_create callback for each of the committed
51
+ # records.
52
+ if AfterCommit.committed_records_on_create.any?
53
+ AfterCommit.committed_records_on_create.each do |record|
54
+ begin
55
+ record.after_commit_on_create_callback
56
+ rescue
57
+ end
58
+ end
59
+ end
60
+
61
+ # Make sure we clear out our list of committed records now that we've
62
+ # triggered the callbacks for each one.
63
+ AfterCommit.committed_records_on_create = []
64
+ end
65
+
66
+ def trigger_after_commit_on_update_callbacks
67
+ # Trigger the after_commit_on_update callback for each of the committed
68
+ # records.
69
+ if AfterCommit.committed_records_on_update.any?
70
+ AfterCommit.committed_records_on_update.each do |record|
71
+ begin
72
+ record.after_commit_on_update_callback
73
+ rescue
74
+ end
75
+ end
76
+ end
77
+
78
+ # Make sure we clear out our list of committed records now that we've
79
+ # triggered the callbacks for each one.
80
+ AfterCommit.committed_records_on_update = []
81
+ end
82
+
83
+ def trigger_after_commit_on_destroy_callbacks
84
+ # Trigger the after_commit_on_destroy callback for each of the committed
85
+ # records.
86
+ if AfterCommit.committed_records_on_destroy.any?
87
+ AfterCommit.committed_records_on_destroy.each do |record|
88
+ begin
89
+ record.after_commit_on_destroy_callback
90
+ rescue
91
+ end
92
+ end
93
+ end
94
+
95
+ # Make sure we clear out our list of committed records now that we've
96
+ # triggered the callbacks for each one.
97
+ AfterCommit.committed_records_on_destroy = []
98
+ end
99
+ #end protected
100
+ end
101
+ end
102
+ end
103
+ end