Class: Tumbler::Manager::Changelog

Inherits:
Object
  • Object
show all
Includes:
Informer, Runner
Defined in:
lib/tumbler/manager/changelog.rb

Constant Summary collapse

DEFAULT_FILE =
'CHANGELOG'

Constants included from Informer

Informer::Colors

Instance Attribute Summary collapse

Attributes included from Runner

#noop

Instance Method Summary collapse

Methods included from Informer

#inform

Methods included from Runner

#dry, #sh, #sh_with_code

Constructor Details

#initialize(manager, &block) ⇒ Changelog

Returns a new instance of Changelog.



14
15
16
17
# File 'lib/tumbler/manager/changelog.rb', line 14

def initialize(manager, &block)
  @manager = manager
  instance_eval(&block) if block
end

Instance Attribute Details

#fileObject (readonly)

Returns the value of attribute file.



12
13
14
# File 'lib/tumbler/manager/changelog.rb', line 12

def file
  @file
end

Instance Method Details

#baseObject



64
65
66
# File 'lib/tumbler/manager/changelog.rb', line 64

def base
  @manager.base
end

#commitObject



60
61
62
# File 'lib/tumbler/manager/changelog.rb', line 60

def commit
  sh "git commit #{@basefile} -m'Updated changelog'"
end

#ensure_existenceObject



56
57
58
# File 'lib/tumbler/manager/changelog.rb', line 56

def ensure_existence
  File.open(@file, 'w') {|f| f << ''} unless File.exist?(@file)
end

#filename(file) ⇒ Object



19
20
21
22
# File 'lib/tumbler/manager/changelog.rb', line 19

def filename(file)
  @basefile = file
  @file = File.join(@manager.base, file)
end

#prepend(data) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/tumbler/manager/changelog.rb', line 30

def prepend(data)
  if @manager.noop
    @manager.dry "Prepending #{data} to `#{@basefile}'"
  else
    Tempfile.open('changelog') do |tmp|
      tmp.puts data
      File.open(@file) do |f|
        f.each do |line|
          tmp << line
        end
      end
      tmp.close
      FileUtils.copy(tmp.path, @file)
      File.unlink(tmp.path)
    end
  end
end

#updateObject



48
49
50
51
52
53
54
# File 'lib/tumbler/manager/changelog.rb', line 48

def update
  ensure_existence
  inform "Updating `#{@basefile}' with latest changes" do
    prepend("\n")
    prepend(@manager.latest_changes.inject('') { |changes, change| changes << "* #{change.summary} (#{change.author}, #{change.hash})\n" })
  end
end

#write_version_headerObject



24
25
26
27
28
# File 'lib/tumbler/manager/changelog.rb', line 24

def write_version_header
  inform "Writing version header to `#{@basefile}'" do
    prepend "== #{@manager.version}\n\n"
  end
end