Class: Pact::V2::Matchers::Base
- Inherits:
-
Object
- Object
- Pact::V2::Matchers::Base
- Defined in:
- lib/pact/v2/matchers/base.rb
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.
12 13 14 15 16 17 |
# File 'lib/pact/v2/matchers/base.rb', line 12 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.
8 9 10 |
# File 'lib/pact/v2/matchers/base.rb', line 8 def kind @kind end |
#opts ⇒ Object (readonly)
Returns the value of attribute opts.
8 9 10 |
# File 'lib/pact/v2/matchers/base.rb', line 8 def opts @opts end |
#spec_version ⇒ Object (readonly)
Returns the value of attribute spec_version.
8 9 10 |
# File 'lib/pact/v2/matchers/base.rb', line 8 def spec_version @spec_version end |
#template ⇒ Object (readonly)
Returns the value of attribute template.
8 9 10 |
# File 'lib/pact/v2/matchers/base.rb', line 8 def template @template end |
Instance Method Details
#as_basic ⇒ Object
19 20 21 22 23 24 25 26 27 |
# File 'lib/pact/v2/matchers/base.rb', line 19 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
29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/pact/v2/matchers/base.rb', line 29 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 |