Class: Sbmt::Pact::Matchers::Base

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

Overview

Defined Under Namespace

Classes: MatcherInitializationError

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(spec_version:, kind:, template:, opts: {}) ⇒ Base

Returns a new instance of Base.



12
13
14
15
16
17
# File 'lib/sbmt/pact/matchers/base.rb', line 12

def initialize(spec_version:, kind:, template:, 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/sbmt/pact/matchers/base.rb', line 8

def kind
  @kind
end

#optsObject (readonly)

Returns the value of attribute opts.



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

def opts
  @opts
end

#spec_versionObject (readonly)

Returns the value of attribute spec_version.



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

def spec_version
  @spec_version
end

#templateObject (readonly)

Returns the value of attribute template.



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

def template
  @template
end

Instance Method Details

#as_basicObject



19
20
21
22
23
24
# File 'lib/sbmt/pact/matchers/base.rb', line 19

def as_basic
  {
    "pact:matcher:type" => serialize!(@kind.deep_dup, :basic),
    "value" => serialize!(@template.deep_dup, :basic)
  }.merge(serialize!(@opts.deep_dup, :basic))
end

#as_pluginObject



26
27
28
29
30
31
32
33
# File 'lib/sbmt/pact/matchers/base.rb', line 26

def as_plugin
  params = @opts.values.map { |v| format_primitive(v) }.join(",")
  value = format_primitive(@template)

  return "matching(#{@kind}, #{params}, #{value})" if params.present?

  "matching(#{@kind}, #{value})"
end