oauthable.rb 706 B

12345678910111213141516171819202122232425262728293031323334353637
  1. module Oauthable
  2. extend ActiveSupport::Concern
  3. included do |base|
  4. @valid_oauth_providers = :all
  5. validate :validate_service
  6. end
  7. def oauthable?
  8. true
  9. end
  10. def validate_service
  11. if !service
  12. errors.add(:service, :blank)
  13. end
  14. end
  15. def valid_services_for(user)
  16. if valid_oauth_providers == :all
  17. user.available_services
  18. else
  19. user.available_services.where(provider: valid_oauth_providers)
  20. end
  21. end
  22. def valid_oauth_providers
  23. self.class.valid_oauth_providers
  24. end
  25. module ClassMethods
  26. def valid_oauth_providers(*providers)
  27. return @valid_oauth_providers if providers == []
  28. @valid_oauth_providers = providers
  29. end
  30. end
  31. end