Class: GitTagger::Changelog

Inherits:
Object
  • Object
show all
Defined in:
app/models/changelog.rb

Overview

Represents a changelog for a project.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(version, message, autocreate) ⇒ Changelog

Sets the updated changelog text based on a semantic version and message



7
8
9
10
11
12
13
14
15
16
# File 'app/models/changelog.rb', line 7

def initialize(version, message, autocreate)
  if autocreate
    @update_text = "## #{ version } - " \
    "#{ DateTime.now.strftime('%F') }\n#{ message }\n\n"
  else
    @update_text = "## #{ version } - " \
    "#{ DateTime.now.strftime('%F') }\n * #{ message }\n\n"
  end

end

Instance Attribute Details

#update_textObject (readonly)

Returns the value of attribute update_text.



4
5
6
# File 'app/models/changelog.rb', line 4

def update_text
  @update_text
end

Instance Method Details

#add_to_gitObject

utilizes system commands to commit the changelog locally



38
39
40
# File 'app/models/changelog.rb', line 38

def add_to_git
  `git add "#{ @changelog_path }"`
end

#update(project_type) ⇒ Object

Updated the changelog file with the new update text



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'app/models/changelog.rb', line 19

def update(project_type)
  @changelog_path = locate_changelog project_type
  new_changelog = "#{ @changelog_path }.new"

  if !File.exist?(@changelog_path)
    File.open(@changelog_path, "w") {}
  end

  File.open(new_changelog, "w") do |fo|
    fo.puts @update_text
    File.foreach(@changelog_path) do |li|
      fo.puts li
    end
  end

  File.rename(new_changelog, @changelog_path)
end