Class: Metatron::Templates::GRPCRoute::Rule
- Inherits:
-
Object
- Object
- Metatron::Templates::GRPCRoute::Rule
- Defined in:
- lib/metatron/templates/grpc_route/rule.rb
Overview
Internal model for a GRPCRoute rule
Instance Attribute Summary collapse
-
#backend_refs ⇒ Object
Returns the value of attribute backend_refs.
-
#filters ⇒ Object
readonly
Returns the value of attribute filters.
-
#matches ⇒ Object
Returns the value of attribute matches.
Instance Method Summary collapse
- #add_filter(filter = nil, **attrs) ⇒ Object
-
#initialize(backend_refs:, matches: nil) ⇒ Rule
constructor
A new instance of Rule.
- #render ⇒ Object
Constructor Details
#initialize(backend_refs:, matches: nil) ⇒ Rule
Returns a new instance of Rule.
11 12 13 14 15 |
# File 'lib/metatron/templates/grpc_route/rule.rb', line 11 def initialize(backend_refs:, matches: nil) @backend_refs = backend_refs @matches = matches @filters = [] end |
Instance Attribute Details
#backend_refs ⇒ Object
Returns the value of attribute backend_refs.
8 9 10 |
# File 'lib/metatron/templates/grpc_route/rule.rb', line 8 def backend_refs @backend_refs end |
#filters ⇒ Object (readonly)
Returns the value of attribute filters.
9 10 11 |
# File 'lib/metatron/templates/grpc_route/rule.rb', line 9 def filters @filters end |
#matches ⇒ Object
Returns the value of attribute matches.
8 9 10 |
# File 'lib/metatron/templates/grpc_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/grpc_route/rule.rb', line 17 def add_filter(filter = nil, **attrs) @filters << if filter.is_a?(Filter) filter else Filter.new(**attrs) end end |
#render ⇒ Object
25 26 27 28 29 |
# File 'lib/metatron/templates/grpc_route/rule.rb', line 25 def render { backendRefs: backend_refs } .merge(matches ? { matches: } : {}) .merge(filters.empty? ? {} : { filters: filters.map(&:render) }) end |