Sha256: 8bfd2f6d34370c472551160a68e602518dd95c08cfaaf119033bd1a16c2f5e92

Contents?: true

Size: 939 Bytes

Versions: 4

Compression:

Stored size: 939 Bytes

Contents

module Dandelion
  class Changeset
    include Enumerable
    
    def initialize(tree, commit, options = {})
      @tree = tree
      @commit = commit
      @options = options
    end

    def diff
      Diff.new(@commit, @tree.commit)
    end

    def empty?
      diff.empty?
    end

    def each
      diff.each do |change|
        if applicable?(change.path)
          path = transform_path(change.path)

          if change.type == :delete
            yield Change.new(path, change.type)
          else
            yield Change.new(path, change.type, @tree.data(change.path))
          end
        end
      end
    end

  private

    def local_path
      @options[:local_path] || ''
    end

    def applicable?(path)
      path.start_with?(local_path)
    end

    def transform_path(path)
      trimmed = path[local_path.length..-1]
      trimmed = trimmed[1..-1] if trimmed[0] == File::SEPARATOR
      trimmed
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
dandelion-0.4.2 lib/dandelion/changeset.rb
dandelion-0.4.1 lib/dandelion/changeset.rb
dandelion-0.4.0 lib/dandelion/changeset.rb
dandelion-0.4.0.beta2 lib/dandelion/changeset.rb