Class: Tumbler::Manager

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

Defined Under Namespace

Classes: Change, Changelog, Version

Constant Summary

Constants included from Informer

Informer::Colors

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Informer

#inform

Methods included from Runner

#dry, #sh, #sh_with_code

Instance Attribute Details

#baseObject (readonly)

Returns the value of attribute base.



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

def base
  @base
end

#changelogObject (readonly)

Returns the value of attribute changelog.



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

def changelog
  @changelog
end

#gemObject (readonly)

Returns the value of attribute gem.



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

def gem
  @gem
end

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#noopObject

Returns the value of attribute noop.



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

def noop
  @noop
end

#versionObject (readonly)

Returns the value of attribute version.



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

def version
  @version
end

Instance Method Details

#bump(level) ⇒ Object



126
127
128
129
130
131
132
# File 'lib/tumbler/manager.rb', line 126

def bump(level)
  from = @version.to_s
  inform "Bumping from #{from} by #{level}" do
    @version.bump(level)
    @version.commit(from)
  end
end

#bump_and_commit(field) ⇒ Object



74
75
76
77
78
79
80
81
# File 'lib/tumbler/manager.rb', line 74

def bump_and_commit(field)
  guard_clean
  inform "Bumping & committing" do
    @changelog.update if @changelog
    bump(field)
    @changelog.write_version_header if @changelog
  end
end

#bump_and_push(field) ⇒ Object



94
95
96
97
98
99
100
101
# File 'lib/tumbler/manager.rb', line 94

def bump_and_push(field)
  inform "Bumping & pushing" do
    revert_on_error do
      bump_and_commit(field)
      tag_and_push
    end
  end
end

#bundlerObject



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

def bundler
  @definition ||= Bundler::Dsl.evaluate(gemfile_path)
end

#changelog_file(file = default_changelog_file, &block) ⇒ Object



62
63
64
65
66
67
# File 'lib/tumbler/manager.rb', line 62

def changelog_file(file = default_changelog_file, &block)
  @changelog = Changelog.new(self)
  @changelog.filename(file)
  @changelog.instance_eval(&block) if block
  @changelog
end

#clean?Boolean

Returns:

  • (Boolean)


134
135
136
# File 'lib/tumbler/manager.rb', line 134

def clean?
  sh("git ls-files -dm").split("\n").size.zero?
end

#config_pathObject



30
31
32
# File 'lib/tumbler/manager.rb', line 30

def config_path
  File.join(@base, 'Tumbler')
end

#current_revisionObject



103
104
105
# File 'lib/tumbler/manager.rb', line 103

def current_revision
  sh('git show --pretty=format:%H').split(/\n/)[0].strip
end

#default_changelog_fileObject



18
19
20
# File 'lib/tumbler/manager.rb', line 18

def default_changelog_file
  Changelog::DEFAULT_FILE
end

#default_version_fileObject



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

def default_version_file
  File.join('lib', name, 'version.rb')
end

#gem_name(name) ⇒ Object



22
23
24
# File 'lib/tumbler/manager.rb', line 22

def gem_name(name)
  @name = name
end

#gemfile_pathObject



34
35
36
# File 'lib/tumbler/manager.rb', line 34

def gemfile_path
  File.join(@base, 'Gemfile')
end

#gemspec_pathObject



38
39
40
# File 'lib/tumbler/manager.rb', line 38

def gemspec_path
  File.join(@base, "#{@name}.gemspec")
end

#guard_already_taggedObject



122
123
124
# File 'lib/tumbler/manager.rb', line 122

def guard_already_tagged
  sh('git tag').split(/\n/).include?(@version.to_s) and raise("This tag has already been committed to the repo.")
end

#guard_cleanObject



118
119
120
# File 'lib/tumbler/manager.rb', line 118

def guard_clean
  clean? or raise("There are files that need to be committed first.")
end

#latest_changesObject



161
162
163
164
165
# File 'lib/tumbler/manager.rb', line 161

def latest_changes
  changes = sh("git log --pretty=format:'%h (%aN) %s' --no-color #{@version}..HEAD").
    scan(/([a-f0-9]{7}) \((.*?)\) (.*)$/).
    map{|line| Change.new(line[0], line[1], line[2])}
end

#lockfile_pathObject



42
43
44
# File 'lib/tumbler/manager.rb', line 42

def lockfile_path
  File.join(@base, 'Gemfile.lock')
end

#pushObject



138
139
140
141
142
143
# File 'lib/tumbler/manager.rb', line 138

def push
  inform "Pushing commit & tags" do
    sh "git push --all"
    sh "git push --tags"
  end
end

#reloadObject



155
156
157
158
159
# File 'lib/tumbler/manager.rb', line 155

def reload
  reset
  @gem = Gem.new(self)
  instance_eval(File.read(config_path), config_path, 1)
end

#resetObject



69
70
71
72
# File 'lib/tumbler/manager.rb', line 69

def reset
  @version = nil
  @changelog = nil
end

#revert_on_errorObject



107
108
109
110
111
112
113
114
115
116
# File 'lib/tumbler/manager.rb', line 107

def revert_on_error
  current_ref = current_revision
  begin
    yield
  rescue
    inform "Undoing commit"
    sh "git reset --hard #{current_ref}"
    raise
  end
end

#tagObject



145
146
147
148
149
# File 'lib/tumbler/manager.rb', line 145

def tag
  inform "Tagging version #{@version.to_s}" do
    sh "git tag #{@version.to_s}"
  end
end

#tag_and_pushObject



83
84
85
86
87
88
89
90
91
92
# File 'lib/tumbler/manager.rb', line 83

def tag_and_push
  inform "Tagging & pushing" do
    @changelog.commit if @changelog && !clean?
    guard_clean
    guard_already_tagged
    tag
    push
    @gem.push
  end
end

#tagsObject



151
152
153
# File 'lib/tumbler/manager.rb', line 151

def tags
  sh('git tag').split(/\n/)
end

#use_color(state = true) ⇒ Object



54
55
56
# File 'lib/tumbler/manager.rb', line 54

def use_color(state = true)
  Sickill::Rainbow.enabled = state
end

#use_gem(&block) ⇒ Object



58
59
60
# File 'lib/tumbler/manager.rb', line 58

def use_gem(&block)
  @gem.instance_eval(block)
end

#version_file(file = default_version_file, &block) ⇒ Object



46
47
48
49
50
51
52
# File 'lib/tumbler/manager.rb', line 46

def version_file(file = default_version_file, &block)
  @version = Manager::Version.new(self)
  @version.filename(file)
  @version.instance_eval(&block) if block
  @version.reload
  @version
end