module Idonethis::Adapters module Git class << self def commits(opts={}) require 'git' fail "opts is supposed to be a hash" unless opts.is_a?(Hash) dir, since, how_many, log = defaults.merge(opts).values_at(:dir, :since, :how_many, :log) since_when = since.strftime("%d-%b-%Y") since_when = '1am' if since == Date.today since_when = '1am yesterday' if since == (Date.today - 1) log.call("Using <#{since_when}> as the since date for git") ::Git.open(dir).log(how_many).since("1am #{since_when}") end def repo?(dir) File.exists?(File.join(dir, ".git")) end private def defaults { log: ->(msg) {}, how_many: 1000 } end end end end