class PactBroker::Pacts::Diff::DiffDecorator

The next pact version after the previous distinct version. Eg. v1 (previous distinct) -> pactContentA

v2 (next pact)         -> pactContentB
v3                     -> pactContentB
v4 (current)           -> pactContentB

If we are at v4, then the previous distinct pact version is v1, and the next pact after that is v2. The timestamps on v2 are the ones we want - that's when the latest distinct version content was first created.

Attributes

base_url[R]
comparison_pact[R]
next_pact[R]
options[R]
pact[R]

Public Class Methods

new(pact, comparison_pact, next_pact, base_url, options) click to toggle source
# File lib/pact_broker/pacts/diff.rb, line 51
def initialize(pact, comparison_pact, next_pact, base_url, options)
  @pact = pact
  @comparison_pact = comparison_pact
  @next_pact = next_pact
  @base_url = base_url
  @options = options
end

Public Instance Methods

to_text() click to toggle source
# File lib/pact_broker/pacts/diff.rb, line 59
def to_text
  header + "\n\n" + diff + "\n\n" + links
end

Private Instance Methods

change_date_ago_in_words() click to toggle source
# File lib/pact_broker/pacts/diff.rb, line 105
def change_date_ago_in_words
  DateHelper.distance_of_time_in_words next_pact.created_at, now
end
change_date_in_words() click to toggle source
# File lib/pact_broker/pacts/diff.rb, line 67
def change_date_in_words
  DateHelper.local_date_in_words next_pact.created_at
end
diff() click to toggle source
# File lib/pact_broker/pacts/diff.rb, line 101
def diff
  CreateFormattedDiff.(prepare_content(pact.json_content), prepare_content(comparison_pact.json_content))
end
header() click to toggle source
# File lib/pact_broker/pacts/diff.rb, line 75
def header
  title = "# Diff between versions #{comparison_pact.consumer_version_number} and #{pact.consumer_version_number} of the pact between #{pact.consumer.name} and #{pact.provider.name}"
  description = "The following changes were made #{change_date_ago_in_words} ago (#{change_date_in_words})"

  title +  "\n\n" + description
end
now() click to toggle source
# File lib/pact_broker/pacts/diff.rb, line 71
def now
  Time.now
end
prepare_content(json_content) click to toggle source
# File lib/pact_broker/pacts/diff.rb, line 109
def prepare_content json_content
  if options[:raw]
    json_content
  else
    SortContent.call(Parse.call(json_content)).to_json
  end
end