Class: DocumentGenerator::Commit
- Inherits:
-
Object
- Object
- DocumentGenerator::Commit
- Defined in:
- lib/document_generator/commit.rb
Instance Attribute Summary collapse
-
#base_url ⇒ Object
Returns the value of attribute base_url.
-
#git_commit ⇒ Object
Returns the value of attribute git_commit.
Instance Method Summary collapse
- #additional ⇒ Object
- #basename_prefix ⇒ Object
- #commit_message_lines ⇒ Object
- #create ⇒ Object
- #details_of_commit_message ⇒ Object
- #diff_files ⇒ Object
- #filename ⇒ Object
- #first_line_of_commit_message ⇒ Object
- #header ⇒ Object
-
#initialize(base_url, git_commit) ⇒ Commit
constructor
A new instance of Commit.
- #link ⇒ Object
- #relative_filename ⇒ Object
Constructor Details
#initialize(base_url, git_commit) ⇒ Commit
Returns a new instance of Commit.
5 6 7 8 |
# File 'lib/document_generator/commit.rb', line 5 def initialize(base_url, git_commit) @base_url = base_url @git_commit = git_commit end |
Instance Attribute Details
#base_url ⇒ Object
Returns the value of attribute base_url.
3 4 5 |
# File 'lib/document_generator/commit.rb', line 3 def base_url @base_url end |
#git_commit ⇒ Object
Returns the value of attribute git_commit.
3 4 5 |
# File 'lib/document_generator/commit.rb', line 3 def git_commit @git_commit end |
Instance Method Details
#additional ⇒ Object
47 48 49 50 51 52 53 54 55 |
# File 'lib/document_generator/commit.rb', line 47 def additional <<-ADDITIONAL ### Additional Resources * [Changes in this step in `diff` format](#{URI.join(base_url, 'commit/', git_commit.sha)}) ADDITIONAL end |
#basename_prefix ⇒ Object
69 70 71 72 73 74 75 76 |
# File 'lib/document_generator/commit.rb', line 69 def basename_prefix = = .split.join('-') .gsub!(%r{[^\w-]}, '') .downcase! .tr!('_', '-') end |
#commit_message_lines ⇒ Object
57 58 59 |
# File 'lib/document_generator/commit.rb', line 57 def git_commit..split("\n") end |
#create ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/document_generator/commit.rb', line 22 def create File.open(relative_filename, 'w') do |writer| writer.write(header) writer.write() if diff_files.each do |diff_file| writer.write(diff_file.content) end writer.write(additional) end end |
#details_of_commit_message ⇒ Object
65 66 67 |
# File 'lib/document_generator/commit.rb', line 65 def [1..-1].join("\n") if .length > 1 end |
#diff_files ⇒ Object
10 11 12 13 14 15 16 |
# File 'lib/document_generator/commit.rb', line 10 def diff_files return [] unless git_commit.parent git_commit.parent.diff(git_commit).map do |git_diff_file| DiffFile.new(git_diff_file) end end |
#filename ⇒ Object
78 79 80 |
# File 'lib/document_generator/commit.rb', line 78 def filename "#{basename_prefix}.md" end |
#first_line_of_commit_message ⇒ Object
61 62 63 |
# File 'lib/document_generator/commit.rb', line 61 def .first end |
#header ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/document_generator/commit.rb', line 35 def header <<-HEADER --- layout: default title: #{} --- <h1 id="main">#{}</h1> HEADER end |
#link ⇒ Object
82 83 84 |
# File 'lib/document_generator/commit.rb', line 82 def link "<li><a href='#{basename_prefix}.html'>#{}</a></li>" end |
#relative_filename ⇒ Object
18 19 20 |
# File 'lib/document_generator/commit.rb', line 18 def relative_filename filename end |