Skip to content

Commit 00f91f8

Browse files
committed
Make it compatible to Sequel 5
Devise 4.3.0 confirmable module uses hooks like after_commit :send_on_create_confirmation_instructions, on: :create, if: :send_confirmation_notification? after_commit :send_reconfirmation_instructions, on: :update, if: :reconfirmation_required? which invoke this deprecation warning of Sequel: SEQUEL DEPRECATION WARNING: Sequel::Model.after_commit in the hook_class_methods plugin is deprecated and will be removed in Sequel 5. Use after_save{db.after_commit{}} instead. This uses the recommended code for after_commit and allows to use the :on option.
1 parent 23f805b commit 00f91f8

File tree

3 files changed

+39
-6
lines changed

3 files changed

+39
-6
lines changed

lib/sequel-devise/version.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module Sequel
22
module Devise
3-
VERSION = "0.0.9"
3+
VERSION = "0.0.11"
44
end
55
end

lib/sequel/plugins/devise.rb

+35-2
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,13 @@ def devise_modules_hook!
7171
include OverrideFixes
7272
end
7373

74-
Model::HOOKS.each do |hook|
74+
Model::HOOKS.reject { |hook| hook == :after_commit }.each do |hook|
7575
define_method(hook) do |method = nil, options = {}, &block|
7676
if Symbol === (if_method = options[:if])
7777
orig_block = block
7878
block = nil
7979
method_without_if = method
80-
method = :"_sequel_hook_with_if_#{method}"
80+
method = :"_sequel_#{hook}_hook_with_if_#{method}"
8181
define_method(method) do
8282
return unless send if_method
8383
send method_without_if
@@ -88,6 +88,39 @@ def devise_modules_hook!
8888
super method, &block
8989
end
9090
end
91+
92+
define_method(:after_commit) do |method = nil, options = {}, &block|
93+
if Symbol === (if_method = options[:if])
94+
orig_block = block
95+
block = nil
96+
method_without_if = method
97+
method = :"_sequel_after_commit_hook_with_if_#{method}"
98+
define_method(method) do
99+
return unless send if_method
100+
send method_without_if
101+
instance_eval &orig_block if orig_block
102+
end
103+
private method
104+
end
105+
106+
commit_method = :"_sequel_after_commit_hook__actual_commit_#{method}"
107+
define_method(commit_method) do
108+
db.after_commit do
109+
send method
110+
instance_eval &block if block
111+
end
112+
end
113+
private commit_method
114+
115+
case options[:on]
116+
when :create
117+
send :after_create, commit_method
118+
when :update
119+
send :after_update, commit_method
120+
else
121+
send :after_save, commit_method
122+
end
123+
end
91124
end
92125
end
93126
end

sequel-devise.gemspec

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
require File.expand_path('../lib/sequel-devise/version', __FILE__)
33

44
Gem::Specification.new do |gem|
5-
gem.authors = ["Rodrigo Rosenfeld Rosas"]
6-
gem.email = ["rr.rosas@gmail.com"]
5+
gem.authors = ["Rodrigo Rosenfeld Rosas", "Eugen Kuksa"]
6+
gem.email = ["kuksa.eugen@gmail.com"]
77
gem.description = %q{Devise support for Sequel models}
88
gem.summary = %q{Enable Devise support by adding plugin :devise to your Sequel Model}
9-
gem.homepage = "https://github.com/rosenfeld/sequel-devise"
9+
gem.homepage = "https://github.com/ontohub/sequel-devise"
1010

1111
gem.files = `git ls-files`.split($\)
1212
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }

0 commit comments

Comments
 (0)