sequel-devise-updated 0.0.14

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: fe48de9c41ec0e7f037948ce7a1587040eee803ba08ff1a5d8d24465db1d1aba
4
+ data.tar.gz: e07b1def336ae03772b74fa61b1024ab2491338fa44ce8b8b8551685bf4518d6
5
+ SHA512:
6
+ metadata.gz: 9975d16a454606eea9b14ec0291123dc810afb54bb8000806d0edeee1547d347f3986b8815dda6d0ebc5215e529731ec85868de2ff983287d954ab6b75086784
7
+ data.tar.gz: 22aa57625f84d4366c853b260c88b4540fb1767ceff1396cb9b4dc0a7b702766939eb7067abbb279a42e8151ba28c6dade786b1683cd2f387b5a0df019f7aa71
data/.gitignore ADDED
@@ -0,0 +1,20 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+
19
+ # vim swap files:
20
+ *.swp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in sequel-devise.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Rodrigo Rosenfeld Rosas
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,86 @@
1
+ # Sequel::Devise Updated
2
+
3
+ Allows the usage of a Sequel::Model class as a Devise mapping.
4
+
5
+ This gem was previously developed at [rosenfeld/sequel-devise](https://github.com/rosenfeld/sequel-devise).
6
+ This updated package keeps the same runtime require path and Sequel plugin while adding compatibility for Devise 5.
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ gem 'sequel-devise-updated', require: 'sequel-devise'
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install sequel-devise-updated
21
+
22
+ ## Usage
23
+
24
+ class User < Sequel::Model
25
+ plugin :devise
26
+ devise :database_authenticatable
27
+ end
28
+
29
+ If you're interested in more instructions on using Sequel with Rails,
30
+ I've written [some instructions](http://rosenfeld.herokuapp.com/en/articles/2012-04-18-getting-started-with-sequel-in-rails) in my web site.
31
+
32
+ ## Important Note
33
+
34
+ Unfortunately Devise does not rely on the `orm_adapter` specs as
35
+ [it was supposed to](https://github.com/plataformatec/devise/blob/master/devise.gemspec#L22).
36
+
37
+ It will assume the model support other methods besides those defined by `orm_adapter` and that they
38
+ behave like the equivalent in ActiveRecord supporting the same arguments.
39
+
40
+ In some cases, it will call some method which is not defined by `Sequel::Model`, so we implement
41
+ them in this gem, but there are some cases which are trickier. For example, Devise will call the
42
+ `save` method in the model and expect it to return false if the validation fails. This is not the
43
+ default behavior of Sequel::Model, so you'll have to change this behavior for your User classes
44
+ that are intended to be used by Devise. There are a few solutions depending on your use case:
45
+
46
+ Please make sure you take a look at the implementation to understand which methods are added
47
+ in order to support Devise. Particularly, for security reasons Devise will override inspect
48
+ so that it doesn't display passwords hashes for example among other keys. If you want the
49
+ original inspect, call `user.inspect(false)`.
50
+
51
+ ### You expect your Sequel Models to not raise on save failure by default
52
+
53
+ Just disable the raise behavior by default:
54
+
55
+ Sequel::Model.raise_on_save_failure = false
56
+
57
+ ### You are okay with changing the raise behavior only for your user classes
58
+
59
+ class User < Sequel::Model
60
+ self.raise_on_save_failure = false
61
+ plugin :devise
62
+ devise :database_authenticatable
63
+ end
64
+
65
+ ### You don't want to touch your user model just to accomodate Devise
66
+
67
+ You are free to simply create another user class that is meant to be used by Devise while the
68
+ remaining of your application just use your regular user class:
69
+
70
+ class DeviseUser < User
71
+ self.raise_on_save_failure = false
72
+ plugin :devise
73
+ devise :database_authenticatable
74
+ end
75
+
76
+ ## Contributing
77
+
78
+ 1. Fork it
79
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
80
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
81
+ 4. Push to the branch (`git push origin my-new-feature`)
82
+ 5. Create new Pull Request
83
+
84
+ ## Acknowledgements
85
+
86
+ Thanks to [@rosenfeld](https://github.com/rosenfeld) for creating this gem before we started maintaining it!
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,177 @@
1
+ module Sequel
2
+ module Plugins
3
+ module Devise
4
+ def self.apply(model, options = {})
5
+ model.extend ::Devise::Models
6
+ model.plugin :hook_class_methods # Devise requires a before_validation
7
+ model.plugin :dirty # email_changed?
8
+ model.plugin :validation_class_methods # for using validatable module
9
+
10
+ # for Devise::Models::Trackable
11
+ model.send :alias_method, :new_record?, :new?
12
+ end
13
+
14
+ module InstanceMethods
15
+ def changed? # For rememberable
16
+ !changed_columns.empty?
17
+ end
18
+
19
+ def encrypted_password_changed? # For recoverable and database_authenticatable
20
+ new? || column_changed?(:encrypted_password)
21
+ end
22
+
23
+ def email_changed? # For validatable
24
+ new? || column_changed?(:email)
25
+ end
26
+
27
+ def email_was # For confirmable
28
+ column_changes[:email].first
29
+ end
30
+
31
+ # for database_authenticatable:
32
+ def assign_attributes(hash)
33
+ set hash
34
+ end
35
+
36
+ def update_attributes(hash, *ignored)
37
+ begin
38
+ update(hash) != false
39
+ rescue Sequel::ValidationFailed
40
+ return false
41
+ end
42
+ end
43
+
44
+ def update_attribute(key, value)
45
+ update_attributes key => value
46
+ end
47
+
48
+ private
49
+
50
+ def devise_safe_values
51
+ values.delete_if{|k, v| devise_safe_keys.include?(k) || k =~ /password/i }
52
+ end
53
+
54
+ def devise_safe_keys
55
+ authenticatable = ::Devise::Models::Authenticatable
56
+
57
+ if authenticatable.const_defined?(:UNSAFE_ATTRIBUTES_FOR_SERIALIZATION)
58
+ authenticatable::UNSAFE_ATTRIBUTES_FOR_SERIALIZATION
59
+ else
60
+ authenticatable::BLACKLIST_FOR_SERIALIZATION
61
+ end
62
+ end
63
+ end
64
+
65
+ module ClassMethods
66
+
67
+ def human_attribute_name(key)
68
+ key.to_s
69
+ end
70
+
71
+ def validates_length_of(*atts)
72
+ opts = {
73
+ nil_message: 'is not present',
74
+ too_long: 'is too long',
75
+ too_short: 'is too short',
76
+ wrong_length: 'is the wrong length'
77
+ }.merge!(extract_options!(atts))
78
+
79
+ opts[:tag] ||= ([:length] + [:maximum, :minimum, :is, :within].reject { |x| !opts.include?(x) }).join('-').to_sym
80
+ reflect_validation(:length, opts, atts)
81
+ atts << opts
82
+
83
+ validates_each(*atts) do |o, a, v|
84
+ if opts.include?(:maximum)
85
+ m = devise_validation_value(opts[:maximum])
86
+ o.errors.add(a, opts[:message] || (v ? opts[:too_long] : opts[:nil_message])) unless v && v.size <= m
87
+ end
88
+
89
+ if opts.include?(:minimum)
90
+ m = devise_validation_value(opts[:minimum])
91
+ o.errors.add(a, opts[:message] || opts[:too_short]) unless v && v.size >= m
92
+ end
93
+
94
+ if opts.include?(:is)
95
+ i = devise_validation_value(opts[:is])
96
+ o.errors.add(a, opts[:message] || opts[:wrong_length]) unless v && v.size == i
97
+ end
98
+
99
+ if opts.include?(:within)
100
+ w = devise_validation_value(opts[:within])
101
+ o.errors.add(a, opts[:message] || opts[:wrong_length]) unless v && w.public_send(w.respond_to?(:cover?) ? :cover? : :include?, v.size)
102
+ end
103
+ end
104
+ end
105
+
106
+ module OverrideFixes
107
+ def inspect(safe = true)
108
+ return self.class.superclass.instance_method(:inspect).bind(self)[] unless safe
109
+ "#<#{self.class} @values=#{devise_safe_values.inspect}>"
110
+ end
111
+ end
112
+
113
+ def devise_modules_hook!
114
+ yield
115
+ include OverrideFixes
116
+ end
117
+
118
+ ::Sequel::Model::HOOKS.reject { |hook| hook == :after_commit }.each do |hook|
119
+ define_method(hook) do |method = nil, options = {}, &block|
120
+ if Symbol === (if_method = options[:if])
121
+ orig_block = block
122
+ block = nil
123
+ method_without_if = method
124
+ method = :"_sequel_#{hook}_hook_with_if_#{method}"
125
+ define_method(method) do
126
+ return unless send if_method
127
+ send method_without_if
128
+ instance_eval &orig_block if orig_block
129
+ end
130
+ private method
131
+ end
132
+ super method, &block
133
+ end
134
+ end
135
+
136
+ define_method(:after_commit) do |method = nil, options = {}, &block|
137
+ if Symbol === (if_method = options[:if])
138
+ orig_block = block
139
+ block = nil
140
+ method_without_if = method
141
+ method = :"_sequel_after_commit_hook_with_if_#{method}"
142
+ define_method(method) do
143
+ return unless send if_method
144
+ send method_without_if
145
+ instance_eval &orig_block if orig_block
146
+ end
147
+ private method
148
+ end
149
+
150
+ commit_method = :"_sequel_after_commit_hook__actual_commit_#{method}"
151
+ define_method(commit_method) do
152
+ db.after_commit do
153
+ send method
154
+ instance_eval &block if block
155
+ end
156
+ end
157
+ private commit_method
158
+
159
+ case options[:on]
160
+ when :create
161
+ send :after_create, commit_method
162
+ when :update
163
+ send :after_update, commit_method
164
+ else
165
+ send :after_save, commit_method
166
+ end
167
+ end
168
+
169
+ private
170
+
171
+ def devise_validation_value(value)
172
+ value.respond_to?(:call) ? value.call : value
173
+ end
174
+ end
175
+ end
176
+ end
177
+ end
@@ -0,0 +1,5 @@
1
+ module Sequel
2
+ module Devise
3
+ VERSION = "0.0.14"
4
+ end
5
+ end
@@ -0,0 +1,10 @@
1
+ require "sequel"
2
+ require "sequel-devise/version"
3
+ require 'sequel/plugins/devise'
4
+ require 'orm_adapter-sequel'
5
+
6
+ module Sequel
7
+ module Devise
8
+ # Your code goes here...
9
+ end
10
+ end
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/sequel-devise/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Rodrigo Rosenfeld Rosas", "Eugen Kuksa"]
6
+ gem.email = ["kuksa.eugen@gmail.com"]
7
+ gem.description = %q{Updated Devise support for Sequel models}
8
+ gem.summary = %q{Enable Devise 4 and 5 support by adding plugin :devise to your Sequel Model}
9
+ gem.homepage = "https://github.com/brauliobo/sequel-devise"
10
+ gem.licenses = ["MIT"]
11
+ gem.required_ruby_version = ">= 2.7"
12
+
13
+ gem.files = `git ls-files`.split($\)
14
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
15
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
16
+ gem.name = "sequel-devise-updated"
17
+ gem.require_paths = ["lib"]
18
+ gem.version = Sequel::Devise::VERSION
19
+
20
+ gem.add_dependency 'sequel', '>= 3.11.0', '< 6'
21
+ gem.add_dependency 'devise', '>= 4', '< 6'
22
+ gem.add_dependency 'orm_adapter-sequel', '~> 0.1'
23
+ end
metadata ADDED
@@ -0,0 +1,104 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sequel-devise-updated
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.14
5
+ platform: ruby
6
+ authors:
7
+ - Rodrigo Rosenfeld Rosas
8
+ - Eugen Kuksa
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 1980-01-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: sequel
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 3.11.0
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '6'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: 3.11.0
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '6'
33
+ - !ruby/object:Gem::Dependency
34
+ name: devise
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '4'
40
+ - - "<"
41
+ - !ruby/object:Gem::Version
42
+ version: '6'
43
+ type: :runtime
44
+ prerelease: false
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: '4'
50
+ - - "<"
51
+ - !ruby/object:Gem::Version
52
+ version: '6'
53
+ - !ruby/object:Gem::Dependency
54
+ name: orm_adapter-sequel
55
+ requirement: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - "~>"
58
+ - !ruby/object:Gem::Version
59
+ version: '0.1'
60
+ type: :runtime
61
+ prerelease: false
62
+ version_requirements: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - "~>"
65
+ - !ruby/object:Gem::Version
66
+ version: '0.1'
67
+ description: Updated Devise support for Sequel models
68
+ email:
69
+ - kuksa.eugen@gmail.com
70
+ executables: []
71
+ extensions: []
72
+ extra_rdoc_files: []
73
+ files:
74
+ - ".gitignore"
75
+ - Gemfile
76
+ - LICENSE
77
+ - README.md
78
+ - Rakefile
79
+ - lib/sequel-devise.rb
80
+ - lib/sequel-devise/version.rb
81
+ - lib/sequel/plugins/devise.rb
82
+ - sequel-devise.gemspec
83
+ homepage: https://github.com/brauliobo/sequel-devise
84
+ licenses:
85
+ - MIT
86
+ metadata: {}
87
+ rdoc_options: []
88
+ require_paths:
89
+ - lib
90
+ required_ruby_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: '2.7'
95
+ required_rubygems_version: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ requirements: []
101
+ rubygems_version: 3.6.7
102
+ specification_version: 4
103
+ summary: Enable Devise 4 and 5 support by adding plugin :devise to your Sequel Model
104
+ test_files: []