0

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
blu
  • 12,905
  • 20
  • 70
  • 106
  • I don't have `ActiveSupport` installed, otherwise I would do it myself, but … why don't you just do it and see if it works? – Jörg W Mittag Aug 17 '15 at 20:37
  • I ran into this "alias_method_chain" issue while trying to use Devise as well. Did you ever try to patch it? – sivanes Oct 12 '15 at 20:49

1 Answers1

0

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
)
Roman Usherenko
  • 4,659
  • 4
  • 17
  • 14