Class: Inventory::Rake::Tasks::Gem
- Inherits:
-
Object
- Object
- Inventory::Rake::Tasks::Gem
- Includes:
- Rake::DSL
- Defined in:
- lib/inventory/rake/tasks/gem.rb
Instance Attribute Summary collapse
-
#inventory ⇒ Object
writeonly
Sets the attribute inventory.
-
#specification ⇒ Object
writeonly
Sets the attribute specification.
Instance Method Summary collapse
- #define ⇒ Object
-
#initialize(options = {}) {|_self, @specification| ... } ⇒ Gem
constructor
A new instance of Gem.
Constructor Details
#initialize(options = {}) {|_self, @specification| ... } ⇒ Gem
Returns a new instance of Gem.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/inventory/rake/tasks/gem.rb', line 6 def initialize( = {}) self.inventory = .fetch(:inventory, Inventory::Rake::Tasks.inventory) self.specification = .fetch(:specification, Gem::Specification.new{ |s| next unless @inventory s.name = @inventory.package s.version = @inventory.to_s # TODO: We could probably skip #to_s s.description = IO.read('README') s.summary = s.description[/^.*?\./].lstrip s.files = @inventory.files # TODO: We can skip #files and rely on #to_a s.require_paths = @inventory.lib_directories @inventory.dependencies.add_to_gem_specification s }) yield self, @specification if block_given? define end |
Instance Attribute Details
#inventory=(value) ⇒ Object (writeonly)
Sets the attribute inventory
190 191 192 |
# File 'lib/inventory/rake/tasks/gem.rb', line 190 def inventory=(value) @inventory = value end |
#specification=(value) ⇒ Object (writeonly)
Sets the attribute specification
190 191 192 |
# File 'lib/inventory/rake/tasks/gem.rb', line 190 def specification=(value) @specification = value end |
Instance Method Details
#define ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 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 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 |
# File 'lib/inventory/rake/tasks/gem.rb', line 28 def define desc 'Create specifications' unless Rake::Task.task_defined? :spec task :spec => :'gem:spec' gemspec = '%s.gemspec' % @specification.name Inventory::Rake::Tasks.cleanfiles << gemspec desc 'Create gem specification' unless Rake::Task.task_defined? :'gem:spec' task :'gem:spec' => gemspec file gemspec => %w'Rakefile README' + [@inventory.path] do |t| tmp = '%s.tmp' % t.name rm([t.name, tmp], :force => true) 'gem specification --ruby %s > %s' % [@specification.name, tmp] if verbose File.open(tmp, 'wb') do |f| f.write @specification.to_ruby end chmod File.stat(tmp).mode & ~0222, tmp mv tmp, t.name end desc 'Create files for distribution' unless Rake::Task.task_defined? :dist task :dist => :'gem:dist' desc 'Create %s for distribution' % @specification.file_name task :'gem:dist' => [:'inventory:check', @specification.file_name] file @specification.file_name => @specification.files do require 'rubygems' unless defined? Gem 'gem build %s' % gemspec if verbose Gem::Builder.new(@specification).build end desc 'Check files before distribution' unless Rake::Task.task_defined? :'dist:check' task :'dist:check' => [:dist, :'gem:dist:check'] desc 'Check %s before distribution' % @specification.file_name task :'gem:dist:check' => :'gem:dist' do require 'rubygems' unless defined? Gem require 'rubygems/installer' unless defined? Gem::Installer checkdir = @specification.full_name 'gem unpack %s --target %s' % [@specification.file_name, checkdir] if verbose Gem::Installer.new(@specification.file_name, :unpack => true). unpack File.(checkdir) chdir checkdir do sh '%s %sinventory:check check' % [Rake.application.name, Rake.application..silent ? '-s ' : ''] end rm_r checkdir end desc 'Install dependencies on the local system' unless Rake::Task.task_defined? :'deps:install' task :'deps:install' => :':gem:deps:install' desc 'Install dependencies in ruby gem directory' task :'gem:deps:install' do require 'rubygems' unless defined? Gem require 'rubygems/dependency_installer' unless defined? Gem::DependencyInstaller @specification.dependencies.each do |dependency| "gem install %s -v '%s'" % [dependency.name, dependency.requirement] if verbose Gem::DependencyInstaller.new.install dependency.name, dependency.requirement end end desc 'Install dependencies for the current user' unless Rake::Task.task_defined? :'deps:install:user' task :'deps:install:user' => :':gem:deps:install:user' desc 'Install dependencies for the current user' task :'gem:deps:install:user' do require 'rubygems' unless defined? Gem require 'rubygems/dependency_installer' unless defined? Gem::DependencyInstaller @specification.dependencies.each do |dependency| "gem install --user-install --bindir %s %s -v '%s'" % [Gem.bindir(Gem.user_dir), dependency.name, dependency.requirement] if verbose Gem::DependencyInstaller. new(:user_install => true, :bindir => Gem.bindir(Gem.user_dir)). install dependency.name, dependency.requirement end end desc 'Install distribution files on the local system' unless Rake::Task.task_defined? :install task :install => :'gem:install' desc 'Install %s in ruby gem directory' % @specification.file_name task :'gem:install' => :'gem:dist' do |t| require 'rubygems' unless defined? Gem require 'rubygems/dependency_installer' unless defined? Gem::DependencyInstaller 'gem install %s' % @specification.file_name if verbose Gem::DependencyInstaller. new(:ignore_dependencies => true). install @specification.file_name end desc 'Install distribution files for the current user' unless Rake::Task.task_defined? :'install:user' task :'install:user' => :'gem:install:user' desc 'Install %s in user gem directory' % @specification.file_name task :'gem:install:user' => :'gem:dist' do require 'rubygems' unless defined? Gem require 'rubygems/dependency_installer' unless defined? Gem::DependencyInstaller 'gem install --user-install --bindir %s %s' % [Gem.bindir(Gem.user_dir), @specification.file_name] if verbose Gem::DependencyInstaller. new(:ignore_dependencies => true, :user_install => true, :bindir => Gem.bindir(Gem.user_dir)). install @specification.file_name end desc 'Delete all files installed on the local system' unless Rake::Task.task_defined? :uninstall task :uninstall => :'gem:uninstall' desc 'Uninstall %s from ruby gem directory' % @specification.file_name task :'gem:uninstall' do require 'rubygems' unless defined? Gem # TODO: I have absolutely no idea why this is needed, but it is. require 'rubygems/user_interaction' unless defined? Gem::UserInteraction require 'rubygems/uninstaller' unless defined? Gem::Uninstaller 'gem uninstall --executables %s' % @specification.name if verbose Gem::Uninstaller.new(@specification.name, :executables => true, :version => @specification.version).uninstall end desc 'Delete all files installed for current user' unless Rake::Task.task_defined? :'uninstall:user' task :'uninstall:user' => :'gem:uninstall:user' desc 'Uninstall %s from user gem directory' % @specification.file_name task :'gem:uninstall:user' do require 'rubygems' unless defined? Gem # TODO: I have absolutely no idea why this is needed, but it is. require 'rubygems/user_interaction' unless defined? Gem::UserInteraction require 'rubygems/uninstaller' unless defined? Gem::Uninstaller 'gem uninstall --executables --install-dir %s %s' % [Gem.user_dir, @specification.name] if verbose Gem::Uninstaller.new(@specification.name, :executables => true, :install_dir => Gem.user_dir, :version => @specification.version).uninstall end desc 'Push distribution files to distribution hubs' unless Rake::Task.task_defined? :push task :push => :'gem:push' desc 'Push %s to rubygems.org' % @specification.file_name task :'gem:push' => :'gem:dist:check' do sh 'gem push -%s-verbose %s' % [verbose ? '' : '-no', @specification.file_name] end end |