Sha256: 550cdecec2f41be02c1b4693f2f230a9e174f32e04ed65dd9b33504422df78ef

Contents?: true

Size: 1002 Bytes

Versions: 1

Compression:

Stored size: 1002 Bytes

Contents

# Provide list of supported providers with metadata (title, icon)
# Detect provider usage in hosting app
module Vxod
  class OmniAuthProvider
    def initialize(name, icon, title)
      @name = name
      @icon = icon
      @title = title
    end

    attr_reader :name, :icon, :title

    def show?
      @show ||= begin
        OmniAuth::Strategies.const_get("#{OmniAuth::Utils.camelize(name.to_s)}")
        true
      rescue NameError
        false
      end
    end

    def href
      "#{OmniAuth.config.path_prefix}/#{name}"
    end

    def self.any?
      all.any?{ |provider| provider.show? }
    end

    def self.all
      @all ||= [
        [:vkontakte, 'fa-vk', 'Login with vk.com'],
        [:twitter, 'fa-twitter', 'Login with Twitter'],
        [:facebook, 'fa-facebook', 'Login with Facebook'],
        [:google_oauth2, 'fa-google-plus', 'Login with Google'],
        [:github, 'fa-github-alt', 'Login with Github'],
      ].map{ |data| OmniAuthProvider.new(*data) }
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
vxod-0.0.2 lib/vxod/omni_auth_provider.rb