Class: Pact::Consumer::InteractionContents

Inherits:
Hash show all
Defined in:
lib/pact/consumer/interaction_contents.rb

Constant Summary collapse

BASIC_FORMAT =
:basic
PLUGIN_FORMAT =
:plugin

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Hash

#deep_dup, #present?

Constructor Details

#initialize(contents_hash, format) ⇒ InteractionContents

Returns a new instance of InteractionContents.



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/pact/consumer/interaction_contents.rb', line 19

def initialize(contents_hash, format)
  serialized = init_hash(contents_hash, format)
  # A scalar body (plain string, integer, etc.) serializes to a non-Hash
  # value that cannot be merged pair by pair; expose it via #value instead.
  if serialized.is_a?(Hash)
    serialized.each_pair { |k, v| self[k] = v }
  else
    @value = serialized
  end
  @format = format
end

Instance Attribute Details

#formatObject (readonly)

Returns the value of attribute format.



9
10
11
# File 'lib/pact/consumer/interaction_contents.rb', line 9

def format
  @format
end

Class Method Details

.basic(contents_hash) ⇒ Object



11
12
13
# File 'lib/pact/consumer/interaction_contents.rb', line 11

def self.basic(contents_hash)
  new(contents_hash, BASIC_FORMAT)
end

.plugin(contents_hash) ⇒ Object



15
16
17
# File 'lib/pact/consumer/interaction_contents.rb', line 15

def self.plugin(contents_hash)
  new(contents_hash, PLUGIN_FORMAT)
end

Instance Method Details

#valueObject



31
32
33
# File 'lib/pact/consumer/interaction_contents.rb', line 31

def value
  defined?(@value) ? @value : self
end