Class: Jeweler::Commands::Release

Inherits:
Object
  • Object
show all
Defined in:
lib/jeweler/commands/release.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Release

Returns a new instance of Release.



6
7
8
9
10
11
12
# File 'lib/jeweler/commands/release.rb', line 6

def initialize(attributes = {})
  self.output = $stdout

  attributes.each_pair do |key, value|
    send("#{key}=", value)
  end
end

Instance Attribute Details

#base_dirObject

Returns the value of attribute base_dir.



4
5
6
# File 'lib/jeweler/commands/release.rb', line 4

def base_dir
  @base_dir
end

#gemspecObject

Returns the value of attribute gemspec.



4
5
6
# File 'lib/jeweler/commands/release.rb', line 4

def gemspec
  @gemspec
end

#gemspec_helperObject

Returns the value of attribute gemspec_helper.



4
5
6
# File 'lib/jeweler/commands/release.rb', line 4

def gemspec_helper
  @gemspec_helper
end

#outputObject

Returns the value of attribute output.



4
5
6
# File 'lib/jeweler/commands/release.rb', line 4

def output
  @output
end

#repoObject

Returns the value of attribute repo.



4
5
6
# File 'lib/jeweler/commands/release.rb', line 4

def repo
  @repo
end

#versionObject

Returns the value of attribute version.



4
5
6
# File 'lib/jeweler/commands/release.rb', line 4

def version
  @version
end

Class Method Details

.build_for(jeweler) ⇒ Object



68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/jeweler/commands/release.rb', line 68

def self.build_for(jeweler)
  command = self.new

  command.base_dir = jeweler.base_dir
  command.gemspec = jeweler.gemspec
  command.version = jeweler.version
  command.repo = jeweler.repo
  command.output = jeweler.output
  command.gemspec_helper = jeweler.gemspec_helper

  command
end

Instance Method Details

#any_pending_changes?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/jeweler/commands/release.rb', line 28

def any_pending_changes?
  !(@repo.status.added.empty? && @repo.status.deleted.empty? && @repo.status.changed.empty?)
end

#commit_gemspec!Object



40
41
42
43
44
# File 'lib/jeweler/commands/release.rb', line 40

def commit_gemspec!
  repo.add(gemspec_helper.path)
  output.puts "Committing #{gemspec_helper.path}"
  repo.commit "Regenerated gemspec for version #{version}"
end

#gemspec_changed?Boolean

Returns:

  • (Boolean)


60
61
62
# File 'lib/jeweler/commands/release.rb', line 60

def gemspec_changed?
  ! any_pending_changes?
end

#regenerate_gemspec!Object



46
47
48
49
# File 'lib/jeweler/commands/release.rb', line 46

def regenerate_gemspec!
  gemspec_helper.update_version(version)
  gemspec_helper.write
end

#release_tagObject



51
52
53
# File 'lib/jeweler/commands/release.rb', line 51

def release_tag
  "v#{version}"
end

#release_tagged?Boolean

Returns:

  • (Boolean)


55
56
57
58
# File 'lib/jeweler/commands/release.rb', line 55

def release_tagged?
  tag = repo.tag(release_tag) rescue nil
  ! tag.nil?
end

#runObject



14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/jeweler/commands/release.rb', line 14

def run
  raise "Hey buddy, try committing them files first" if any_pending_changes?

  repo.checkout('master')

  regenerate_gemspec!
  commit_gemspec! if gemspec_changed?

  output.puts "Pushing master to origin"
  repo.push

  tag_release! unless release_tagged?
end

#tag_release!Object



32
33
34
35
36
37
38
# File 'lib/jeweler/commands/release.rb', line 32

def tag_release!
  output.puts "Tagging #{release_tag}"
  repo.add_tag(release_tag)

  output.puts "Pushing #{release_tag} to origin"
  repo.push('origin', release_tag)
end