John Smith
John Smith

Reputation: 6269

Override method Ruby

I would like to override the method: authorize_endpoint_url from the Gem in a Rails application: https://github.com/AzureAD/omniauth-azure-activedirectory/blob/master/lib/omniauth/strategies/azure_activedirectory.rb

I tried to do it by adding a file to config/initializers/oauth.rb

With the code:

module OmniAuth
  module Strategies
    # A strategy for authentication against Azure Active Directory.
    class AzureActiveDirectory
      def request_phase
        debugger
        "www.hans.com"
      end
    end
  end
end

But this approach doesn't seem to work, nothing get's actually overwriten. What do I wrong? Thank you

Upvotes: 1

Views: 81

Answers (1)

tadman
tadman

Reputation: 211740

When writing "monkey patch" style alterations you'll want to ensure they're loaded correctly. One way to test this is, after all is said and done, to interrogate Ruby to find out which method is actually being used:

OmniAuth::Strategies::AzureActiveDirectory.instance_method(:‌​request_phase).sourc‌​e_location

The instance_method call returns an object with information about that method and the source_location property tells you where that was defined.

If if's your method, great, you got it loaded right. If not you may need to check that you're hooking in at the correct time.

Upvotes: 2

Related Questions