File: error_rule.rb

package info (click to toggle)
ruby-aws-sdk-core 3.168.1-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,924 kB
  • sloc: ruby: 15,292; makefile: 4
file content (37 lines) | stat: -rw-r--r-- 979 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# frozen_string_literal: true

module Aws
  module Endpoints
    # @api private
    class ErrorRule < Rule
      def initialize(type: 'error', conditions:, error: nil, documentation: nil)
        @type = type
        @conditions = Condition.from_json(conditions)
        @error = error
        @documentation = documentation
      end

      attr_reader :type
      attr_reader :conditions
      attr_reader :error
      attr_reader :documentation

      def match(parameters, assigned = {})
        assigns = assigned.dup
        matched = conditions.all? do |condition|
          output = condition.match?(parameters, assigns)
          assigns = assigns.merge(condition.assigned) if condition.assign
          output
        end
        resolved_error(parameters, assigns) if matched
      end

      private

      def resolved_error(parameters, assigns)
        error = resolve_value(@error, parameters, assigns)
        ArgumentError.new(error)
      end
    end
  end
end