Class: Ritual::Changelog

Inherits:
Object
  • Object
show all
Defined in:
lib/ritual/changelog.rb

Constant Summary collapse

Error =
Class.new(RuntimeError)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Changelog

Returns a new instance of Changelog.



5
6
7
# File 'lib/ritual/changelog.rb', line 5

def initialize(path)
  @path = path
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



9
10
11
# File 'lib/ritual/changelog.rb', line 9

def path
  @path
end

Instance Method Details

#set_latest_version(version) ⇒ Object



11
12
13
14
15
16
17
18
19
# File 'lib/ritual/changelog.rb', line 11

def set_latest_version(version)
  File.exist?(path) or
    raise Error, "Don't release without a CHANGELOG!"
  text = File.read(path)
  heading = "#{version} #{Date.today.strftime('%Y-%m-%d')}"
  text.sub!(/^(== )LATEST$/i, "\\1#{heading}") or
    raise Error, "No LATEST entry in CHANGELOG - did you forget to update it?"
  open(path, 'w'){|f| f.print text}
end