Module: Idonethis::UseCases::Git

Defined in:
lib/idonethis/use_cases/git.rb

Class Method Summary collapse

Class Method Details

.apply(args = {}) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/idonethis/use_cases/git.rb', line 6

def apply(args={})
  log   = args[:log]   || fail("You need to supply :log adapter")
  git   = args[:git]   || fail("You need to supply :git adapter")
  view  = args[:view]  || fail("You need to supply :view adapter")
  fs    = args[:fs]    || fail("You need to supply :fs adapter")
  since = args[:since] || 'today'

  log.call args

  opts = args[:opts] || []
  
  dir = opts.any? ? File.expand_path(opts.first) : File.expand_path(".")

  dirs = dir
  
  if dir == FileUtils.pwd
    view.call "Scanning the current directory <#{dir}>\n\n"
  else
    dirs = fs.modified_today?(dir).select{|dir| git.repo?(dir) }

    view.call "Scanning dir <#{dir}>, which has <#{dirs.size}> repositories that have changed\n\n"
  end

  view.call summarise(git, view, since, *dirs)
  view.call ""
end

.date_from(commit) ⇒ Object



40
41
42
43
# File 'lib/idonethis/use_cases/git.rb', line 40

def date_from(commit)
  return commit.date.strftime("%d %b, %H:%M") unless today?(commit.date, Time.now)
  commit.date.strftime("%H:%M")
end

.summarise(git, view, since, *dirs) ⇒ Object



33
34
35
36
37
38
# File 'lib/idonethis/use_cases/git.rb', line 33

def summarise(git, view, since, *dirs)
  dirs.map do |dir|
    commits = git.commits(dir, since).map{|it| %Q{[#{date_from(it)}] (#{it.author.name}) #{it.message}}}        
    %Q{#{Pathname.new(dir).basename} (#{commits.size}):\n\n-- #{commits.join("\n-- ")}}
  end.join "\n\n"
end

.today?(time, now) ⇒ Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/idonethis/use_cases/git.rb', line 45

def today?(time, now)
  time.year == now.year && time.month == now.month && time.day == now.day
end