Class: RakeTasks::Gem

Inherits:
Object
  • Object
show all
Defined in:
lib/rake_tasks/gem.rb

Overview

This class will handle gem utilities.

Class Method Summary collapse

Class Method Details

.gem_fileObject



65
66
67
# File 'lib/rake_tasks/gem.rb', line 65

def gem_file
  @gem_file ||= System.dir_glob('*.gem').first
end

.gem_file?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/rake_tasks/gem.rb', line 43

def gem_file?
  return !gem_file.nil?
end

.gem_specObject

Get the gem specification.



56
57
58
# File 'lib/rake_tasks/gem.rb', line 56

def gem_spec
  System.load_gemspec(gem_spec_file) if gemspec_file?
end

.gem_spec_fileObject

Check for a gem spec file.



61
62
63
# File 'lib/rake_tasks/gem.rb', line 61

def gem_spec_file
  System.dir_glob('*.gemspec').first
end

.gem_title(spec = gem_spec) ⇒ Object

Returns the gem title. This is the gem name with underscores removed. Wherever an underscore is removed, the next letter is capitalized.



50
51
52
53
# File 'lib/rake_tasks/gem.rb', line 50

def gem_title(spec = gem_spec)
  return nil unless spec.respond_to?(:name)
  spec.name.split('_').map { |w| w.capitalize }.join('')
end

.gemspec_file?Boolean

Check whether a gem spec file exists for this project.

Returns:

  • (Boolean)


39
40
41
# File 'lib/rake_tasks/gem.rb', line 39

def gemspec_file?
  return !gem_spec_file.nil?
end

.pushObject



87
88
89
90
91
92
# File 'lib/rake_tasks/gem.rb', line 87

def push
  ::Gems.configure do |config|
    config.key = ENV['RUBYGEMS_API_KEY']
  end
  ::Gems.push File.new(gem_file)
end

.version(spec = gem_spec) ⇒ Object

Returns the name and version from the specified gem specification.



70
71
72
73
74
# File 'lib/rake_tasks/gem.rb', line 70

def version(spec = gem_spec)
  if spec.respond_to?(:name) && spec.respond_to?(:version)
    "#{spec.name} version #{spec.version}"
  end
end

.version!(value, spec = gem_spec) ⇒ Object

Updates the version in the gem specification file.



77
78
79
80
81
82
83
84
85
# File 'lib/rake_tasks/gem.rb', line 77

def version!(value, spec = gem_spec)
  return unless gem_spec_file

  temp = StringIO.new
  write_temp spec, temp, gem_spec_file, value

  temp.rewind
  write_file gem_spec_file, temp
end