oauthable.rb 624 B

12345678910111213141516171819202122232425262728293031
  1. module Oauthable
  2. extend ActiveSupport::Concern
  3. included do |base|
  4. @valid_oauth_providers = :all
  5. validates_presence_of :service_id
  6. end
  7. def oauthable?
  8. true
  9. end
  10. def valid_services_for(user)
  11. if valid_oauth_providers == :all
  12. user.available_services
  13. else
  14. user.available_services.where(provider: valid_oauth_providers)
  15. end
  16. end
  17. def valid_oauth_providers
  18. self.class.valid_oauth_providers
  19. end
  20. module ClassMethods
  21. def valid_oauth_providers(*providers)
  22. return @valid_oauth_providers if providers == []
  23. @valid_oauth_providers = providers
  24. end
  25. end
  26. end