Class: Rookie::Tasks::Gem
- Inherits:
-
Rake::TaskLib
- Object
- Rake::TaskLib
- Rookie::Tasks::Gem
- Defined in:
- lib/rookie/tasks/gem.rb
Overview
Adds various gem management tasks that allows you to build, install, uninstall and release your gem with ease.
Instance Attribute Summary collapse
-
#dir ⇒ Object
The directory where
.gem
files will be stored. -
#spec ⇒ Object
The gem specification.
Instance Method Summary collapse
-
#build_gem ⇒ Object
Builds the gem from the specification and moves it to the gem directory.
-
#clean! ⇒ Object
Removes the gem directory.
-
#define_tasks! ⇒ Object
Defines the gem tasks.
-
#gem(cmd, arg = gem_file) ⇒ Object
Executes a gem command.
-
#gem_file ⇒ Object
The full path to the gem file.
-
#gem_file_name ⇒ Object
The name of the packaged gem file.
-
#initialize(gemspec = nil, gem_dir = 'gem') {|_self| ... } ⇒ Gem
constructor
Creates a new gem task with the given gem specification and temporary gem directory.
Constructor Details
#initialize(gemspec = nil, gem_dir = 'gem') {|_self| ... } ⇒ Gem
Creates a new gem task with the given gem specification and temporary gem directory.
Tasks do not get defined automatically; don’t forget to call #define_tasks!
45 46 47 48 49 |
# File 'lib/rookie/tasks/gem.rb', line 45 def initialize(gemspec = nil, gem_dir = 'gem') self.spec = gemspec self.dir = gem_dir yield self if block_given? end |
Instance Attribute Details
#dir ⇒ Object
The directory where .gem
files will be stored. 'gem'
by default.
This directory will be completely erased by the clean
task. Make sure it is not in use!
19 20 21 |
# File 'lib/rookie/tasks/gem.rb', line 19 def dir @dir end |
#spec ⇒ Object
The gem specification.
12 13 14 |
# File 'lib/rookie/tasks/gem.rb', line 12 def spec @spec end |
Instance Method Details
#build_gem ⇒ Object
Builds the gem from the specification and moves it to the gem directory.
62 63 64 65 66 |
# File 'lib/rookie/tasks/gem.rb', line 62 def build_gem FileUtils.mkdir_p dir gem = ::Gem::Builder.new(spec).build FileUtils.mv gem, dir end |
#clean! ⇒ Object
Removes the gem directory.
74 75 76 |
# File 'lib/rookie/tasks/gem.rb', line 74 def clean! FileUtils.rm_rf dir end |
#define_tasks! ⇒ Object
Defines the gem tasks.
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/rookie/tasks/gem.rb', line 79 def define_tasks! directory dir namespace :gem do desc 'Builds the gem from the specification' task :build => dir do build_gem end desc 'Pushes the gem to rubygems.org' task :push => :build do sh gem :push end desc 'Same as gem:push' task :release => :push desc 'Installs the gem locally' task :install => :build do sh gem :install end desc 'Uninstalls the gem' task :uninstall do sh gem(:uninstall, spec.name) end desc 'Removes the gem package directory' task :clean do clean! end desc 'Installs the gem locally and cleans up' task :setup => [ :install, :clean ] end desc 'Same as gem:build' task :gem => 'gem:build' end |
#gem(cmd, arg = gem_file) ⇒ Object
Executes a gem command.
69 70 71 |
# File 'lib/rookie/tasks/gem.rb', line 69 def gem(cmd, arg = gem_file) "gem #{cmd} #{arg}" end |
#gem_file ⇒ Object
The full path to the gem file.
57 58 59 |
# File 'lib/rookie/tasks/gem.rb', line 57 def gem_file File.join dir, gem_file_name end |
#gem_file_name ⇒ Object
The name of the packaged gem file.
52 53 54 |
# File 'lib/rookie/tasks/gem.rb', line 52 def gem_file_name "#{spec.name}-#{spec.version}.gem" end |