class RakeTasks::Gem
This class will handle gem utilities.
Public Class Methods
gem_file()
click to toggle source
# File lib/rake_tasks/gem.rb, line 121 def gem_file @gem_file ||= System.dir_glob('*.gem').first end
gem_file?()
click to toggle source
# File lib/rake_tasks/gem.rb, line 99 def gem_file? return !gem_file.nil? end
gem_spec()
click to toggle source
Get the gem specification.
# File lib/rake_tasks/gem.rb, line 112 def gem_spec System.load_gemspec(gem_spec_file) if gemspec_file? end
gem_spec_file()
click to toggle source
Check for a gem spec file.
# File lib/rake_tasks/gem.rb, line 117 def gem_spec_file System.dir_glob('*.gemspec').first end
gem_title(spec = gem_spec)
click to toggle source
Returns the gem title. This is the gem name with underscores removed. Wherever an underscore is removed, the next letter is capitalized.
# File lib/rake_tasks/gem.rb, line 106 def gem_title(spec = gem_spec) return nil unless spec.respond_to?(:name) spec.name.split('_').map { |w| w.capitalize }.join('') end
gem_version()
click to toggle source
# File lib/rake_tasks/gem.rb, line 137 def gem_version Version.new version_number end
gemspec_file?()
click to toggle source
Check whether a gem spec file exists for this project.
# File lib/rake_tasks/gem.rb, line 95 def gemspec_file? return !gem_spec_file.nil? end
push()
click to toggle source
# File lib/rake_tasks/gem.rb, line 152 def push ::Gems.configure do |config| config.key = ENV['RUBYGEMS_API_KEY'] end ::Gems.push File.new(gem_file) end
version(spec = gem_spec)
click to toggle source
Returns the name and version from the specified gem specification.
# File lib/rake_tasks/gem.rb, line 126 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)
click to toggle source
Updates the version in the gem specification file.
# File lib/rake_tasks/gem.rb, line 142 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
version_number(spec = gem_spec)
click to toggle source
Returns the version from the specified gem specification.
# File lib/rake_tasks/gem.rb, line 133 def version_number(spec = gem_spec) spec.version.to_s if spec.respond_to?(:version) end
Private Class Methods
write_file(gem_spec_file, stream)
click to toggle source
Write the contents of a stream to a file.
# File lib/rake_tasks/gem.rb, line 162 def write_file(gem_spec_file, stream) System.open_file(gem_spec_file, 'w') do |file| while line = stream.gets file.puts line end end end
write_temp(spec, stream, gem_spec_file, version)
click to toggle source
Write the contents of a file to an in-memory stream object, changing the version.
# File lib/rake_tasks/gem.rb, line 172 def write_temp(spec, stream, gem_spec_file, version) System.open_file(gem_spec_file, 'r') do |file| while line = file.gets if line =~ /version *= *['"]#{spec.version}['"]/ stream.puts line.sub(/['"].*['"]/, "'#{version}'") else stream.puts line end end end end