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.



9
10
11
12
13
14
15
# 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

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



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

def gemspec_helper
  @gemspec_helper ||= Jeweler::GemSpecHelper.new(gemspec, base_dir)
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



71
72
73
74
75
76
77
78
79
80
81
82
# 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

Instance Method Details

#base_dir_pathObject



67
68
69
# File 'lib/jeweler/commands/release_gemspec.rb', line 67

def base_dir_path
  Pathname.new(base_dir).realpath
end

#clean_staging_area?Boolean

Returns:

  • (Boolean)


37
38
39
40
# 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!Object



42
43
44
45
46
47
# 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?Boolean

Returns:

  • (Boolean)


54
55
56
57
# 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

#regenerate_gemspec!Object



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

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

#run(args = {}) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# 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_subdirObject



63
64
65
# 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