-1
代码方面:符号传递给“养”
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)
遇到了一些代码,其中一个符号传递给raise
传来:
raise(:invalid)
看起来不像有任何猴子补丁raise
来处理符号参数。似乎使用了fail
,如果我使用fail
,代码实际上可以工作。
这不只是为raise
的别名?这在任何情况下都有意义吗?
呀应该抛出'TypeError'与任一'fail'或'raise'。你能给更多的上下文吗?玩任何宝石? – hoffm
谢谢@hoffm。而且是啊,这就是我在想,上面贴一些额外的代码,实际上它只是一个自定义的策略制定 – Drew
@hoffm看起来像遗赠是使用语法在它的一些代码,以及 – Drew