devise_invalidatable 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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f92232200260dbb1d0e4052ad0e17a6d7e6fdc6c
4
- data.tar.gz: 925c9619e77588dddb81a9e94dfd5834c0c5277a
3
+ metadata.gz: d347d5fe4c9336e80566904e823f5cfe3a6cf198
4
+ data.tar.gz: afe9a82bf243791d442a96c27fb68dd670f74e27
5
5
  SHA512:
6
- metadata.gz: 0ce8619f19ff1f1a5e5c9988273f318b4902920f7f473e09feb9b20bbc1187c38ed57bdfe9ca74a0b2181a74d2b6db95602a1a5c2aa5654515d6e9fcd98d9ea3
7
- data.tar.gz: c336ff382bc2a9cf22e2d71c43476967f3f778d365453757d78044c4b4ccd6dccf65c5cbe3be1675ed00a1b000c58a405ce151d68207b625ec4bce2af9ee6e3a
6
+ metadata.gz: 98b958e96dc30e88fb5d2326f151e5d250aaa05eddc55f17be82b2fde1f639fcd630d3400315f8d829d5fd924e2ff034a07c421c5605bbf3a328def4db8af581
7
+ data.tar.gz: 3c52bcb01a97d5d8e381fa30fcaf8c25a7975b832b6df240aa744031dff131bcf1dff582bba92443458eac3eaaa5da3e9887d320f0eaa63caa18fbe69520df2d
@@ -8,7 +8,6 @@ module Devise
8
8
  included do
9
9
  has_many :user_sessions,
10
10
  class_name: 'UserSession',
11
- foreign_key: :user_id,
12
11
  dependent: :destroy
13
12
  end
14
13
 
@@ -1,3 +1,3 @@
1
1
  module DeviseInvalidatable
2
- VERSION = '0.0.1'.freeze
3
- end
2
+ VERSION = '0.0.2'.freeze
3
+ end
@@ -9,8 +9,10 @@ Devise.add_module(:invalidatable,
9
9
  module DeviseInvalidatable
10
10
  end
11
11
 
12
- class UserSession < ActiveRecord::Base
13
- def self.deactivate(session_id)
14
- where(session_id: session_id).delete_all
12
+ if defined?(ActiveRecord)
13
+ class UserSession < ActiveRecord::Base
14
+ def self.deactivate(session_id)
15
+ where(session_id: session_id).delete_all
16
+ end
15
17
  end
16
- end
18
+ end
@@ -1,10 +1,14 @@
1
1
  require 'rails/generators'
2
2
 
3
3
  class DeviseInvalidatableGenerator < Rails::Generators::NamedBase
4
- include Rails::Generators::Migration
4
+ if defined?(ActiveRecord)
5
+ include Rails::Generators::Migration
6
+ end
5
7
 
6
- desc 'Creates a migration to add the required attributes to NAME, and adds' \
8
+ desc 'Creates a migration to add the required attributes to NAME, and adds ' \
7
9
  'the necessary Devise directives to the model'
10
+ class_option :mongoid, type: :boolean, group: :runtime,
11
+ desc: 'Create mongoid user session model'
8
12
 
9
13
  def self.source_root
10
14
  @_devise_source_root ||= File.expand_path('../templates', __FILE__)
@@ -18,10 +22,27 @@ class DeviseInvalidatableGenerator < Rails::Generators::NamedBase
18
22
  end
19
23
  end
20
24
 
25
+ def generate
26
+ if options['mongoid']
27
+ create_session_model
28
+ else
29
+ create_migration_file
30
+ end
31
+
32
+ inject_devise_directives_into_model
33
+ end
34
+
35
+ private
36
+
21
37
  def create_migration_file
22
38
  migration_template 'migration.rb', 'db/migrate/devise_create_user_sessions.rb'
23
39
  end
24
40
 
41
+ def create_session_model
42
+ model_path = File.join('app', 'models', 'user_session.rb')
43
+ template('user_session.rb', model_path)
44
+ end
45
+
25
46
  def inject_devise_directives_into_model
26
47
  model_path = File.join('app', 'models', "#{file_path}.rb")
27
48
  class_path = namespaced? ? class_name.to_s.split('::') : [class_name]
@@ -32,5 +53,4 @@ class DeviseInvalidatableGenerator < Rails::Generators::NamedBase
32
53
 
33
54
  inject_into_class(model_path, class_path.last, content)
34
55
  end
35
-
36
56
  end
@@ -1,6 +1,6 @@
1
1
  class DeviseCreateUserSessions < ActiveRecord::Migration
2
2
  @@table_name = :user_sessions
3
- @@column_name = :user_id
3
+ @@column_name = :<%= file_name %>_id
4
4
 
5
5
  def up
6
6
  create_table @@table_name do |t|
@@ -0,0 +1,15 @@
1
+ class UserSession
2
+ include Mongoid::Document
3
+ include Mongoid::Timestamps
4
+
5
+ field :session_id, type: String
6
+
7
+ belongs_to :<%= file_name %>
8
+
9
+ index({ <%= file_name %>_id: 1 })
10
+ index({ session_id: 1 }, { unique: true })
11
+
12
+ def self.deactivate(session_id)
13
+ where(session_id: session_id).delete_all
14
+ end
15
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: devise_invalidatable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Adkins
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-09-10 00:00:00.000000000 Z
11
+ date: 2016-07-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -50,6 +50,7 @@ files:
50
50
  - lib/devise_invalidatable/version.rb
51
51
  - lib/generators/devise_invalidatable/devise_invalidatable_generator.rb
52
52
  - lib/generators/devise_invalidatable/templates/migration.rb
53
+ - lib/generators/devise_invalidatable/templates/user_session.rb
53
54
  homepage: https://github.com/madkins/devise_invalidatable
54
55
  licenses:
55
56
  - MIT
@@ -70,7 +71,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
70
71
  version: '0'
71
72
  requirements: []
72
73
  rubyforge_project:
73
- rubygems_version: 2.2.2
74
+ rubygems_version: 2.4.8
74
75
  signing_key:
75
76
  specification_version: 4
76
77
  summary: Adds the ability to invalidate a session with Devise