Class List Method List File List

# Class: VertxWeb::Route

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

## Overview

A route is a holder for a set of criteria which determine whether an HTTP request or failure should be routed to a handler.

## Constant Summary

@@j_api_type =

      Object.new

## Class Method Summary (collapse)

- + (Boolean) accept?(obj)
- + (Object) j_api_type
- + (Object) j_class
- + (Object) unwrap(obj)
- + (Object) wrap(obj)

## Instance Method Summary (collapse)

- - (self) blocking_handler(requestHandler = nil, ordered = nil)
  Specify a blocking request handler for the route.
- - (self) consumes(contentType = nil)
  Add a content type consumed by this route.
- - (self) disable
  Disable this route.
- - (self) enable
  Enable this route.
- - (self) failure_handler { ... }
  Append a failure handler to the route failure handlers list.
- - (String) get_path
  The path prefix (if any) for this route.
- - (self) handler { ... }
  Append a request handler to the route handlers list.
- - (self) last
  Specify this is the last route for the router.
- - (self) method(method = nil)
  Add an HTTP method for this route.
- - (Set<:OPTIONS,:GET,:HEAD,:POST,:PUT,:DELETE,:TRACE,:CONNECT,:PATCH,:OTHER>) methods
  The http methods accepted by this route.
- - (self) order(order = nil)
  Specify the order for this route.
- - (self) path(path = nil)
  Set the path prefix for this route.
- - (self) path_regex(path = nil)
  Set the path prefix as a regular expression.
- - (self) produces(contentType = nil)
  Add a content type produced by this route.
- - (true, false) regex_path?
  Returns true of the path is a regular expression, this includes expression paths.
- - (self) remove
  Remove this route from the router.
- - (self) set_regex_groups_names(groups = nil)
  When you add a new route with a regular expression, you can add named capture groups for parameters.
- - (self) sub_router(subRouter = nil)
  Use a (sub) Router as a handler.
- - (self) use_normalised_path(useNormalisedPath = nil)
  If true then the normalised request path will be used when routing (e.g. removing duplicate /) Default is true.

## Class Method Details

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

Returns:

- (`Boolean`)

    20
    21
    22
    # File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-web/route.rb', line 20

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

### + (`Object`) j_api_type

    29
    30
    31
    # File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-web/route.rb', line 29

    def self.j_api_type
      @@j_api_type
    end

### + (`Object`) j_class

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

    def self.j_class
      Java::IoVertxExtWeb::Route.java_class
    end

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

    26
    27
    28
    # File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-web/route.rb', line 26

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

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

    23
    24
    25
    # File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-web/route.rb', line 23

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

## Instance Method Details

### - (`self`) blocking_handler(requestHandler = nil, ordered = nil)

Specify a blocking request handler for the route. This method works just like #handler excepted that it will run the blocking handler on a worker thread so that it won't block the event loop. Note that it's safe to call context.next() from the blocking handler as it will be executed on the event loop context (and not on the worker thread. If the blocking handler is ordered it means that any blocking handlers for the same context are never executed concurrently but always in the order they were called. The default value of ordered is true. If you do not want this behaviour and don't mind if your blocking handlers are executed in parallel you can set ordered to false.

Parameters:

- requestHandler (`Proc`) (defaults to: `nil`) —
  the blocking request handler
- ordered (`true`, `false`) (defaults to: `nil`) —
  if true handlers are executed in sequence, otherwise are run in parallel

Returns:

- (`self`)

Raises:

- (`ArgumentError`)

    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    # File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-web/route.rb', line 130

    def blocking_handler(requestHandler=nil,ordered=nil)
      if block_given? && requestHandler == nil && ordered == nil
        @j_del.java_method(:blockingHandler, [Java::IoVertxCore::Handler.java_class]).call((Proc.new { |event| yield(::Vertx::Util::Utils.safe_create(event,::VertxWeb::RoutingContext)) }))
        return self
      elsif requestHandler.class == Proc && (ordered.class == TrueClass || ordered.class == FalseClass) && !block_given?
        @j_del.java_method(:blockingHandler, [Java::IoVertxCore::Handler.java_class,Java::boolean.java_class]).call((Proc.new { |event| requestHandler.call(::Vertx::Util::Utils.safe_create(event,::VertxWeb::RoutingContext)) }),ordered)
        return self
      end
      raise ArgumentError, "Invalid arguments when calling blocking_handler(#{requestHandler},#{ordered})"
    end

### - (`self`) consumes(contentType = nil)

Add a content type consumed by this route. Used for content based routing.

Parameters:

- contentType (`String`) (defaults to: `nil`) —
  the content type

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/route.rb', line 81

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

### - (`self`) disable

Disable this route. While disabled the router will not route any requests or failures to it.

Returns:

- (`self`)

Raises:

- (`ArgumentError`)

    181
    182
    183
    184
    185
    186
    187
    # File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-web/route.rb', line 181

    def disable
      if !block_given?
        @j_del.java_method(:disable, []).call()
        return self
      end
      raise ArgumentError, "Invalid arguments when calling disable()"
    end

### - (`self`) enable

Enable this route.

Returns:

- (`self`)

Raises:

- (`ArgumentError`)

    190
    191
    192
    193
    194
    195
    196
    # File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-web/route.rb', line 190

    def enable
      if !block_given?
        @j_del.java_method(:enable, []).call()
        return self
      end
      raise ArgumentError, "Invalid arguments when calling enable()"
    end

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

Append a failure handler to the route failure handlers list. The router routes failures to failurehandlers depending on whether the various criteria such as method, path, etc match. When method, path, etc are the same for different routes, You should add multiple failure handlers to the same route object rather than creating two different routes objects with one failure handler for route

Yields:

- the request handler

Returns:

- (`self`)

Raises:

- (`ArgumentError`)

    163
    164
    165
    166
    167
    168
    169
    # File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-web/route.rb', line 163

    def failure_handler
      if block_given?
        @j_del.java_method(:failureHandler, [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 failure_handler()"
    end

### - (`String`) get_path

Returns the path prefix (if any) for this route

Returns:

- (`String`) —
  the path prefix (if any) for this route

Raises:

- (`ArgumentError`)

    209
    210
    211
    212
    213
    214
    # File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-web/route.rb', line 209

    def get_path
      if !block_given?
        return @j_del.java_method(:getPath, []).call()
      end
      raise ArgumentError, "Invalid arguments when calling get_path()"
    end

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

Append a request handler to the route handlers list. The router routes requests to handlers depending on whether the various criteria such as method, path, etc match. When method, path, etc are the same for different routes, You should add multiple handlers to the same route object rather than creating two different routes objects with one handler for route

Yields:

- the request handler

Returns:

- (`self`)

Raises:

- (`ArgumentError`)

    112
    113
    114
    115
    116
    117
    118
    # File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-web/route.rb', line 112

    def handler
      if block_given?
        @j_del.java_method(:handler, [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 handler()"
    end

### - (`self`) last

Specify this is the last route for the router.

Returns:

- (`self`)

Raises:

- (`ArgumentError`)

    100
    101
    102
    103
    104
    105
    106
    # File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-web/route.rb', line 100

    def last
      if !block_given?
        @j_del.java_method(:last, []).call()
        return self
      end
      raise ArgumentError, "Invalid arguments when calling last()"
    end

### - (`self`) method(method = nil)

Add an HTTP method for this route. By default a route will match all HTTP methods. If any are specified then the route will only match any of the specified methods

Parameters:

- method (`:OPTIONS`, `:GET`, `:HEAD`, `:POST`, `:PUT`, `:DELETE`, `:TRACE`, `:CONNECT`, `:PATCH`, `:OTHER`) (defaults to: `nil`) —
  the HTTP method to add

Returns:

- (`self`)

Raises:

- (`ArgumentError`)

    39
    40
    41
    42
    43
    44
    45
    # File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-web/route.rb', line 39

    def method(method=nil)
      if method.class == Symbol && !block_given?
        @j_del.java_method(:method, [Java::IoVertxCoreHttp::HttpMethod.java_class]).call(Java::IoVertxCoreHttp::HttpMethod.valueOf(method.to_s))
        return self
      end
      raise ArgumentError, "Invalid arguments when calling method(#{method})"
    end

### - (`Set<:OPTIONS,:GET,:HEAD,:POST,:PUT,:DELETE,:TRACE,:CONNECT,:PATCH,:OTHER>`) methods

Returns the http methods accepted by this route

Returns:

- (`Set<:OPTIONS,:GET,:HEAD,:POST,:PUT,:DELETE,:TRACE,:CONNECT,:PATCH,:OTHER>`) —
  the http methods accepted by this route

Raises:

- (`ArgumentError`)

    224
    225
    226
    227
    228
    229
    # File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-web/route.rb', line 224

    def methods
      if !block_given?
        return ::Vertx::Util::Utils.to_set(@j_del.java_method(:methods, []).call()).map! { |elt| elt.name.intern }
      end
      raise ArgumentError, "Invalid arguments when calling methods()"
    end

### - (`self`) order(order = nil)

Specify the order for this route. The router tests routes in that order.

Parameters:

- order (`Fixnum`) (defaults to: `nil`) —
  the order

Returns:

- (`self`)

Raises:

- (`ArgumentError`)

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

    def order(order=nil)
      if order.class == Fixnum && !block_given?
        @j_del.java_method(:order, [Java::int.java_class]).call(order)
        return self
      end
      raise ArgumentError, "Invalid arguments when calling order(#{order})"
    end

### - (`self`) path(path = nil)

Set the path prefix for this route. If set then this route will only match request URI paths which start with this path prefix. Only a single path or path regex can be set for a route.

Parameters:

- path (`String`) (defaults to: `nil`) —
  the path prefix

Returns:

- (`self`)

Raises:

- (`ArgumentError`)

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

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

### - (`self`) path_regex(path = nil)

Set the path prefix as a regular expression. If set then this route will only match request URI paths, the beginning of which match the regex. Only a single path or path regex can be set for a route.

Parameters:

- path (`String`) (defaults to: `nil`) —
  the path regex

Returns:

- (`self`)

Raises:

- (`ArgumentError`)

    61
    62
    63
    64
    65
    66
    67
    # File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-web/route.rb', line 61

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

### - (`self`) produces(contentType = nil)

Add a content type produced by this route. Used for content based routing.

Parameters:

- contentType (`String`) (defaults to: `nil`) —
  the content type

Returns:

- (`self`)

Raises:

- (`ArgumentError`)

    71
    72
    73
    74
    75
    76
    77
    # File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-web/route.rb', line 71

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

### - (`true`, `false`) regex_path?

Returns true of the path is a regular expression, this includes expression paths.

Returns:

- (`true`, `false`) —
  true if backed by a pattern.

Raises:

- (`ArgumentError`)

    217
    218
    219
    220
    221
    222
    # File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-web/route.rb', line 217

    def regex_path?
      if !block_given?
        return @j_del.java_method(:isRegexPath, []).call()
      end
      raise ArgumentError, "Invalid arguments when calling regex_path?()"
    end

### - (`self`) remove

Remove this route from the router

Returns:

- (`self`)

Raises:

- (`ArgumentError`)

    172
    173
    174
    175
    176
    177
    178
    # File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-web/route.rb', line 172

    def remove
      if !block_given?
        @j_del.java_method(:remove, []).call()
        return self
      end
      raise ArgumentError, "Invalid arguments when calling remove()"
    end

### - (`self`) set_regex_groups_names(groups = nil)

When you add a new route with a regular expression, you can add named capture groups for parameters.
However, if you need more complex parameters names (like "param_name"), you can add parameters names with this function. You have to name capture groups in regex with names: "p0", "p1", "p2", ...
For example: If you declare route with regex \/(?[a-z]*)\/(?[a-z]*) and group names ["param_a", "param-b"] for uri /hello/world you receive inside pathParams() the parameter param_a = "hello"

Parameters:

- groups (`Array<String>`) (defaults to: `nil`) —
  group names

Returns:

- (`self`)

Raises:

- (`ArgumentError`)

    238
    239
    240
    241
    242
    243
    244
    # File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-web/route.rb', line 238

    def set_regex_groups_names(groups=nil)
      if groups.class == Array && !block_given?
        @j_del.java_method(:setRegexGroupsNames, [Java::JavaUtil::List.java_class]).call(groups.map { |element| element })
        return self
      end
      raise ArgumentError, "Invalid arguments when calling set_regex_groups_names(#{groups})"
    end

### - (`self`) sub_router(subRouter = nil)

Use a (sub) VertxWeb::Router as a handler. There are several requirements to be fulfilled for this to be accepted.

- The route path must end with a wild card
- Parameters are allowed but full regex patterns not
- No other handler can be registered before or after this call (but they can on a new route object for the same path)
- Only 1 router per path object

Parameters:

- subRouter (`::VertxWeb::Router`) (defaults to: `nil`) —
  the router to add

Returns:

- (`self`)

Raises:

- (`ArgumentError`)

    151
    152
    153
    154
    155
    156
    157
    # File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-web/route.rb', line 151

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

### - (`self`) use_normalised_path(useNormalisedPath = nil)

If true then the normalised request path will be used when routing (e.g. removing duplicate /) Default is true

Parameters:

- useNormalisedPath (`true`, `false`) (defaults to: `nil`) —
  use normalised path for routing?

Returns:

- (`self`)

Raises:

- (`ArgumentError`)

    201
    202
    203
    204
    205
    206
    207
    # File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-web/route.rb', line 201

    def use_normalised_path(useNormalisedPath=nil)
      if (useNormalisedPath.class == TrueClass || useNormalisedPath.class == FalseClass) && !block_given?
        @j_del.java_method(:useNormalisedPath, [Java::boolean.java_class]).call(useNormalisedPath)
        return self
      end
      raise ArgumentError, "Invalid arguments when calling use_normalised_path(#{useNormalisedPath})"
    end