Class: Pact::V2::Matchers::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/pact/v2/matchers/base.rb

Overview

Defined Under Namespace

Classes: MatcherInitializationError

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#kindObject (readonly)

Returns the value of attribute kind.



8
9
10
# File 'lib/pact/v2/matchers/base.rb', line 8

def kind
  @kind
end

#optsObject (readonly)

Returns the value of attribute opts.



8
9
10
# File 'lib/pact/v2/matchers/base.rb', line 8

def opts
  @opts
end

#spec_versionObject (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

#templateObject (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_basicObject



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_pluginObject



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