[英]Can I use module#prepend instead of alias_method_chain to monkey patch this concern?
I am patching a concern in the Devise Token Auth gem . 我正在修正Devise Token Auth gem中的问题 。
I have it working with alias_method_chain
but am wondering if I can use module#prepend
instead in this scenario? 我可以通过
alias_method_chain
使用它,但想知道在这种情况下是否可以使用module#prepend
代替?
Note: We are on ruby 2.2.x 注意:我们使用的是ruby 2.2.x
Existing: 现有:
DeviseTokenAuth::Concerns::User.module_eval do
def token_validation_response_with_customer_info
json = token_validation_response_without_customer_info
# add some customer stuff based on has_role? check
json
end
alias_method_chain :token_validation_response, :customer_info
end
You can try 你可以试试
DeviseTokenAuth::Concerns::User.prepend(
Module.new do
def token_validation_response
json = super
# add some customer stuff based on has_role? check
json
end
end
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.