Class: Yanapiri::Entrega

Inherits:
Object
  • Object
show all
Defined in:
lib/yanapiri/entrega.rb

Defined Under Namespace

Classes: ModoCorreccion, ModoEstricto, ModoRelajado

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(repo_path, commit_base = nil, fecha_limite = nil, modo_estricto = false) ⇒ Entrega



6
7
8
9
10
11
12
# 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

Instance Attribute Details

#commit_baseObject (readonly)

Returns the value of attribute commit_base.



3
4
5
# File 'lib/yanapiri/entrega.rb', line 3

def commit_base
  @commit_base
end

#fecha_limiteObject (readonly)

Returns the value of attribute fecha_limite.



3
4
5
# File 'lib/yanapiri/entrega.rb', line 3

def fecha_limite
  @fecha_limite
end

#idObject (readonly)

Returns the value of attribute id.



3
4
5
# File 'lib/yanapiri/entrega.rb', line 3

def id
  @id
end

#repoObject (readonly)

Returns the value of attribute repo.



3
4
5
# File 'lib/yanapiri/entrega.rb', line 3

def repo
  @repo
end

Instance Method Details

#actualizar!Object



48
49
50
51
# File 'lib/yanapiri/entrega.rb', line 48

def actualizar!
  repo.checkout 'entrega'
  repo.merge commit_entrega, nil
end

#autorObject



18
19
20
# File 'lib/yanapiri/entrega.rb', line 18

def autor
  @id.split('-').last
end

#commits_fuera_de_terminoObject



31
32
33
34
# 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) ⇒ Boolean



27
28
29
# File 'lib/yanapiri/entrega.rb', line 27

def contiene_archivo?(nombre)
  @repo.chdir { File.exist? nombre }
end

#crear_branch_base!Object



44
45
46
# File 'lib/yanapiri/entrega.rb', line 44

def crear_branch_base!
  crear_branch! 'base', commit_base
end

#crear_branch_entrega!Object



40
41
42
# File 'lib/yanapiri/entrega.rb', line 40

def crear_branch_entrega!
  crear_branch! 'entrega', commit_entrega
end

#fechaObject



22
23
24
25
# File 'lib/yanapiri/entrega.rb', line 22

def fecha
  @repo.checkout 'master'
  @repo.log.first.author_date
end

#formato_humano(fecha) ⇒ Object



64
65
66
# File 'lib/yanapiri/entrega.rb', line 64

def formato_humano(fecha)
  I18n.l(fecha, format: :human)
end

#fuera_de_termino?Boolean



14
15
16
# File 'lib/yanapiri/entrega.rb', line 14

def fuera_de_termino?
  commits_fuera_de_termino.any?
end

#hay_cambios?Boolean



36
37
38
# File 'lib/yanapiri/entrega.rb', line 36

def hay_cambios?
  @repo.log.between(@commit_base, 'master').any?
end

#to_sObject



57
58
59
60
61
62
# 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?Boolean



53
54
55
# File 'lib/yanapiri/entrega.rb', line 53

def ya_preparada?
  repo.is_local_branch? 'entrega'
end