Class: Pact::Matchers::Base
Overview
Direct Known Subclasses
V1::Equality, V2::Regex, V2::Type, V3::Boolean, V3::ContentType, V3::Date, V3::DateTime, V3::Decimal, V3::Each, V3::Include, V3::Integer, V3::Null, V3::Number, V3::Semver, V3::Time, V3::Values, V4::EachKey, V4::EachKeyValue, V4::EachValue, V4::NotEmpty, V4::StatusCode
Defined Under Namespace
Classes: MatcherInitializationError
Instance Attribute Summary collapse
-
#kind ⇒ Object
readonly
Returns the value of attribute kind.
-
#opts ⇒ Object
readonly
Returns the value of attribute opts.
-
#spec_version ⇒ Object
readonly
Returns the value of attribute spec_version.
-
#template ⇒ Object
readonly
Returns the value of attribute template.
Instance Method Summary collapse
- #as_basic ⇒ Object
- #as_plugin ⇒ Object
-
#initialize(spec_version:, kind:, template: nil, opts: {}) ⇒ Base
constructor
A new instance of Base.
Constructor Details
#initialize(spec_version:, kind:, template: nil, opts: {}) ⇒ Base
Returns a new instance of Base.
11 12 13 14 15 16 |
# File 'lib/pact/matchers/base.rb', line 11 def initialize(spec_version:, kind:, template: nil, opts: {}) @spec_version = spec_version @kind = kind @template = template @opts = opts end |
Instance Attribute Details
#kind ⇒ Object (readonly)
Returns the value of attribute kind.
7 8 9 |
# File 'lib/pact/matchers/base.rb', line 7 def kind @kind end |
#opts ⇒ Object (readonly)
Returns the value of attribute opts.
7 8 9 |
# File 'lib/pact/matchers/base.rb', line 7 def opts @opts end |
#spec_version ⇒ Object (readonly)
Returns the value of attribute spec_version.
7 8 9 |
# File 'lib/pact/matchers/base.rb', line 7 def spec_version @spec_version end |
#template ⇒ Object (readonly)
Returns the value of attribute template.
7 8 9 |
# File 'lib/pact/matchers/base.rb', line 7 def template @template end |
Instance Method Details
#as_basic ⇒ Object
18 19 20 21 22 23 24 25 26 |
# File 'lib/pact/matchers/base.rb', line 18 def as_basic result = { "pact:matcher:type" => serialize!(@kind.deep_dup, :basic) } result["status"] = serialize!(@opts[:status].deep_dup, :basic) if @opts[:status] result["value"] = serialize!(@template.deep_dup, :basic) unless @template.nil? result.merge!(serialize!(@opts.deep_dup, :basic)) result end |
#as_plugin ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/pact/matchers/base.rb', line 28 def as_plugin params = @opts.values.map { |v| format_primitive(v) }.join(",") value = format_primitive(@template) unless @template.nil? if @template.nil? return "matching(#{@kind}#{params.present? ? ", #{params}" : ""})" end return "matching(#{@kind}, #{params}, #{value})" if params.present? "matching(#{@kind}, #{value})" end |