after_commit_queue 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,72 @@
1
+ # after_commit_queue
2
+ ---
3
+
4
+ Rails plugin which allows to run callbacks after database transaction is committed.
5
+
6
+ ### What problem does it solve ?
7
+
8
+ When using [state_machine](https://github.com/pluginaweek/state_machine) it's hard to run a callback on event after the transaction is committed.
9
+
10
+ after_commit_queue plugin addresses this problem.
11
+
12
+ ### Installation
13
+
14
+ Add this to your Gemfile and run ```bundle install```
15
+
16
+ ```ruby
17
+ gem 'after_commit_queue'
18
+ ```
19
+
20
+ ### Usage
21
+
22
+ Include AfterCommitQueue module in your ActiveRecord model and you're ready to go.
23
+
24
+ ```ruby
25
+ class Server < ActiveRecord::Base
26
+ attr_accessor :started, :stopped
27
+
28
+ # include plugin
29
+ include AfterCommitQueue
30
+
31
+ state_machine :state, :initial => :pending do
32
+ after_transition :pending => :running, :do => :schedule_start
33
+ after_transition :running => :turned_off, :do => :schedule_stop
34
+ event(:start) { transition :pending => :running }
35
+ event(:stop) { transition :running => :turned_off }
36
+ end
37
+
38
+ def schedule_start
39
+ # Adds method to be run after transaction is committed
40
+ run_after_commit(:start_server)
41
+ end
42
+
43
+ def schedule_stop
44
+ run_after_commit(:stop_server)
45
+ end
46
+
47
+ def start_server; @started = true end
48
+ def stop_server; @stopped = true end
49
+ end
50
+ ```
51
+
52
+ ### Contributions
53
+
54
+ To fetch & test the library for development, do:
55
+
56
+ $ git clone https://github.com/Ragnarson/after_commit_queue
57
+ $ cd after_commit_queue
58
+ $ bundle
59
+
60
+ #### Running tests
61
+
62
+ # Before each test run, the database will be created and migrated automatically
63
+ $ bundle exec rake test
64
+
65
+ If you want to contribute, please:
66
+
67
+ * Fork the project.
68
+ * Make your feature addition or bug fix.
69
+ * Add tests for it. This is important so I don't break it in a future version unintentionally.
70
+ * Send me a pull request on Github.
71
+
72
+ This project rocks and uses MIT-LICENSE.
data/Rakefile CHANGED
@@ -21,9 +21,6 @@ RDoc::Task.new(:rdoc) do |rdoc|
21
21
  rdoc.rdoc_files.include('lib/**/*.rb')
22
22
  end
23
23
 
24
-
25
-
26
-
27
24
  Bundler::GemHelper.install_tasks
28
25
 
29
26
  require 'rake/testtask'
@@ -37,3 +34,11 @@ end
37
34
 
38
35
 
39
36
  task :default => :test
37
+
38
+ APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
39
+ load 'rails/tasks/engine.rake'
40
+
41
+ Rake::Task['test'].enhance ['app:db:drop']
42
+ Rake::Task['test'].enhance ['app:db:create']
43
+ Rake::Task['test'].enhance ['app:db:migrate']
44
+ Rake::Task['test'].enhance ['app:db:test:prepare']
@@ -1,3 +1,3 @@
1
1
  module AfterCommitQueue
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -5,7 +5,7 @@ class AfterCommitQueueTest < ActiveSupport::TestCase
5
5
  @server = Server.new
6
6
  end
7
7
 
8
- test "run after methods after transaction is committed" do
8
+ test "run methods after transaction is committed" do
9
9
  assert !@server.started
10
10
 
11
11
  @server.transaction do
Binary file
@@ -29,3 +29,47 @@ Connecting to database specified by database.yml
29
29
   (1.2ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
30
30
   (0.1ms) SELECT version FROM "schema_migrations"
31
31
   (1.1ms) INSERT INTO "schema_migrations" (version) VALUES ('20120622135717')
32
+ Connecting to database specified by database.yml
33
+  (0.1ms) select sqlite_version(*)
34
+  (1.3ms) CREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL)
35
+  (0.0ms) PRAGMA index_list("schema_migrations")
36
+  (1.1ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
37
+  (0.1ms) SELECT "schema_migrations"."version" FROM "schema_migrations" 
38
+ Migrating to CreateServers (20120622135717)
39
+  (0.0ms) begin transaction
40
+  (0.3ms) CREATE TABLE "servers" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "state" varchar(255), "created_at" datetime NOT NULL, "updated_at" datetime NOT NULL) 
41
+  (0.1ms) INSERT INTO "schema_migrations" ("version") VALUES ('20120622135717')
42
+  (1.1ms) commit transaction
43
+  (0.3ms) select sqlite_version(*)
44
+  (0.1ms) SELECT "schema_migrations"."version" FROM "schema_migrations" 
45
+  (0.0ms) PRAGMA index_list("servers")
46
+  (0.1ms) SELECT "schema_migrations"."version" FROM "schema_migrations" 
47
+  (0.2ms) select sqlite_version(*)
48
+  (1.2ms) CREATE TABLE "servers" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "state" varchar(255), "created_at" datetime NOT NULL, "updated_at" datetime NOT NULL) 
49
+  (1.2ms) CREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL)
50
+  (0.0ms) PRAGMA index_list("schema_migrations")
51
+  (0.9ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
52
+  (0.1ms) SELECT version FROM "schema_migrations"
53
+  (1.2ms) INSERT INTO "schema_migrations" (version) VALUES ('20120622135717')
54
+ Connecting to database specified by database.yml
55
+  (0.1ms) select sqlite_version(*)
56
+  (2.5ms) CREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL)
57
+  (0.0ms) PRAGMA index_list("schema_migrations")
58
+  (1.3ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
59
+  (0.1ms) SELECT "schema_migrations"."version" FROM "schema_migrations" 
60
+ Migrating to CreateServers (20120622135717)
61
+  (0.0ms) begin transaction
62
+  (0.3ms) CREATE TABLE "servers" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "state" varchar(255), "created_at" datetime NOT NULL, "updated_at" datetime NOT NULL) 
63
+  (0.1ms) INSERT INTO "schema_migrations" ("version") VALUES ('20120622135717')
64
+  (1.2ms) commit transaction
65
+  (0.2ms) select sqlite_version(*)
66
+  (0.1ms) SELECT "schema_migrations"."version" FROM "schema_migrations" 
67
+  (0.0ms) PRAGMA index_list("servers")
68
+  (0.1ms) SELECT "schema_migrations"."version" FROM "schema_migrations" 
69
+  (0.2ms) select sqlite_version(*)
70
+  (1.3ms) CREATE TABLE "servers" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "state" varchar(255), "created_at" datetime NOT NULL, "updated_at" datetime NOT NULL) 
71
+  (1.0ms) CREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL)
72
+  (0.0ms) PRAGMA index_list("schema_migrations")
73
+  (1.1ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
74
+  (0.1ms) SELECT version FROM "schema_migrations"
75
+  (1.0ms) INSERT INTO "schema_migrations" (version) VALUES ('20120622135717')
@@ -270,3 +270,33 @@ Connecting to database specified by database.yml
270
270
   (0.1ms) begin transaction
271
271
  SQL (0.5ms) INSERT INTO "servers" ("created_at", "state", "updated_at") VALUES (?, ?, ?) [["created_at", Fri, 22 Jun 2012 15:35:43 UTC +00:00], ["state", "running"], ["updated_at", Fri, 22 Jun 2012 15:35:43 UTC +00:00]]
272
272
   (0.7ms) commit transaction
273
+ Connecting to database specified by database.yml
274
+  (0.0ms) begin transaction
275
+ SQL (5.1ms) INSERT INTO "servers" ("created_at", "state", "updated_at") VALUES (?, ?, ?) [["created_at", Fri, 22 Jun 2012 15:58:05 UTC +00:00], ["state", "running"], ["updated_at", Fri, 22 Jun 2012 15:58:05 UTC +00:00]]
276
+  (0.8ms) commit transaction
277
+  (0.1ms) begin transaction
278
+  (0.3ms) UPDATE "servers" SET "state" = 'turned_off', "updated_at" = '2012-06-22 15:58:05.778522' WHERE "servers"."id" = 25
279
+  (0.7ms) commit transaction
280
+  (0.1ms) begin transaction
281
+ SQL (0.5ms) INSERT INTO "servers" ("created_at", "state", "updated_at") VALUES (?, ?, ?) [["created_at", Fri, 22 Jun 2012 15:58:05 UTC +00:00], ["state", "running"], ["updated_at", Fri, 22 Jun 2012 15:58:05 UTC +00:00]]
282
+  (0.7ms) commit transaction
283
+ Connecting to database specified by database.yml
284
+  (0.1ms) begin transaction
285
+ SQL (5.1ms) INSERT INTO "servers" ("created_at", "state", "updated_at") VALUES (?, ?, ?) [["created_at", Wed, 18 Jul 2012 21:11:10 UTC +00:00], ["state", "running"], ["updated_at", Wed, 18 Jul 2012 21:11:10 UTC +00:00]]
286
+  (1.1ms) commit transaction
287
+  (0.0ms) begin transaction
288
+  (0.2ms) UPDATE "servers" SET "state" = 'turned_off', "updated_at" = '2012-07-18 21:11:10.161801' WHERE "servers"."id" = 1
289
+  (0.6ms) commit transaction
290
+  (0.1ms) begin transaction
291
+ SQL (0.4ms) INSERT INTO "servers" ("created_at", "state", "updated_at") VALUES (?, ?, ?) [["created_at", Wed, 18 Jul 2012 21:11:10 UTC +00:00], ["state", "running"], ["updated_at", Wed, 18 Jul 2012 21:11:10 UTC +00:00]]
292
+  (0.6ms) commit transaction
293
+ Connecting to database specified by database.yml
294
+  (0.0ms) begin transaction
295
+ SQL (2.6ms) INSERT INTO "servers" ("created_at", "state", "updated_at") VALUES (?, ?, ?) [["created_at", Wed, 18 Jul 2012 21:16:29 UTC +00:00], ["state", "running"], ["updated_at", Wed, 18 Jul 2012 21:16:29 UTC +00:00]]
296
+  (1.1ms) commit transaction
297
+  (0.0ms) begin transaction
298
+  (0.2ms) UPDATE "servers" SET "state" = 'turned_off', "updated_at" = '2012-07-18 21:16:29.689270' WHERE "servers"."id" = 1
299
+  (1.1ms) commit transaction
300
+  (0.0ms) begin transaction
301
+ SQL (0.3ms) INSERT INTO "servers" ("created_at", "state", "updated_at") VALUES (?, ?, ?) [["created_at", Wed, 18 Jul 2012 21:16:29 UTC +00:00], ["state", "running"], ["updated_at", Wed, 18 Jul 2012 21:16:29 UTC +00:00]]
302
+  (0.9ms) commit transaction
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: after_commit_queue
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-06-22 00:00:00.000000000 Z
13
+ date: 2012-07-18 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rails
@@ -19,7 +19,7 @@ dependencies:
19
19
  requirements:
20
20
  - - ~>
21
21
  - !ruby/object:Gem::Version
22
- version: 3.2.6
22
+ version: '3.0'
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
@@ -27,7 +27,7 @@ dependencies:
27
27
  requirements:
28
28
  - - ~>
29
29
  - !ruby/object:Gem::Version
30
- version: 3.2.6
30
+ version: '3.0'
31
31
  - !ruby/object:Gem::Dependency
32
32
  name: sqlite3
33
33
  requirement: !ruby/object:Gem::Requirement
@@ -56,7 +56,7 @@ files:
56
56
  - lib/tasks/after_commit_queue_tasks.rake
57
57
  - MIT-LICENSE
58
58
  - Rakefile
59
- - README.rdoc
59
+ - README.md
60
60
  - test/after_commit_queue_test.rb
61
61
  - test/dummy/app/assets/javascripts/application.js
62
62
  - test/dummy/app/assets/stylesheets/application.css
@@ -110,7 +110,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
110
110
  version: '0'
111
111
  segments:
112
112
  - 0
113
- hash: -4088333639822721744
113
+ hash: -2163612595833260696
114
114
  required_rubygems_version: !ruby/object:Gem::Requirement
115
115
  none: false
116
116
  requirements:
@@ -119,7 +119,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
119
119
  version: '0'
120
120
  segments:
121
121
  - 0
122
- hash: -4088333639822721744
122
+ hash: -2163612595833260696
123
123
  requirements: []
124
124
  rubyforge_project:
125
125
  rubygems_version: 1.8.24
@@ -1,3 +0,0 @@
1
- = AfterCommitQueue
2
-
3
- This project rocks and uses MIT-LICENSE.