devise-hookable-notifications 0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +16 -0
- data/lib/devise-hookable-notifications.rb +31 -0
- data/spec/devise_hookable_notifications_spec.rb +23 -0
- data/spec/schema.rb +7 -0
- data/spec/spec_helper.rb +14 -0
- metadata +102 -0
data/README.md
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# devise-hookable-notifications
|
2
|
+
|
3
|
+
Hook email send events, such as `:unlock_instructions`, perhaps to send
|
4
|
+
another email of your own or whatever you want, without having to mess
|
5
|
+
around with the actions themselves.
|
6
|
+
|
7
|
+
```ruby
|
8
|
+
devise :database_authenticatable, :lockable, :hookable_notifications
|
9
|
+
|
10
|
+
after_devise_notification :unlock_instructions, perform: ->(user) {
|
11
|
+
AdminMailer.activity_notice(user, 'Account Locked').deliver }
|
12
|
+
```
|
13
|
+
|
14
|
+
### TODO
|
15
|
+
|
16
|
+
- [ ] As needed, add support for a `before` callback.
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'active_support/concern'
|
2
|
+
|
3
|
+
module Devise
|
4
|
+
module Models
|
5
|
+
module HookableNotification
|
6
|
+
extend ActiveSupport::Concern
|
7
|
+
|
8
|
+
included do
|
9
|
+
def send_devise_notification(notification, *args)
|
10
|
+
super.tap do |_|
|
11
|
+
cbs = self.class.instance_variable_get('@_after_devise_notification_callbacks')
|
12
|
+
|
13
|
+
if cbs.present? && cbs[notification].present?
|
14
|
+
cbs[notification].each { |cb| cb.call(self) }
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
module ClassMethods
|
21
|
+
def after_devise_notification(notification, options = {})
|
22
|
+
@_after_devise_notification_callbacks ||= {}
|
23
|
+
if options[:perform].present?
|
24
|
+
@_after_devise_notification_callbacks[notification] ||= []
|
25
|
+
@_after_devise_notification_callbacks[notification] << options[:perform]
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'devise'
|
3
|
+
|
4
|
+
describe Devise::Models::HookableNotification do
|
5
|
+
before do
|
6
|
+
$devise_mailer = double('devise_mailer').as_null_object
|
7
|
+
|
8
|
+
class User < ActiveRecord::Base
|
9
|
+
devise :database_authenticatable, :hookable_notifications
|
10
|
+
|
11
|
+
def devise_mailer; $devise_mailer; end
|
12
|
+
|
13
|
+
after_devise_notification :something, perform: ->(user) { user.after_callback }
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
let(:user) { User.new }
|
18
|
+
|
19
|
+
it 'allows you to define actions to perform after certain events' do
|
20
|
+
allow(user).to receive(:after_callback).once
|
21
|
+
user.send_devise_notification(:something)
|
22
|
+
end
|
23
|
+
end
|
data/spec/schema.rb
ADDED
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'pry'
|
2
|
+
require 'rspec'
|
3
|
+
require 'active_record'
|
4
|
+
require 'nulldb_rspec'
|
5
|
+
|
6
|
+
ActiveRecord::Base.establish_connection adapter: :nulldb,
|
7
|
+
schema: File.join(File.dirname(File.expand_path(__FILE__)), '/schema.rb')
|
8
|
+
|
9
|
+
require 'devise'
|
10
|
+
Devise.setup do |config|
|
11
|
+
require 'devise/orm/active_record'
|
12
|
+
end
|
13
|
+
|
14
|
+
require_relative '../lib/devise-hookable-notifications'
|
metadata
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: devise-hookable-notifications
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '0.1'
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Brent Vatne
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2014-06-17 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: activesupport
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 3.0.0
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 3.0.0
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: activerecord
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 3.0.0
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 3.0.0
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: devise
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ~>
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 3.2.3
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 3.2.3
|
62
|
+
description: Hooks to run some code around notification events for Devise
|
63
|
+
email:
|
64
|
+
- brent.vatne@gmail.com
|
65
|
+
executables: []
|
66
|
+
extensions: []
|
67
|
+
extra_rdoc_files: []
|
68
|
+
files:
|
69
|
+
- lib/devise-hookable-notifications.rb
|
70
|
+
- README.md
|
71
|
+
- spec/devise_hookable_notifications_spec.rb
|
72
|
+
- spec/schema.rb
|
73
|
+
- spec/spec_helper.rb
|
74
|
+
homepage: https://github.com/brentvatne/devise-hookable-notifications
|
75
|
+
licenses: []
|
76
|
+
post_install_message:
|
77
|
+
rdoc_options: []
|
78
|
+
require_paths:
|
79
|
+
- lib
|
80
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
87
|
+
none: false
|
88
|
+
requirements:
|
89
|
+
- - ! '>='
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
92
|
+
requirements: []
|
93
|
+
rubyforge_project:
|
94
|
+
rubygems_version: 1.8.29
|
95
|
+
signing_key:
|
96
|
+
specification_version: 3
|
97
|
+
summary: Hooks to run some code around notification events for Devise
|
98
|
+
test_files:
|
99
|
+
- spec/devise_hookable_notifications_spec.rb
|
100
|
+
- spec/schema.rb
|
101
|
+
- spec/spec_helper.rb
|
102
|
+
has_rdoc:
|