-1

Code for context:

module Devise
  module Strategies
    class AuthxAuthenticatable < Authenticatable
      def valid?
        !params[scope].nil?
      end

      def authenticate!
        resource = mapping.to.authenticate_with_credentials(params[scope])
        return fail(:invalid) if resource.nil?
        success!(resource) if validate(resource)
      end
    end
  end
end

Warden::Strategies.add(:authx_authenticatable, Devise::Strategies::AuthxAuthenticatable)

Came across some code where a symbol is passed to raise:

raise(:invalid)

Doesn't look like there's any monkey patching of raise to handle symbol arguments. Seems like fail used to be used, and the code actually works if I use fail.

Isn't that just an alias for raise? Does this make sense in any context?

sawa
  • 165,429
  • 45
  • 277
  • 381
Drew
  • 2,583
  • 5
  • 36
  • 54
  • Yeah that should throw a `TypeError` with either `fail` or `raise`. Can you give more context? Any gems at play? – hoffm Oct 18 '17 at 15:48
  • Thanks @hoffm. And yeah that's what I was thinking, posted some additional code above, essentially it's just a custom strategy for Devise – Drew Oct 18 '17 at 15:50
  • @hoffm looks like devise is using that syntax in some of its code as well – Drew Oct 18 '17 at 15:53
  • What version of Devise are you using? Looks like the latest doesn't do that https://github.com/plataformatec/devise/search?q=%22raise%22&type=&utf8=%E2%9C%93 – hoffm Oct 18 '17 at 15:54
  • @hoffm looks like it's mapped to the https://github.com/plataformatec/devise/blob/master/config/locales/en.yml file – Drew Oct 18 '17 at 15:55
  • @hoffm sorry, looks like they're using it with the fail method https://github.com/plataformatec/devise/blob/88724e10adaf9ffd1d8dbfbaadda2b9d40de756a/lib/devise/strategies/database_authenticatable.rb#L18 – Drew Oct 18 '17 at 15:56
  • Ah, so it's just an implicit localization of a string then? – hoffm Oct 18 '17 at 15:56
  • Must be something to that effect, but wouldn't the fail method have to be redefined somewhere to use a mapping scheme? Maybe they have their own gem at play... – Drew Oct 18 '17 at 15:57
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/157016/discussion-between-drew-and-hoffm). – Drew Oct 18 '17 at 15:58

1 Answers1

0

Looks like the fail method being used was the warden method:

http://www.rubydoc.info/github/hassox/warden/Warden%2FStrategies%2FBase:fail

Drew
  • 2,583
  • 5
  • 36
  • 54