class SiteDiff::Result

SiteDiff Result Object.

Constants

STATUS_ERROR
STATUS_FAILURE
STATUS_SUCCESS
STATUS_TEXT

Attributes

diff[R]
status[R]

Public Class Methods

new(*args) click to toggle source

Creates a Result.

Calls superclass method
# File lib/sitediff/result.rb, line 29
def initialize(*args)
  super
  if error
    @status = STATUS_ERROR
  else
    if !before_encoding || !after_encoding
      @diff = Diff.binary_diffy(
        before,
        after,
        before_encoding,
        after_encoding
      )
    else
      @diff = Diff.html_diffy(before, after)
    end
    @status = @diff ? STATUS_FAILURE : STATUS_SUCCESS
  end
end

Public Instance Methods

diff_url(relative = false) click to toggle source

Returns a URL to the result diff.

Returns nil if the result has no diffs.

# File lib/sitediff/result.rb, line 85
def diff_url(relative = false)
  prefix = relative ? 'files/' : '/files/'
  return prefix + filename if status == STATUS_FAILURE
end
dump(dir, relative = false) click to toggle source

Dump the result to a file

# File lib/sitediff/result.rb, line 104
def dump(dir, relative = false)
  dump_path = File.join(dir, filename)
  base = File.dirname(dump_path)
  FileUtils.mkdir_p(base) unless File.exist?(base)
  File.open(dump_path, 'w') do |f|
    f.write(Diff.generate_diff_output(self, relative))
  end
end
error?() click to toggle source

Whether the result has an error.

# File lib/sitediff/result.rb, line 60
def error?
  status == STATUS_ERROR
end
filename() click to toggle source

Filename to store diff

# File lib/sitediff/result.rb, line 78
def filename
  File.join(Report::DIFFS_DIR, Digest::SHA1.hexdigest(path) + '.html')
end
log(verbose = true) click to toggle source

Log the result to the terminal

# File lib/sitediff/result.rb, line 91
def log(verbose = true)
  case status
  when STATUS_SUCCESS
    SiteDiff.log path, :success, 'UNCHANGED'
  when STATUS_ERROR
    SiteDiff.log path + " (#{error})", :warning, 'ERROR'
  when STATUS_FAILURE
    SiteDiff.log path, :error, 'CHANGED'
    puts Diff.terminal_diffy(before, after) if verbose
  end
end
status_text() click to toggle source

Textual representation of the status

# File lib/sitediff/result.rb, line 65
def status_text
  STATUS_TEXT[status]
end
success?() click to toggle source

Whether the result has no diff.

If there is a diff, it is not a success.

TODO: Change “Success” to unchanged.

# File lib/sitediff/result.rb, line 54
def success?
  status == STATUS_SUCCESS
end
url(tag, prefix, cache) click to toggle source

Printable URL

# File lib/sitediff/result.rb, line 70
def url(tag, prefix, cache)
  return unless prefix

  base = cache.read_tags.include?(tag) ? "/cache/#{tag}" : prefix
  base.to_s + path
end