Class: Hashira::Churn

Inherits:
Object
  • Object
show all
Defined in:
lib/hashira/churn.rb

Constant Summary collapse

LOG =
%w[log --no-renames --name-only --format=].freeze
SITES_THAT_DRIFT_APART =
2

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(counts) ⇒ Churn

Returns a new instance of Churn.



17
18
19
# File 'lib/hashira/churn.rb', line 17

def initialize(counts)
  @counts = counts
end

Class Method Details

.read(directory) ⇒ Object



9
10
11
12
13
# File 'lib/hashira/churn.rb', line 9

def self.read(directory)
  IO.popen(["git", "-C", directory, *LOG], err: File::NULL, &:read)
rescue SystemCallError
  ""
end

.scan(directory) ⇒ Object



7
# File 'lib/hashira/churn.rb', line 7

def self.scan(directory) = new(tally(read(directory)))

.tally(output) ⇒ Object



15
# File 'lib/hashira/churn.rb', line 15

def self.tally(output) = output.split("\n").map(&:strip).reject(&:empty?).tally

Instance Method Details

#changing(members) ⇒ Object



27
# File 'lib/hashira/churn.rb', line 27

def changing(members) = members.count { |member| hits(member.file).positive? }

#history?Boolean

Returns:

  • (Boolean)


21
# File 'lib/hashira/churn.rb', line 21

def history? = @counts.any?

#hits(file) ⇒ Object



23
# File 'lib/hashira/churn.rb', line 23

def hits(file) = @counts.select { |path, _| path.end_with?(file) }.values.max || 0

#hot?(members) ⇒ Boolean

Returns:

  • (Boolean)


25
# File 'lib/hashira/churn.rb', line 25

def hot?(members) = changing(members) >= SITES_THAT_DRIFT_APART