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

- (ReleaseGemspec) initialize(attributes = {})



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

- (Object) base_dir

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

- (Object) gemspec

Returns the value of attribute gemspec



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

def gemspec
  @gemspec
end

- (Object) gemspec_helper

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

- (Object) output

Returns the value of attribute output



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

def output
  @output
end

- (Object) repo

Returns the value of attribute repo



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

def repo
  @repo
end

- (Object) version

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

+ (Object) build_for(jeweler)



73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/jeweler/commands/release_gemspec.rb', line 73

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

- (Object) base_dir_path



69
70
71
# File 'lib/jeweler/commands/release_gemspec.rb', line 69

def base_dir_path
  Pathname.new(base_dir).realpath
end

- (Boolean) clean_staging_area?



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

def clean_staging_area?
  # surprisingly simpler than ruby-git
  `git ls-files --deleted --modified --others --exclude-standard` == ""
end

- (Object) commit_gemspec!



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

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

- (Boolean) gemspec_changed?



53
54
55
56
# File 'lib/jeweler/commands/release_gemspec.rb', line 53

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

- (Object) regenerate_gemspec!



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

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

- (Object) run(args = {})



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

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

- (Object) working_subdir



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

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