Last active
December 11, 2015 21:09
-
-
Save parndt/4660837 to your computer and use it in GitHub Desktop.
Devise multi-patcher
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# config/initializers/devise_patch.rb | |
require 'devise/version' | |
if !defined?(Devise::VERSION) || (Devise::VERSION < "1.4.0" && %w[1.2 1.3].all? {|v| !Devise::VERSION.start_with?(v)}) | |
raise "I don't know how to patch your devise version. See http://blog.plataformatec.com.br/2013/01/security-announcement-devise-v2-2-3-v2-1-3-v2-0-5-and-v1-5-3-released/" | |
end | |
if Devise::VERSION < "1.5.0" | |
warn "Patching devise #{Devise::VERSION} with < 1.5.0 patch" | |
Devise::Models::Authenticatable::ClassMethods.class_eval do | |
def auth_param_requires_string_conversion?(value); true; end | |
end | |
elsif [("1.5.0".."1.5.3"), ("2.0.0".."2.0.4"), ("2.1.0".."2.1.2"), ("2.2.0".."2.2.2")].any? { |range| | |
range.include?(Devise::VERSION) | |
} | |
warn "Patching devise #{Devise::VERSION} with < 2.2.3 patch" | |
Devise::ParamFilter.class_eval do | |
def param_requires_string_conversion?(_value); true; end | |
end | |
end |
@postmodern sure, I just whipped it up. I'll investigate those improvements!
The first warn
should still be a raise
.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Maybe it's just my style, but I like to use
warn
andString#start_with?
instead of Regexps.