Sha256: 9e4402c3f113a9b55b46ec11d8b72b58dda4e1d7e248ee1a5c6d447fe403010d

Contents?: true

Size: 1.69 KB

Versions: 51

Compression:

Stored size: 1.69 KB

Contents

class Jets::Router::Route
  module Authorizer
    # IE: main#protect => MainProtectAuthorizer
    def authorizer_id(prefix_class: true)
      return unless authorizer
      logical_id(authorizer, prefix_class: prefix_class)
    end

    # Metadata about the authorizer class that can be used later. Stored in the Authorizer template parameters.
    # In app_class.rb `def controller_params` it is used to build the input parameters for controller templates.
    def authorizer_metadata
      metadata(authorizer)
    end

    def authorizer
      @options[:authorizer]
    end

    def authorization_scopes
      @options[:authorization_scopes]
    end

    def authorization_type
      @options[:authorization_type] || inferred_authorization_type
    end

    def api_key_required
      @options[:api_key_required]
    end

    module ModuleMethods
      def logical_id(authorizer, prefix_class: true)
        klass, meth = authorizer.split("#")
        words = [meth, "authorizer"]
        words.unshift(klass) if prefix_class
        words.join('_').camelize # logical_id
      end

      def metadata(authorizer)
        klass = authorizer.split("#").first
        authorizer_class = "#{klass}_authorizer".camelize
        logical_id = logical_id(authorizer, prefix_class: false)
        # IE: MainAuthorizer.ProtectAuthorizer
        "#{authorizer_class}.#{logical_id}"
      end
    end
    include ModuleMethods # so available as instance methods
    extend ModuleMethods # so also available as module method. IE: Jets::Router::Route::Authorizer.metadata(auth_to)

  private
    def inferred_authorization_type
      return unless authorizer
      Jets::Authorizer::Base.authorization_type(authorizer)
    end

  end
end

Version data entries

51 entries across 51 versions & 2 rubygems

Version Path
jets-4.0.12 lib/jets/router/route/authorizer.rb
jets-4.0.11 lib/jets/router/route/authorizer.rb
jets-4.0.10 lib/jets/router/route/authorizer.rb
jets-4.0.9 lib/jets/router/route/authorizer.rb
jets-4.0.8 lib/jets/router/route/authorizer.rb
jets-4.0.7 lib/jets/router/route/authorizer.rb
jets-4.0.6 lib/jets/router/route/authorizer.rb
jets-4.0.5 lib/jets/router/route/authorizer.rb
jets-4.0.4 lib/jets/router/route/authorizer.rb
jets-4.0.3 lib/jets/router/route/authorizer.rb
jets-4.0.2 lib/jets/router/route/authorizer.rb
jets-4.0.1 lib/jets/router/route/authorizer.rb
jets-4.0.0 lib/jets/router/route/authorizer.rb
jets-3.2.2 lib/jets/router/route/authorizer.rb
jets-3.2.1 lib/jets/router/route/authorizer.rb
jets.benforeva-3.0.17.pre.mount.pre.fix lib/jets/router/route/authorizer.rb
jets-3.2.0 lib/jets/router/route/authorizer.rb
jets-3.1.5 lib/jets/router/route/authorizer.rb
jets-3.1.4 lib/jets/router/route/authorizer.rb
jets-3.1.3 lib/jets/router/route/authorizer.rb