Can I use module#prepend instead of alias_method_chain to monkey patch this concern?

1k Views Asked by At

I am patching a concern in the 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?

Note: We are on 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
1

There are 1 best solutions below

0
On

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
)