Class: Jeweler::Commands::ReleaseGemspec

Inherits:
Object
  • Object
show all
Includes:
ReleaseCommon
Defined in:
lib/jeweler/commands/release_gemspec.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ReleaseCommon

#clean_staging_area?

Constructor Details

#initialize(attributes = {}) ⇒ ReleaseGemspec

Returns a new instance of ReleaseGemspec.



12
13
14
15
16
17
18
# File 'lib/jeweler/commands/release_gemspec.rb', line 12

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.



10
11
12
# File 'lib/jeweler/commands/release_gemspec.rb', line 10

def base_dir
  @base_dir
end

#gemspecObject

Returns the value of attribute gemspec.



10
11
12
# File 'lib/jeweler/commands/release_gemspec.rb', line 10

def gemspec
  @gemspec
end

#gemspec_helperObject

Returns the value of attribute gemspec_helper.



10
11
12
# File 'lib/jeweler/commands/release_gemspec.rb', line 10

def gemspec_helper
  @gemspec_helper
end

#outputObject

Returns the value of attribute output.



10
11
12
# File 'lib/jeweler/commands/release_gemspec.rb', line 10

def output
  @output
end

#repoObject

Returns the value of attribute repo.



10
11
12
# File 'lib/jeweler/commands/release_gemspec.rb', line 10

def repo
  @repo
end

#versionObject

Returns the value of attribute version.



10
11
12
# File 'lib/jeweler/commands/release_gemspec.rb', line 10

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_gemspec.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

#base_dir_pathObject



64
65
66
# File 'lib/jeweler/commands/release_gemspec.rb', line 64

def base_dir_path
  Pathname.new(base_dir).realpath
end

#commit_gemspec!Object



36
37
38
39
40
41
# File 'lib/jeweler/commands/release_gemspec.rb', line 36

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?Boolean

Returns:

  • (Boolean)


48
49
50
51
# File 'lib/jeweler/commands/release_gemspec.rb', line 48

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

#regenerate_gemspec!Object



43
44
45
46
# File 'lib/jeweler/commands/release_gemspec.rb', line 43

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

#runObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/jeweler/commands/release_gemspec.rb', line 20

def run
  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('master')

  regenerate_gemspec!
  commit_gemspec! if gemspec_changed?

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

#working_subdirObject



57
58
59
60
61
62
# File 'lib/jeweler/commands/release_gemspec.rb', line 57

def working_subdir
  return @working_subdir if @working_subdir
  cwd = base_dir_path
  @working_subdir = cwd.relative_path_from(Pathname.new(repo.dir.path))
  @working_subdir
end