Class: Pact::Doc::InteractionViewModel
- Inherits:
-
Object
- Object
- Pact::Doc::InteractionViewModel
- Includes:
- ActiveSupportSupport
- Defined in:
- lib/pact/doc/interaction_view_model.rb
Constant Summary collapse
- MARKDOWN_BOLD_CHARACTERS =
"**"
Instance Method Summary collapse
- #consumer_name ⇒ Object
- #description(start_of_sentence = false) ⇒ Object
- #formatted_provider_states(mark_bold: false) ⇒ Object
- #has_provider_state? ⇒ Boolean
- #id ⇒ Object
-
#initialize(interaction, consumer_contract) ⇒ InteractionViewModel
constructor
A new instance of InteractionViewModel.
- #provider_name ⇒ Object
- #provider_state(start_of_sentence = false) ⇒ Object
- #request ⇒ Object
- #request_method ⇒ Object
- #request_path ⇒ Object
- #response ⇒ Object
- #response_status ⇒ Object
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_name ⇒ Object
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
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 |
#id ⇒ Object
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_name ⇒ Object
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 |
#request ⇒ Object
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_method ⇒ Object
29 30 31 |
# File 'lib/pact/doc/interaction_view_model.rb', line 29 def request_method interaction.request.method.upcase end |
#request_path ⇒ Object
33 34 35 |
# File 'lib/pact/doc/interaction_view_model.rb', line 33 def request_path interaction.request.path end |
#response ⇒ Object
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_status ⇒ Object
37 38 39 |
# File 'lib/pact/doc/interaction_view_model.rb', line 37 def response_status interaction.response.status end |