Class: Metatron::Templates::HTTPRoute::Rule

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

Overview

Internal model for an HTTPRoute rule

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(backend_refs:, matches: nil) ⇒ Rule

Returns a new instance of Rule.



11
12
13
14
15
# File 'lib/metatron/templates/http_route/rule.rb', line 11

def initialize(backend_refs:, matches: nil)
  @backend_refs = backend_refs
  @matches = matches
  @filters = []
end

Instance Attribute Details

#backend_refsObject

Returns the value of attribute backend_refs.



8
9
10
# File 'lib/metatron/templates/http_route/rule.rb', line 8

def backend_refs
  @backend_refs
end

#filtersObject (readonly)

Returns the value of attribute filters.



9
10
11
# File 'lib/metatron/templates/http_route/rule.rb', line 9

def filters
  @filters
end

#matchesObject

Returns the value of attribute matches.



8
9
10
# File 'lib/metatron/templates/http_route/rule.rb', line 8

def matches
  @matches
end

Instance Method Details

#add_filter(filter = nil, **attrs) ⇒ Object



17
18
19
20
21
22
23
# File 'lib/metatron/templates/http_route/rule.rb', line 17

def add_filter(filter = nil, **attrs)
  @filters << if filter.is_a?(Filter)
                filter
              else
                Filter.new(**attrs)
              end
end

#renderObject



25
26
27
28
29
# File 'lib/metatron/templates/http_route/rule.rb', line 25

def render
  { backendRefs: backend_refs }
    .merge(matches ? { matches: } : {})
    .merge(filters.empty? ? {} : { filters: filters.map(&:render) })
end