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.



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

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

Instance Method Details

#consumer_nameObject



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

def consumer_name
  markdown_escape @consumer_contract.consumer.name
end

#description(start_of_sentence = false) ⇒ Object



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

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



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

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)


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

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

#idObject



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

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



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

def provider_name
  markdown_escape @consumer_contract.provider.name
end

#provider_state(start_of_sentence = false) ⇒ Object



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

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

#requestObject



73
74
75
76
77
78
79
80
# File 'lib/pact/doc/interaction_view_model.rb', line 73

def request
  the_clean_request = clean_request
  if the_clean_request == "ASYNC_REQUEST"
    "ASYNC_REQUEST"
  else  
    fix_json_formatting JSON.pretty_generate(clean_request)
  end
end

#request_methodObject



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

def request_method
  interaction.request.method.upcase
end

#request_pathObject



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

def request_path
  interaction.request.path
end

#responseObject



82
83
84
# File 'lib/pact/doc/interaction_view_model.rb', line 82

def response
  fix_json_formatting JSON.pretty_generate(clean_response)
end

#response_statusObject



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

def response_status
  interaction.response.status
end