oauthable.rb 656 B

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