-
Notifications
You must be signed in to change notification settings - Fork 231
Allow for custom providers with multi-word class names. #190
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow for custom providers with multi-word class names. #190
Conversation
Currently sorcery will not handle custom providers with names like: ExampleProvider. config.example_provider would search for a class called Example_provider rather than ExampleProvider. Using .classify rather than .capitalize will fix this. I've added an example provider implementation under the spec/support directory, and have a test that ensures that it is loaded properly via config. The existing tests for existing providers are also coming back with successes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Amazing work! Could you also add a spec for one-word-provider to be cover it 100%?
lib/sorcery/version.rb
Outdated
| @@ -1,3 +1,3 @@ | |||
| module Sorcery | |||
| VERSION = '0.14.0'.freeze | |||
| VERSION = '0.15.0'.freeze | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure if we want to change version.
|
@chhga Thanks! I've added a spec to cover single-word custom providers. I've also reverted the version back to 0.14.0. |
* set version back to 0.14.0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm. @athix fyi
|
@chhga Yup, looks good to me as well. Merging. |
|
curious @mvandenbeuken did you add a custom provider without forking the gem and adding it into the submodule folder? (if so would be great to know details of how) |
|
@murtali I'd imagine you should be able to require your custom provider, and as long as it's conformant to the standard the rest of the providers follow, and you add it to the providers list in your config, it should work. |
|
@athix -- hmm I tried doing the following: and then in and it's throwing the following error when I tried starting the rails server: it seems to be looking for submodule in the gem source? Should I be doing this in another way? (thanks again for the response here) |
|
@murtali You need to tell the application where it can find that class: Currently Sorcery tries to autoload that constant, but fails to find the class because neither your application nor Sorcery provides it. Within config.autoload_paths += %W(#{config.root}/lib)As for getting it to auto discover the class within lib, I'm honestly not sure what the best approach would be. It's been a while since I've added a class to an already existing/loaded module. I don't know if it might get confused because the Sorcery::Providers module already has been loaded...What may work if Ruby works the way I would hope it would in this scenario, is: # lib/sorcery.rb
module Sorcery
autoload :Providers, 'sorcery/providers'
end# lib/sorcery/providers.rb
module Sorcery
module Providers
autoload :MyCustomProvider, 'sorcery/providers/my_custom_provider'
end
end# lib/sorcery/providers/my_custom_provider.rb
class Sorcery::Providers::MyCustomProvider < Sorcery::Providers::Base
# [...]
end |
Currently sorcery will not handle custom providers with names like: ExampleProvider. config.example_provider would search for a class called Example_provider rather than ExampleProvider. Using .classify rather than .capitalize will fix this.
I've added an example provider implementation under the spec/support directory, and have a test that ensures that it is loaded properly via config. The existing tests for existing providers are also coming back with successes.