Class: Jeweler::Commands::ReleaseToGit

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ ReleaseToGit

Returns a new instance of ReleaseToGit.



6
7
8
9
10
11
12
# File 'lib/jeweler/commands/release_to_git.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_to_git.rb', line 4

def base_dir
  @base_dir
end

#gemspecObject

Returns the value of attribute gemspec.



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

def gemspec
  @gemspec
end

#gemspec_helperObject

Returns the value of attribute gemspec_helper.



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

def gemspec_helper
  @gemspec_helper
end

#outputObject

Returns the value of attribute output.



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

def output
  @output
end

#repoObject

Returns the value of attribute repo.



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

def repo
  @repo
end

#versionObject

Returns the value of attribute version.



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

def version
  @version
end

Class Method Details

.build_for(jeweler) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/jeweler/commands/release_to_git.rb', line 54

def self.build_for(jeweler)
  command = 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

#clean_staging_area?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/jeweler/commands/release_to_git.rb', line 37

def clean_staging_area?
  `git ls-files --deleted --modified --others --exclude-standard` == ''
end

#release_not_tagged?Boolean

Returns:

  • (Boolean)


45
46
47
48
49
50
51
52
# File 'lib/jeweler/commands/release_to_git.rb', line 45

def release_not_tagged?
  tag = begin
          repo.tag(release_tag)
        rescue
          nil
        end
  tag.nil?
end

#release_tagObject



41
42
43
# File 'lib/jeweler/commands/release_to_git.rb', line 41

def release_tag
  "v#{version}"
end

#run(args = {}) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/jeweler/commands/release_to_git.rb', line 14

def run(args = {})
  remote = args[:remote] || 'origin'
  branch = args[:branch] || 'master'
  local_branch = args[:local_branch] || branch
  remote_branch = args[:remote_branch] || branch

  unless clean_staging_area?
    system 'git status'
    raise 'Unclean staging area! Be sure to commit or .gitignore everything first. See `git status` above.'
  end

  repo.checkout(local_branch)
  repo.push(remote, "#{local_branch}:#{remote_branch}")

  if release_not_tagged?
    output.puts "Tagging #{release_tag}"
    repo.add_tag(release_tag)

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