delayed_after_commit 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: cbf215af4da0696ce77b3a66ea46ffdb82894cf5
4
+ data.tar.gz: 497c34145e4e8d05ca9f76181a0679468f4f1773
5
+ SHA512:
6
+ metadata.gz: 3a84762a172d295a59928ea9be8d1f43efac381531eaf3483e14eb52f00650c44ad2f3db5451c6bf2864e23d688c51d89b8b30e6471867d2c8d13514b05f8054
7
+ data.tar.gz: 3a377597e9becc61d396680df1df0ba42f95a6dd76234d732e2462bc1846b4f7f6a2ea54a27ca983fb3079f45ac43880b1f6e5d2b6221c4e7460301f117a7700
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ .byebug_history
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.3
data/.travis.yml ADDED
@@ -0,0 +1,19 @@
1
+ language: ruby
2
+
3
+ rvm:
4
+ - 2.3.0
5
+
6
+ sudo: false
7
+
8
+ matrix:
9
+ allow_failures:
10
+ - rvm: rbx-2
11
+ - rvm: jruby-19mode
12
+ - rvm: ruby-head
13
+ - rvm: jruby-head
14
+
15
+ gemfile:
16
+ - gemfiles/rails_42.gemfile
17
+ - gemfiles/rails_5.gemfile
18
+
19
+ script: 'bundle exec rake spec'
data/Appraisals ADDED
@@ -0,0 +1,7 @@
1
+ appraise 'rails-42' do
2
+ gem 'activerecord', '4.2.0'
3
+ end
4
+
5
+ appraise 'rails-5' do
6
+ gem 'activerecord', '5'
7
+ end
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in delayed_after_commit.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,46 @@
1
+ [![Build Status](http://img.shields.io/travis/intellum/delayed_after_commit.svg?style=flat)](https://travis-ci.org/intellum/delayed_after_commit)
2
+
3
+ # DelayedAfterCommit
4
+
5
+ Exactly the same as after_commit, except it puts the job onto the Sidekiq queue.
6
+
7
+ Allows you to queue active record methods, after they have been created or updated.
8
+
9
+ Requires Sidekiq, and Rails >= 4.
10
+
11
+ ## Installation
12
+
13
+ Add this line to your application's Gemfile:
14
+
15
+ ```ruby
16
+ gem 'delayed_after_commit'
17
+ ```
18
+
19
+ And then execute:
20
+
21
+ $ bundle
22
+
23
+ Or install it yourself as:
24
+
25
+ $ gem install delayed_after_commit
26
+
27
+ ## Usage
28
+
29
+ ```ruby
30
+
31
+ class User < ActiveRecord::Base
32
+ include DelayedAfterCommit
33
+ delayed_on_update :increment_number_of_updates
34
+ delayed_on_create :calculate_number_of_letters_in_name
35
+ end
36
+
37
+ ```
38
+
39
+ ## Roadmap
40
+
41
+ - Allow asyncronous callbacks on destroying objects
42
+
43
+ ## Contributing
44
+
45
+ Bug reports and pull requests are welcome on GitHub at https://github.com/intellum/delayed_after_commit.
46
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require 'bundler/gem_tasks'
2
+
3
+ require 'rspec/core/rake_task'
4
+ RSpec::Core::RakeTask.new :spec
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "delayed_after_commit"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'delayed_after_commit/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "delayed_after_commit"
8
+ spec.version = DelayedAfterCommit::VERSION
9
+ spec.authors = ["Simon Rentzke"]
10
+ spec.email = ["simon@rentzke.com"]
11
+
12
+ spec.summary = %q{delayed after commit}
13
+ spec.description = %q{defer your after commit callbacks to sidekiq}
14
+ spec.homepage = "https://intellum.com"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "activerecord", '>= 4.2.0'
22
+ spec.add_development_dependency "sidekiq", "> 4.1"
23
+ spec.add_development_dependency "bundler", "~> 1.12"
24
+ spec.add_development_dependency "byebug", '>= 0'
25
+ spec.add_development_dependency "rspec", '>= 0'
26
+ spec.add_development_dependency "sqlite3", '>= 0'
27
+ spec.add_development_dependency "rake", "~> 10.0"
28
+ spec.add_development_dependency "appraisal"
29
+ end
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "activerecord", "4.2.0"
6
+
7
+ gemspec :path => "../"
@@ -0,0 +1,80 @@
1
+ PATH
2
+ remote: ../
3
+ specs:
4
+ delayed_after_commit (0.1.0)
5
+ activerecord (>= 4.2.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ activemodel (4.2.0)
11
+ activesupport (= 4.2.0)
12
+ builder (~> 3.1)
13
+ activerecord (4.2.0)
14
+ activemodel (= 4.2.0)
15
+ activesupport (= 4.2.0)
16
+ arel (~> 6.0)
17
+ activesupport (4.2.0)
18
+ i18n (~> 0.7)
19
+ json (~> 1.7, >= 1.7.7)
20
+ minitest (~> 5.1)
21
+ thread_safe (~> 0.3, >= 0.3.4)
22
+ tzinfo (~> 1.1)
23
+ appraisal (2.1.0)
24
+ bundler
25
+ rake
26
+ thor (>= 0.14.0)
27
+ arel (6.0.3)
28
+ builder (3.2.2)
29
+ byebug (9.0.6)
30
+ concurrent-ruby (1.0.2)
31
+ connection_pool (2.2.0)
32
+ diff-lcs (1.2.5)
33
+ i18n (0.7.0)
34
+ json (1.8.3)
35
+ minitest (5.9.1)
36
+ rack (2.0.1)
37
+ rack-protection (1.5.3)
38
+ rack
39
+ rake (10.5.0)
40
+ redis (3.3.1)
41
+ rspec (3.5.0)
42
+ rspec-core (~> 3.5.0)
43
+ rspec-expectations (~> 3.5.0)
44
+ rspec-mocks (~> 3.5.0)
45
+ rspec-core (3.5.4)
46
+ rspec-support (~> 3.5.0)
47
+ rspec-expectations (3.5.0)
48
+ diff-lcs (>= 1.2.0, < 2.0)
49
+ rspec-support (~> 3.5.0)
50
+ rspec-mocks (3.5.0)
51
+ diff-lcs (>= 1.2.0, < 2.0)
52
+ rspec-support (~> 3.5.0)
53
+ rspec-support (3.5.0)
54
+ sidekiq (4.2.3)
55
+ concurrent-ruby (~> 1.0)
56
+ connection_pool (~> 2.2, >= 2.2.0)
57
+ rack-protection (>= 1.5.0)
58
+ redis (~> 3.2, >= 3.2.1)
59
+ sqlite3 (1.3.12)
60
+ thor (0.19.1)
61
+ thread_safe (0.3.5)
62
+ tzinfo (1.2.2)
63
+ thread_safe (~> 0.1)
64
+
65
+ PLATFORMS
66
+ ruby
67
+
68
+ DEPENDENCIES
69
+ activerecord (= 4.2.0)
70
+ appraisal
71
+ bundler (~> 1.12)
72
+ byebug
73
+ delayed_after_commit!
74
+ rake (~> 10.0)
75
+ rspec
76
+ sidekiq (> 4.1)
77
+ sqlite3
78
+
79
+ BUNDLED WITH
80
+ 1.12.5
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "activerecord", "5"
6
+
7
+ gemspec :path => "../"
@@ -0,0 +1,76 @@
1
+ PATH
2
+ remote: ../
3
+ specs:
4
+ delayed_after_commit (0.1.0)
5
+ activerecord (>= 4.2.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ activemodel (5.0.0)
11
+ activesupport (= 5.0.0)
12
+ activerecord (5.0.0)
13
+ activemodel (= 5.0.0)
14
+ activesupport (= 5.0.0)
15
+ arel (~> 7.0)
16
+ activesupport (5.0.0)
17
+ concurrent-ruby (~> 1.0, >= 1.0.2)
18
+ i18n (~> 0.7)
19
+ minitest (~> 5.1)
20
+ tzinfo (~> 1.1)
21
+ appraisal (2.1.0)
22
+ bundler
23
+ rake
24
+ thor (>= 0.14.0)
25
+ arel (7.1.4)
26
+ byebug (9.0.6)
27
+ concurrent-ruby (1.0.2)
28
+ connection_pool (2.2.0)
29
+ diff-lcs (1.2.5)
30
+ i18n (0.7.0)
31
+ minitest (5.9.1)
32
+ rack (2.0.1)
33
+ rack-protection (1.5.3)
34
+ rack
35
+ rake (10.5.0)
36
+ redis (3.3.1)
37
+ rspec (3.5.0)
38
+ rspec-core (~> 3.5.0)
39
+ rspec-expectations (~> 3.5.0)
40
+ rspec-mocks (~> 3.5.0)
41
+ rspec-core (3.5.4)
42
+ rspec-support (~> 3.5.0)
43
+ rspec-expectations (3.5.0)
44
+ diff-lcs (>= 1.2.0, < 2.0)
45
+ rspec-support (~> 3.5.0)
46
+ rspec-mocks (3.5.0)
47
+ diff-lcs (>= 1.2.0, < 2.0)
48
+ rspec-support (~> 3.5.0)
49
+ rspec-support (3.5.0)
50
+ sidekiq (4.2.3)
51
+ concurrent-ruby (~> 1.0)
52
+ connection_pool (~> 2.2, >= 2.2.0)
53
+ rack-protection (>= 1.5.0)
54
+ redis (~> 3.2, >= 3.2.1)
55
+ sqlite3 (1.3.12)
56
+ thor (0.19.1)
57
+ thread_safe (0.3.5)
58
+ tzinfo (1.2.2)
59
+ thread_safe (~> 0.1)
60
+
61
+ PLATFORMS
62
+ ruby
63
+
64
+ DEPENDENCIES
65
+ activerecord (= 5)
66
+ appraisal
67
+ bundler (~> 1.12)
68
+ byebug
69
+ delayed_after_commit!
70
+ rake (~> 10.0)
71
+ rspec
72
+ sidekiq (> 4.1)
73
+ sqlite3
74
+
75
+ BUNDLED WITH
76
+ 1.12.5
@@ -0,0 +1,3 @@
1
+ module DelayedAfterCommit
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,34 @@
1
+ require "delayed_after_commit/version"
2
+
3
+ module DelayedAfterCommit
4
+ extend ActiveSupport::Concern
5
+
6
+ class_methods do
7
+ def enqueue_delayed_method(method, id)
8
+ # this is used as a generic method that is created to run asyncronously from within sidekiq
9
+ # it finds the object, and runs the deferred method
10
+ obj = self.find(id)
11
+ obj.send(method)
12
+ end
13
+
14
+ def delayed_on_create(method)
15
+ delayed_after_commit(method, on: :create)
16
+ end
17
+
18
+ def delayed_on_update(method)
19
+ delayed_after_commit(method, on: :update)
20
+ end
21
+
22
+ protected
23
+ def delayed_after_commit(method, on: nil)
24
+ # this creates a method that runs `enqueue_delayed_method`
25
+ # it then adds that method to the after_commit callback
26
+ on ||= :update
27
+ delayed_method_name = "delayed_after_#{on}_#{method}"
28
+ define_method(delayed_method_name) do |m = method|
29
+ self.class.delay.enqueue_delayed_method(m, self.id)
30
+ end
31
+ self.after_commit(delayed_method_name.to_sym, on: on)
32
+ end
33
+ end
34
+ end
metadata ADDED
@@ -0,0 +1,171 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: delayed_after_commit
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Simon Rentzke
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-10-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activerecord
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 4.2.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 4.2.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: sidekiq
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">"
32
+ - !ruby/object:Gem::Version
33
+ version: '4.1'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">"
39
+ - !ruby/object:Gem::Version
40
+ version: '4.1'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.12'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.12'
55
+ - !ruby/object:Gem::Dependency
56
+ name: byebug
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: sqlite3
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rake
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '10.0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '10.0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: appraisal
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ description: defer your after commit callbacks to sidekiq
126
+ email:
127
+ - simon@rentzke.com
128
+ executables: []
129
+ extensions: []
130
+ extra_rdoc_files: []
131
+ files:
132
+ - ".gitignore"
133
+ - ".ruby-version"
134
+ - ".travis.yml"
135
+ - Appraisals
136
+ - Gemfile
137
+ - README.md
138
+ - Rakefile
139
+ - bin/console
140
+ - bin/setup
141
+ - delayed_after_commit.gemspec
142
+ - gemfiles/rails_42.gemfile
143
+ - gemfiles/rails_42.gemfile.lock
144
+ - gemfiles/rails_5.gemfile
145
+ - gemfiles/rails_5.gemfile.lock
146
+ - lib/delayed_after_commit.rb
147
+ - lib/delayed_after_commit/version.rb
148
+ homepage: https://intellum.com
149
+ licenses: []
150
+ metadata: {}
151
+ post_install_message:
152
+ rdoc_options: []
153
+ require_paths:
154
+ - lib
155
+ required_ruby_version: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ required_rubygems_version: !ruby/object:Gem::Requirement
161
+ requirements:
162
+ - - ">="
163
+ - !ruby/object:Gem::Version
164
+ version: '0'
165
+ requirements: []
166
+ rubyforge_project:
167
+ rubygems_version: 2.5.1
168
+ signing_key:
169
+ specification_version: 4
170
+ summary: delayed after commit
171
+ test_files: []