class Crosby::Diff

Public Class Methods

compare(uuid, options = {}, &block) click to toggle source
# File lib/crosby/diff.rb, line 6
def compare(uuid, options = {}, &block)
  new(uuid, options).compare(&block)
end
new(uuid, options = {}) click to toggle source
# File lib/crosby/diff.rb, line 11
def initialize(uuid, options = {})
  @uuid = uuid
  @config = Crosby.config.merge(options)
end

Public Instance Methods

compare(format = :color, &block) click to toggle source

github.com/samg/diffy#supported-formats

# File lib/crosby/diff.rb, line 17
def compare(format = :color, &block)
  diffs.map { |diff|
    out = diff.to_s(format)
    block_given? ? block.call(out) : out
  }
end
diffs() click to toggle source
# File lib/crosby/diff.rb, line 24
def diffs
  @diffs ||= [].tap { |diffs|
    pairs.each { |pair|
      diffs << Diffy::Diff.new(
        *pair,
        :context => 0,
        :include_diff_info => true,
        :source => "files"
      )
    }
  }
end

Private Instance Methods

build_file_paths(pairs) click to toggle source
# File lib/crosby/diff.rb, line 39
def build_file_paths(pairs)
  pairs.map { |pair|
    pair.map { |filename|
      File.realpath(File.join(@config[:export_path], filename))
    }
  }
end
files() click to toggle source
# File lib/crosby/diff.rb, line 47
def files
  matcher = Regexp.new("#{@uuid}\\.crosby\\z")

  Dir.new(@config[:export_path]).entries.select { |entry|
    entry =~ matcher ? true : false
  }
end
pairs() click to toggle source
# File lib/crosby/diff.rb, line 55
def pairs
  [
    :unique_pairs,
    :sort_pairs,
    :build_file_paths
  ].reduce([]) { |obj, meth|
    send(meth, obj)
  }
end
sort_pairs(pairs) click to toggle source
# File lib/crosby/diff.rb, line 65
def sort_pairs(pairs)
  pairs.map { |pair|
    pair.first =~ Regexp.new(@config[:app_name]) ? pair.reverse : pair
  }
end
unique_pairs(arr) click to toggle source
# File lib/crosby/diff.rb, line 71
def unique_pairs(arr)
  arr.tap { |pairs|
    files.repeated_permutation(2) { |permutation|
      pairs << permutation.sort unless permutation.uniq.length == 1
    }

    pairs.uniq!
  }
end