Sha256: 3e1faf6c9564a79d78d2cea6b4daa63c745e4f96a1ec3f0f72d12ce95809135b

Contents?: true

Size: 1019 Bytes

Versions: 7

Compression:

Stored size: 1019 Bytes

Contents

require 'singleton'

module PansophyAuthenticator
  class ApplicationKeys
    include Singleton

    %i(own key valid? validate! clear_cache).each do |method|
      define_singleton_method(method) { |*args| instance.send(method, *args) }
    end

    def own
      key(configuration.application)
    end

    def key(application)
      matcher(application).key
    end

    def valid?(application, key)
      matcher(application).valid?(key)
    end

    def validate!(application, key)
      matcher(application).validate!(key)
    end

    def clear_cache
      cache.delete
    end

    private

    def matcher(application)
      Matcher.new(keys, application)
    end

    def keys
      cache.fetch { fetcher.keys }
    end

    def cache
      Cache.new(configuration.cache_store)
    end

    def fetcher
      if PansophyAuthenticator.remote?
        Remote::Fetcher.new
      else
        Local::Fetcher.new
      end
    end

    def configuration
      PansophyAuthenticator.configuration
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
pansophy_authenticator-0.5.0 lib/pansophy_authenticator/application_keys.rb
pansophy_authenticator-0.4.3 lib/pansophy_authenticator/application_keys.rb
pansophy_authenticator-0.4.2 lib/pansophy_authenticator/application_keys.rb
pansophy_authenticator-0.4.1 lib/pansophy_authenticator/application_keys.rb
pansophy_authenticator-0.4.0 lib/pansophy_authenticator/application_keys.rb
pansophy_authenticator-0.3.0 lib/pansophy_authenticator/application_keys.rb
pansophy_authenticator-0.2.0 lib/pansophy_authenticator/application_keys.rb