Class: Pact::V2::Consumer::PactConfig::Http

Inherits:
Base
  • Object
show all
Defined in:
lib/pact/v2/consumer/pact_config/http.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#consumer_name, #log_level, #pact_dir, #provider_name

Instance Method Summary collapse

Constructor Details

#initialize(consumer_name:, provider_name:, opts: {}) ⇒ Http

Returns a new instance of Http.



12
13
14
15
16
17
18
19
20
# File 'lib/pact/v2/consumer/pact_config/http.rb', line 12

def initialize(consumer_name:, provider_name:, opts: {})
  super

  @mock_host = opts[:mock_host] || "127.0.0.1"
  @mock_port = opts[:mock_port] || 0
  @log_level = opts[:log_level] || :info
  @pact_specification = get_pact_specification(opts)
  @pact_handle = init_pact
end

Instance Attribute Details

#mock_hostObject (readonly)

Returns the value of attribute mock_host.



10
11
12
# File 'lib/pact/v2/consumer/pact_config/http.rb', line 10

def mock_host
  @mock_host
end

#mock_portObject (readonly)

Returns the value of attribute mock_port.



10
11
12
# File 'lib/pact/v2/consumer/pact_config/http.rb', line 10

def mock_port
  @mock_port
end

#pact_handleObject (readonly)

Returns the value of attribute pact_handle.



10
11
12
# File 'lib/pact/v2/consumer/pact_config/http.rb', line 10

def pact_handle
  @pact_handle
end

Instance Method Details

#get_pact_specification(opts) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/pact/v2/consumer/pact_config/http.rb', line 30

def get_pact_specification(opts)
  pact_spec_version = opts[:pact_specification] || "V4"
  unless pact_spec_version.match?(/^v?[1-4](\.\d+){0,2}$/i)
    raise ArgumentError, "Invalid pact specification version format \n Valid versions are 1, 1.1, 2, 3, 4. Default is V4 \n V prefix is optional, and case insensitive"
  end
  pact_spec_version = pact_spec_version.upcase
  pact_spec_version = "V#{pact_spec_version}" unless pact_spec_version.start_with?("V")
  pact_spec_version = pact_spec_version.sub(/(\.0+)+$/, "")
  pact_spec_version = pact_spec_version.tr(".", "_")
  PactFfi::FfiSpecificationVersion["SPECIFICATION_VERSION_#{pact_spec_version.upcase}"]
end

#init_pactObject



42
43
44
45
46
47
48
49
50
# File 'lib/pact/v2/consumer/pact_config/http.rb', line 42

def init_pact
  handle = PactFfi.new_pact(consumer_name, provider_name)
  PactFfi.with_specification(handle, @pact_specification)
  PactFfi.(handle, "pact-ruby-v2", "pact-ffi", PactFfi.version)

  Pact::V2::Native::Logger.log_to_stdout(@log_level)

  handle
end

#new_interaction(description = nil) ⇒ Object



22
23
24
# File 'lib/pact/v2/consumer/pact_config/http.rb', line 22

def new_interaction(description = nil)
  HttpInteractionBuilder.new(self, description: description)
end

#reset_pactObject



26
27
28
# File 'lib/pact/v2/consumer/pact_config/http.rb', line 26

def reset_pact
  @pact_handle = init_pact
end