简体   繁体   中英

Class name conflicts in module

I am implementing a client web application that connects to an API using Omniauth, following instruction here

I have a class defined in a nested module in /lib/omniauth/strategies/testservice.rb

module OmniAuth:: Strategies
    class Testservice < OmniAuth::Strategies::OAuth2
      option :name, :testservice
    end
end

When I invoke the following in Rails console:

require File.expand_path('lib/omniauth/strategies/testservice', Rails.root)

it will fail.

However, if I shorten the name of the class Testservice to a single word, such as Test , then it works.

I suspect that my class name conflicts with Rails naming convention. I can't create the class name as TestService due to some constraints from Omniauth gem.

How can I overcome this issue?

In case of conflicts use fully qualified class name ie along with the package name something like com.test.Test . It will help you to avoid the conflicts

Adding OmniAuth.config.add_camelization 'testservice', 'TestService fixes the issue. See more here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM