Class: Jeweler::Commands::ReleaseGemspec

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ ReleaseGemspec

Returns a new instance of ReleaseGemspec.



8
9
10
11
12
13
14
# File 'lib/jeweler/commands/release_gemspec.rb', line 8

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.



6
7
8
# File 'lib/jeweler/commands/release_gemspec.rb', line 6

def base_dir
  @base_dir
end

#gemspecObject

Returns the value of attribute gemspec.



6
7
8
# File 'lib/jeweler/commands/release_gemspec.rb', line 6

def gemspec
  @gemspec
end

#gemspec_helperObject

Returns the value of attribute gemspec_helper.



6
7
8
# File 'lib/jeweler/commands/release_gemspec.rb', line 6

def gemspec_helper
  @gemspec_helper
end

#outputObject

Returns the value of attribute output.



6
7
8
# File 'lib/jeweler/commands/release_gemspec.rb', line 6

def output
  @output
end

#repoObject

Returns the value of attribute repo.



6
7
8
# File 'lib/jeweler/commands/release_gemspec.rb', line 6

def repo
  @repo
end

#versionObject

Returns the value of attribute version.



6
7
8
# File 'lib/jeweler/commands/release_gemspec.rb', line 6

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

#clean_staging_area?Boolean

Returns:

  • (Boolean)


31
32
33
34
# File 'lib/jeweler/commands/release_gemspec.rb', line 31

def clean_staging_area?
  # surprisingly simpler than ruby-git
  `git ls-files --deleted --modified --others --exclude-standard` == ""
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



16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/jeweler/commands/release_gemspec.rb', line 16

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?

  output.puts "Pushing master to origin"
  repo.push
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