Class: Pact::Doc::InteractionViewModel

Inherits:
Object
  • Object
show all
Includes:
ActiveSupportSupport
Defined in:
lib/pact/doc/interaction_view_model.rb

Constant Summary collapse

MARKDOWN_BOLD_CHARACTERS =
"**"

Instance Method Summary collapse

Constructor Details

#initialize(interaction, consumer_contract) ⇒ InteractionViewModel

Returns a new instance of InteractionViewModel.



13
14
15
16
# File 'lib/pact/doc/interaction_view_model.rb', line 13

def initialize interaction, consumer_contract
  @interaction = interaction
  @consumer_contract = consumer_contract
end

Instance Method Details

#consumer_nameObject



41
42
43
# File 'lib/pact/doc/interaction_view_model.rb', line 41

def consumer_name
  markdown_escape @consumer_contract.consumer.name
end

#description(start_of_sentence = false) ⇒ Object



67
68
69
70
# File 'lib/pact/doc/interaction_view_model.rb', line 67

def description start_of_sentence = false
  return "" unless @interaction.description
  markdown_escape apply_capitals(@interaction.description.strip, start_of_sentence)
end

#formatted_provider_states(mark_bold: false) ⇒ Object



57
58
59
60
61
62
63
64
65
# File 'lib/pact/doc/interaction_view_model.rb', line 57

def formatted_provider_states mark_bold: false
  bold_marker = mark_bold ? MARKDOWN_BOLD_CHARACTERS : ""

  (@interaction.provider_states || []).map do |ps|
    "#{bold_marker}" \
    "#{markdown_escape(apply_capitals(ps.name.strip, false))}" \
    "#{bold_marker}"
  end.join(" and ")
end

#has_provider_state?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/pact/doc/interaction_view_model.rb', line 49

def has_provider_state?
  @interaction.provider_state && !@interaction.provider_state.empty?
end

#idObject



18
19
20
21
22
23
24
25
26
27
# File 'lib/pact/doc/interaction_view_model.rb', line 18

def id
  @id ||= begin
    full_desc = if has_provider_state?
                  "#{description} given #{interaction.provider_state}"
                else
                  description
                end
    CGI.escapeHTML(full_desc.gsub(/\s+/,"_"))
  end
end

#provider_nameObject



45
46
47
# File 'lib/pact/doc/interaction_view_model.rb', line 45

def provider_name
  markdown_escape @consumer_contract.provider.name
end

#provider_state(start_of_sentence = false) ⇒ Object



53
54
55
# File 'lib/pact/doc/interaction_view_model.rb', line 53

def provider_state start_of_sentence = false
  markdown_escape apply_capitals(@interaction.provider_state.strip, start_of_sentence)
end

#requestObject



72
73
74
# File 'lib/pact/doc/interaction_view_model.rb', line 72

def request
  fix_json_formatting JSON.pretty_generate(clean_request)
end

#request_methodObject



29
30
31
# File 'lib/pact/doc/interaction_view_model.rb', line 29

def request_method
  interaction.request.method.upcase
end

#request_pathObject



33
34
35
# File 'lib/pact/doc/interaction_view_model.rb', line 33

def request_path
  interaction.request.path
end

#responseObject



76
77
78
# File 'lib/pact/doc/interaction_view_model.rb', line 76

def response
  fix_json_formatting JSON.pretty_generate(clean_response)
end

#response_statusObject



37
38
39
# File 'lib/pact/doc/interaction_view_model.rb', line 37

def response_status
  interaction.response.status
end