Skip to content

Instantly share code, notes, and snippets.

@parndt
Last active December 11, 2015 21:09
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save parndt/4660837 to your computer and use it in GitHub Desktop.
Save parndt/4660837 to your computer and use it in GitHub Desktop.
Devise multi-patcher
# 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
Copy link

Maybe it's just my style, but I like to use warn and String#start_with? instead of Regexps.

@parndt
Copy link
Author

parndt commented Jan 29, 2013

@postmodern sure, I just whipped it up. I'll investigate those improvements!

@postmodern
Copy link

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