Class List Method List File List

# Class: VertxWeb::MultiTenantHandler

Inherits:
  Object
  - Object
  - VertxWeb::MultiTenantHandler
  show all
Defined in:
  /Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-web/multi_tenant_handler.rb

## Overview

A handler which selectively executes another handler if a precondition is met. There are cases where applications are build as multi tenant, in this cases one of the common tasks is to configure different authentication mechanisms for each tenant. This handler will allow registering any other handler and will only execute it if the precondition is met. There are 2 way of defining a precondition:

- A http header value for example

      X-Tenant

- A custom extractor function that can return a String from the context

Requests that pass the validation will contain a new key in the routing context with the tenant id, for the case of being a default handler the value if this key will be "default".

## Constant Summary

@@j_api_type =

      Object.new

## Class Method Summary (collapse)

- + (Boolean) accept?(obj)
- + (::VertxWeb::MultiTenantHandler) create(param_1 = nil, param_2 = nil)
  Create a MultiTenant handler using a custom tenant extraction function.
- + (Object) j_api_type
- + (Object) j_class
- + (Object) TENANT
  The default key used to identify a tenant in the context data.
- + (Object) unwrap(obj)
- + (Object) wrap(obj)

## Instance Method Summary (collapse)

- - (self) add_default_handler { ... }
  Add a default handler for the case when no tenant was matched.
- - (self) add_tenant_handler(tenant = nil) { ... }
  Add a handler for a given tenant to this handler.
- - (void) handle(event = nil)
  Something has happened, so handle it.
- - (self) remove_tenant(tenant = nil)
  Remove a handler for a given tenant from this handler.

## Class Method Details

### + (`Boolean`) accept?(obj)

Returns:

- (`Boolean`)

    32
    33
    34
    # File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-web/multi_tenant_handler.rb', line 32

    def @@j_api_type.accept?(obj)
      obj.class == MultiTenantHandler
    end

### + (`::VertxWeb::MultiTenantHandler`) create(header) + (`::VertxWeb::MultiTenantHandler`) create(tenantExtractor) { ... } + (`::VertxWeb::MultiTenantHandler`) create(tenantExtractor, contextKey)

Create a MultiTenant handler using a custom tenant extraction function.

Overloads:

- + (`::VertxWeb::MultiTenantHandler`) create(header)

  Parameters:

  - header (`String`) —
    the header to lookup (e.g.: "X-Tenant")
- + (`::VertxWeb::MultiTenantHandler`) create(tenantExtractor) { ... }

  Yields:

  - the function that extracts the tenant id from the request
- + (`::VertxWeb::MultiTenantHandler`) create(tenantExtractor, contextKey)

  Parameters:

  - tenantExtractor (`Proc`) —
    the function that extracts the tenant id from the request
  - contextKey (`String`) —
    the custom key to store the tenant id in the context

Returns:

- (`::VertxWeb::MultiTenantHandler`) —
  the new handler.

Raises:

- (`ArgumentError`)

    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    # File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-web/multi_tenant_handler.rb', line 65

    def self.create(param_1=nil,param_2=nil)
      if param_1.class == String && !block_given? && param_2 == nil
        return ::Vertx::Util::Utils.safe_create(Java::IoVertxExtWebHandler::MultiTenantHandler.java_method(:create, [Java::java.lang.String.java_class]).call(param_1),::VertxWeb::MultiTenantHandler)
      elsif block_given? && param_1 == nil && param_2 == nil
        return ::Vertx::Util::Utils.safe_create(Java::IoVertxExtWebHandler::MultiTenantHandler.java_method(:create, [Java::JavaUtilFunction::Function.java_class]).call((Proc.new { |event| yield(::Vertx::Util::Utils.safe_create(event,::VertxWeb::RoutingContext)) })),::VertxWeb::MultiTenantHandler)
      elsif param_1.class == Proc && param_2.class == String && !block_given?
        return ::Vertx::Util::Utils.safe_create(Java::IoVertxExtWebHandler::MultiTenantHandler.java_method(:create, [Java::JavaUtilFunction::Function.java_class,Java::java.lang.String.java_class]).call((Proc.new { |event| param_1.call(::Vertx::Util::Utils.safe_create(event,::VertxWeb::RoutingContext)) }),param_2),::VertxWeb::MultiTenantHandler)
      end
      raise ArgumentError, "Invalid arguments when calling create(#{param_1},#{param_2})"
    end

### + (`Object`) j_api_type

    41
    42
    43
    # File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-web/multi_tenant_handler.rb', line 41

    def self.j_api_type
      @@j_api_type
    end

### + (`Object`) j_class

    44
    45
    46
    # File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-web/multi_tenant_handler.rb', line 44

    def self.j_class
      Java::IoVertxExtWebHandler::MultiTenantHandler.java_class
    end

### + (`Object`) TENANT

The default key used to identify a tenant in the context data.

    113
    114
    115
    # File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-web/multi_tenant_handler.rb', line 113

    def self.TENANT
      Java::IoVertxExtWebHandler::MultiTenantHandler.TENANT
    end

### + (`Object`) unwrap(obj)

    38
    39
    40
    # File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-web/multi_tenant_handler.rb', line 38

    def @@j_api_type.unwrap(obj)
      obj.j_del
    end

### + (`Object`) wrap(obj)

    35
    36
    37
    # File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-web/multi_tenant_handler.rb', line 35

    def @@j_api_type.wrap(obj)
      MultiTenantHandler.new(obj)
    end

## Instance Method Details

### - (`self`) add_default_handler { ... }

Add a default handler for the case when no tenant was matched. The handler cannot be null.

Yields:

- the handler to register.

Returns:

- (`self`)

Raises:

- (`ArgumentError`)

    105
    106
    107
    108
    109
    110
    111
    # File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-web/multi_tenant_handler.rb', line 105

    def add_default_handler
      if block_given?
        @j_del.java_method(:addDefaultHandler, [Java::IoVertxCore::Handler.java_class]).call((Proc.new { |event| yield(::Vertx::Util::Utils.safe_create(event,::VertxWeb::RoutingContext)) }))
        return self
      end
      raise ArgumentError, "Invalid arguments when calling add_default_handler()"
    end

### - (`self`) add_tenant_handler(tenant = nil) { ... }

Add a handler for a given tenant to this handler. Both tenant and handler cannot be null.

Parameters:

- tenant (`String`) (defaults to: `nil`) —
  the tenant id

Yields:

- the handler to register.

Returns:

- (`self`)

Raises:

- (`ArgumentError`)

    81
    82
    83
    84
    85
    86
    87
    # File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-web/multi_tenant_handler.rb', line 81

    def add_tenant_handler(tenant=nil)
      if tenant.class == String && block_given?
        @j_del.java_method(:addTenantHandler, [Java::java.lang.String.java_class,Java::IoVertxCore::Handler.java_class]).call(tenant,(Proc.new { |event| yield(::Vertx::Util::Utils.safe_create(event,::VertxWeb::RoutingContext)) }))
        return self
      end
      raise ArgumentError, "Invalid arguments when calling add_tenant_handler(#{tenant})"
    end

### - (`void`) handle(event = nil)

This method returns an undefined value.

Something has happened, so handle it.

Parameters:

- event (`::VertxWeb::RoutingContext`) (defaults to: `nil`) —
  the event to handle

Raises:

- (`ArgumentError`)

    50
    51
    52
    53
    54
    55
    # File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-web/multi_tenant_handler.rb', line 50

    def handle(event=nil)
      if event.class.method_defined?(:j_del) && !block_given?
        return @j_del.java_method(:handle, [Java::IoVertxExtWeb::RoutingContext.java_class]).call(event.j_del)
      end
      raise ArgumentError, "Invalid arguments when calling handle(#{event})"
    end

### - (`self`) remove_tenant(tenant = nil)

Remove a handler for a given tenant from this handler. Tenant cannot be null.

Parameters:

- tenant (`String`) (defaults to: `nil`) —
  the tenant id

Returns:

- (`self`)

Raises:

- (`ArgumentError`)

    93
    94
    95
    96
    97
    98
    99
    # File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-web/multi_tenant_handler.rb', line 93

    def remove_tenant(tenant=nil)
      if tenant.class == String && !block_given?
        @j_del.java_method(:removeTenant, [Java::java.lang.String.java_class]).call(tenant)
        return self
      end
      raise ArgumentError, "Invalid arguments when calling remove_tenant(#{tenant})"
    end