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

- (ReleaseToGit) initialize(attributes = {})



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

- (Object) base_dir

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

- (Object) gemspec

Returns the value of attribute gemspec



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

def gemspec
  @gemspec
end

- (Object) gemspec_helper

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

- (Object) output

Returns the value of attribute output



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

def output
  @output
end

- (Object) repo

Returns the value of attribute repo



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

def repo
  @repo
end

- (Object) version

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

+ (Object) build_for(jeweler)



50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/jeweler/commands/release_to_git.rb', line 50

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

- (Boolean) clean_staging_area?



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

- (Boolean) release_not_tagged?



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

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

- (Object) release_tag



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

def release_tag
  "v#{version}"
end

- (Object) run(args = {})



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