Class: Metatron::Templates::HTTPRoute::Filter

Inherits:
Object
  • Object
show all
Defined in:
lib/metatron/templates/http_route/filter.rb

Overview

Internal model for an HTTPRoute filter. The type must be the canonical CamelCase name (e.g. "URLRewrite", "RequestHeaderModifier"). All remaining keyword arguments become the type-specific configuration nested under the auto-derived camelCase key.

Example:

Filter.new(
type: "URLRewrite",
hostname: "example.net",
path: { type: "ReplacePrefixMatch", replacePrefixMatch: "/new-prefix" }
)
# => { type: "URLRewrite", urlRewrite: { hostname: "example.net", path: { ... } } }

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type:, **config) ⇒ Filter

Returns a new instance of Filter.



21
22
23
24
# File 'lib/metatron/templates/http_route/filter.rb', line 21

def initialize(type:, **config)
  @type = type
  @config = config
end

Instance Attribute Details

#configObject

Returns the value of attribute config.



19
20
21
# File 'lib/metatron/templates/http_route/filter.rb', line 19

def config
  @config
end

#typeObject

Returns the value of attribute type.



19
20
21
# File 'lib/metatron/templates/http_route/filter.rb', line 19

def type
  @type
end

Instance Method Details

#renderObject



26
27
28
# File 'lib/metatron/templates/http_route/filter.rb', line 26

def render
  { type: }.merge(config.empty? ? {} : { type_key => config })
end