class Yanapiri::Entrega

Attributes

commit_base[R]
fecha_limite[R]
id[R]
repo[R]

Public Class Methods

new(repo_path, commit_base = nil, fecha_limite = nil, modo_estricto = false) click to toggle source
# File lib/yanapiri/entrega.rb, line 6
def initialize(repo_path, commit_base = nil, fecha_limite = nil, modo_estricto = false)
  @id = File.basename repo_path
  @fecha_limite = fecha_limite || Time.now + 1.second
  @modo = (modo_estricto ? ModoEstricto : ModoRelajado).new self
  @repo = Git.open repo_path
  @commit_base = parse_commit_base commit_base
end

Public Instance Methods

actualizar!() click to toggle source
# File lib/yanapiri/entrega.rb, line 48
def actualizar!
  repo.checkout 'entrega'
  repo.merge commit_entrega, nil
end
autor() click to toggle source
# File lib/yanapiri/entrega.rb, line 18
def autor
  @id.split('-').last
end
commits_fuera_de_termino() click to toggle source
# File lib/yanapiri/entrega.rb, line 31
def commits_fuera_de_termino
  @repo.checkout 'master'
  @repo.log.since(@fecha_limite.iso8601)
end
contiene_archivo?(nombre) click to toggle source
# File lib/yanapiri/entrega.rb, line 27
def contiene_archivo?(nombre)
  @repo.chdir { File.exist? nombre }
end
crear_branch_base!() click to toggle source
# File lib/yanapiri/entrega.rb, line 44
def crear_branch_base!
  crear_branch! 'base', commit_base
end
crear_branch_entrega!() click to toggle source
# File lib/yanapiri/entrega.rb, line 40
def crear_branch_entrega!
  crear_branch! 'entrega', commit_entrega
end
fecha() click to toggle source
# File lib/yanapiri/entrega.rb, line 22
def fecha
  @repo.checkout 'master'
  @repo.log.first.author_date
end
formato_humano(fecha) click to toggle source
# File lib/yanapiri/entrega.rb, line 64
def formato_humano(fecha)
  I18n.l(fecha, format: :human)
end
fuera_de_termino?() click to toggle source
# File lib/yanapiri/entrega.rb, line 14
def fuera_de_termino?
  commits_fuera_de_termino.any?
end
hay_cambios?() click to toggle source
# File lib/yanapiri/entrega.rb, line 36
def hay_cambios?
  @repo.log.between(@commit_base, 'master').any?
end
to_s() click to toggle source
# File lib/yanapiri/entrega.rb, line 57
def to_s
  string = "entrega de @#{autor}, "
  string << if hay_cambios? then "modificada por Ășltima vez #{formato_humano fecha}" else "sin cambios" end
  string << ' (fuera de término)' if fuera_de_termino?
  string
end
ya_preparada?() click to toggle source
# File lib/yanapiri/entrega.rb, line 53
def ya_preparada?
  repo.is_local_branch? 'entrega'
end

Private Instance Methods

crear_branch!(nombre, head) click to toggle source
# File lib/yanapiri/entrega.rb, line 70
def crear_branch!(nombre, head)
  @repo.checkout head
  @repo.branch(nombre).checkout
end
parse_commit_base(commit_base) click to toggle source
# File lib/yanapiri/entrega.rb, line 75
def parse_commit_base(commit_base)
  if not commit_base
    '--max-parents=0 HEAD'
  elsif commit_base.start_with? 'index'
    requested = commit_base.split(':').last.to_i
    index = [@repo.log.size - requested, 0].max
    @repo.log[index].sha
  else
    commit_base
  end
end