Class: Stove::Action::Changelog
- Inherits:
-
Base
- Object
- Base
- Stove::Action::Changelog
show all
- Defined in:
- lib/stove/actions/changelog.rb
Instance Attribute Summary
Attributes inherited from Base
#cookbook, #options
Instance Method Summary
collapse
Methods inherited from Base
#initialize
extended, included
#validate
Instance Method Details
#default_changeset ⇒ Object
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
# File 'lib/stove/actions/changelog.rb', line 56
def default_changeset
return @default_changeset if @default_changeset
= "v#{cookbook.version} (#{Time.now.to_date})"
contents = []
contents <<
contents << '-'*.length
contents << cookbook.changeset || 'Enter CHANGELOG entries here'
contents << ''
@default_changeset = contents.join("\n")
@default_changeset
end
|
#prompt_for_changeset ⇒ Object
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
# File 'lib/stove/actions/changelog.rb', line 40
def prompt_for_changeset
tempfile = Tempfile.new(["#{cookbook.name}-changeset-#{Time.now}", '.md'])
tempfile.write(default_changeset)
tempfile.rewind
system %Q|$EDITOR "#{tempfile.path}"|
cookbook.changeset = File.read(tempfile.path).strip
tempfile.close
tempfile.unlink
end
|
#run ⇒ Object
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/stove/actions/changelog.rb', line 19
def run
log.info('Generating new Changelog')
log.debug("Generated changeset:\n#{default_changeset}")
prompt_for_changeset
log.debug("New changeset:\n#{cookbook.changeset}")
path = File.join(cookbook.path, 'CHANGELOG.md')
contents = File.readlines(path)
index = contents.find_index { |line| line =~ /^(--)+/ }
log.debug("Writing changelog at `#{path}', index #{index}")
contents.insert(index - 2, "\n" + cookbook.changeset + "\n\n")
File.open(path, 'w') { |file| file.write(contents.join('')) }
end
|