class Jeweler::Commands::ReleaseGemspec

Attributes

base_dir[RW]
gemspec[RW]
gemspec_helper[W]
output[RW]
repo[RW]
version[RW]

Public Class Methods

build_for(jeweler) click to toggle source
# File lib/jeweler/commands/release_gemspec.rb, line 71
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
new(attributes = {}) click to toggle source
# File lib/jeweler/commands/release_gemspec.rb, line 9
def initialize(attributes = {})
  self.output = $stdout

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

Public Instance Methods

base_dir_path() click to toggle source
# File lib/jeweler/commands/release_gemspec.rb, line 67
def base_dir_path
  Pathname.new(base_dir).realpath
end
clean_staging_area?() click to toggle source
# File lib/jeweler/commands/release_gemspec.rb, line 37
def clean_staging_area?
  # surprisingly simpler than ruby-git
  `git ls-files --deleted --modified --others --exclude-standard` == ''
end
commit_gemspec!() click to toggle source
# File lib/jeweler/commands/release_gemspec.rb, line 42
def commit_gemspec!
  gemspec_gitpath = working_subdir.join(gemspec_helper.path)
  repo.add(gemspec_gitpath.to_s)
  output.puts "Committing #{gemspec_gitpath}"
  repo.commit "Regenerate gemspec for version #{version}"
end
gemspec_changed?() click to toggle source
# File lib/jeweler/commands/release_gemspec.rb, line 54
def gemspec_changed?
  # OMGHAX. ruby-git status always ends up being 'M', so let's do it a crazy way
  system "git status -s #{working_subdir.join(gemspec_helper.path)} | grep  #{working_subdir.join(gemspec_helper.path)} > /dev/null 2>/dev/null"
end
gemspec_helper() click to toggle source
# File lib/jeweler/commands/release_gemspec.rb, line 59
def gemspec_helper
  @gemspec_helper ||= Jeweler::GemSpecHelper.new(gemspec, base_dir)
end
regenerate_gemspec!() click to toggle source
# File lib/jeweler/commands/release_gemspec.rb, line 49
def regenerate_gemspec!
  gemspec_helper.update_version(version)
  gemspec_helper.write
end
run(args = {}) click to toggle source
# File lib/jeweler/commands/release_gemspec.rb, line 17
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)

  regenerate_gemspec!
  commit_gemspec! if gemspec_changed?

  output.puts "Pushing #{local_branch} to #{remote}"
  repo.push(remote, "#{local_branch}:#{remote_branch}")
end
working_subdir() click to toggle source
# File lib/jeweler/commands/release_gemspec.rb, line 63
def working_subdir
  @working_subdir ||= base_dir_path.relative_path_from(Pathname.new(repo.dir.path))
end