Class: Daun::RefsDiff

Inherits:
Object
  • Object
show all
Defined in:
lib/daun/refs_diff.rb

Overview

Produce git refs differences before and after fetch

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(before, after) ⇒ RefsDiff

Creates a new instance of RefsDiff.

Parameters:

  • before (Hash)

    the refs hash with full refs format as key and commit id as value

  • after (Hash)

    the refs hash with full refs format as key and commit id as value



11
12
13
14
# File 'lib/daun/refs_diff.rb', line 11

def initialize(before, after)
  @before = before
  @after = after
end

Instance Attribute Details

#added_remotesObject

Returns the value of attribute added_remotes.



5
6
7
# File 'lib/daun/refs_diff.rb', line 5

def added_remotes
  @added_remotes
end

Instance Method Details

#added(type = nil) ⇒ Object

Returns all of the refs that have been added after the fetch. These are the refs that exists in after but not before.

Parameters:

  • type (Symbol) (defaults to: nil)

    :tag for tag refs, :remotes for remote branches, nil for everything



20
21
22
23
# File 'lib/daun/refs_diff.rb', line 20

def added(type = nil)
  keys = (@after.keys - @before.keys).collect(&:to_s)
  filter(keys, type)
end

#deleted(type = nil) ⇒ Object

Returns all of the refs that have been deleted after the fetch. These are the refs that exists in before but not after

Parameters:

  • type (Symbol) (defaults to: nil)

    :tag for tag refs, :remotes for remote branches, nil for everything



42
43
44
45
# File 'lib/daun/refs_diff.rb', line 42

def deleted(type = nil)
  keys = (@before.keys - @after.keys).collect(&:to_s)
  filter(keys, type)
end

#updated(type = nil) ⇒ Object

Returns all of the refs that have been updated after the fetch. Updated refs are detected when refs exists in both before and after but is having a different commit id in the Hash.

Parameters:

  • type (Symbol) (defaults to: nil)

    :tag for tag refs, :remotes for remote branches, nil for everything



30
31
32
33
34
35
36
# File 'lib/daun/refs_diff.rb', line 30

def updated(type = nil)
  keys = (@after.keys + @before.keys)
             .group_by { |k| k }
             .select { |k, k_group| k_group.size > 1 && @before[k] != @after[k] }
             .keys.collect(&:to_s)
  filter(keys, type)
end