Class: AWSCDK::Assertions::Capture

Inherits:
Matcher
  • Object
show all
Defined in:
assertions/capture.rb

Overview

Capture values while matching templates.

Using an instance of this class within a Matcher will capture the matching value. The as*() APIs on the instance can be used to get the captured value.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pattern = nil) ⇒ Capture

Initialize a new capture.

Parameters:

  • pattern (Object, nil) (defaults to: nil)

    a nested pattern or Matcher.



14
15
16
17
# File 'assertions/capture.rb', line 14

def initialize(pattern = nil)
  Jsii::Type.check_type(pattern, JSON.parse(Base64.strict_decode64("eyJwcmltaXRpdmUiOiJhbnkifQ==")), "pattern") unless pattern.nil?
  Jsii::Object.instance_method(:initialize).bind(self).call(pattern)
end

Class Method Details

.jsii_overridable_methodsObject



19
20
21
22
23
24
25
26
27
28
29
30
# File 'assertions/capture.rb', line 19

def self.jsii_overridable_methods
  {
    :name => { kind: :property, name: "name", is_optional: false },
    :test => { kind: :method, name: "test", is_optional: false },
    :as_array => { kind: :method, name: "asArray", is_optional: false },
    :as_boolean => { kind: :method, name: "asBoolean", is_optional: false },
    :as_number => { kind: :method, name: "asNumber", is_optional: false },
    :as_object => { kind: :method, name: "asObject", is_optional: false },
    :as_string => { kind: :method, name: "asString", is_optional: false },
    :_next => { kind: :method, name: "next", is_optional: false },
  }
end

Instance Method Details

#_nextBoolean

When multiple results are captured, move the iterator to the next result.

Returns:

  • (Boolean)

    true if another capture is present, false otherwise



101
102
103
# File 'assertions/capture.rb', line 101

def _next()
  jsii_call_method("next", [])
end

#as_arrayArray<Object>

Retrieve the captured value as an array.

An error is generated if no value is captured or if the value is not an array.

Returns:

  • (Array<Object>)


58
59
60
# File 'assertions/capture.rb', line 58

def as_array()
  jsii_call_method("asArray", [])
end

#as_booleanBoolean

Retrieve the captured value as a boolean.

An error is generated if no value is captured or if the value is not a boolean.

Returns:

  • (Boolean)


67
68
69
# File 'assertions/capture.rb', line 67

def as_boolean()
  jsii_call_method("asBoolean", [])
end

#as_numberNumeric

Retrieve the captured value as a number.

An error is generated if no value is captured or if the value is not a number.

Returns:

  • (Numeric)


76
77
78
# File 'assertions/capture.rb', line 76

def as_number()
  jsii_call_method("asNumber", [])
end

#as_objectHash{String => Object}

Retrieve the captured value as a JSON object.

An error is generated if no value is captured or if the value is not an object.

Returns:

  • (Hash{String => Object})


85
86
87
# File 'assertions/capture.rb', line 85

def as_object()
  jsii_call_method("asObject", [])
end

#as_stringString

Retrieve the captured value as a string.

An error is generated if no value is captured or if the value is not a string.

Returns:

  • (String)


94
95
96
# File 'assertions/capture.rb', line 94

def as_string()
  jsii_call_method("asString", [])
end

#nameString

A name for the matcher.

This is collected as part of the result and may be presented to the user.

Returns:

  • (String)


37
38
39
# File 'assertions/capture.rb', line 37

def name()
  jsii_get_property("name")
end

#test(actual) ⇒ AWSCDK::Assertions::MatchResult

Test whether a target matches the provided pattern.

Every Matcher must implement this method. This method will be invoked by the assertions framework. Do not call this method directly.

Parameters:

  • actual (Object)

Returns:



48
49
50
51
# File 'assertions/capture.rb', line 48

def test(actual)
  Jsii::Type.check_type(actual, JSON.parse(Base64.strict_decode64("eyJwcmltaXRpdmUiOiJhbnkifQ==")), "actual")
  jsii_call_method("test", [actual])
end