In Files

Hoe::Deps

Deps plugin for hoe.

Tasks Provided:

check_extra_deps

Install missing dependencies.

deps:email

Print a contact list for gems dependent on this gem

deps:fetch

Fetch all the dependent gems of this gem into tarballs

deps:list

List all the dependent gems of this gem

Constants

GEMURL

The main rubygems repository.

Public Instance Methods

define_deps_tasks() click to toggle source

Define tasks for plugin.

     # File lib/hoe/deps.rb, line 23
 23:   def define_deps_tasks
 24:     namespace :deps do
 25:       desc "List all the dependent gems of this gem"
 26:       task :list do
 27:         gems = self.get_gems_by_name
 28:         gem  = gems[self.name]
 29: 
 30:         abort "Couldn't find gem: #{self.name}" unless gem
 31: 
 32:         deps = self.dependent_upon self.name
 33:         max  = deps.map { |s| s.full_name.size }.max
 34: 
 35:         puts "  dependents:"
 36:         unless deps.empty? then
 37:           deps.sort_by { |spec| spec.full_name }.each do |spec|
 38:             vers = spec.dependencies.find {|s| s.name == name}.requirements_list
 39:             puts "    %-*s - %s" % [max, spec.full_name, vers.join(", ")]
 40:           end
 41:         else
 42:           puts "    none"
 43:         end
 44:       end
 45: 
 46:       desc "Print a contact list for gems dependent on this gem"
 47:       task :email do
 48:         gems = self.get_gems_by_name
 49:         gem  = gems[self.name]
 50: 
 51:         abort "Couldn't find gem: #{self.name}" unless gem
 52: 
 53:         deps = self.dependent_upon self.name
 54:         email = deps.map { |s| s.email }.compact.flatten.sort.uniq
 55:         email = email.map { |s| s.split(/,\s*/) }.flatten.sort.uniq
 56: 
 57:         email.map! { |s| # don't you people realize how easy this is?
 58:           s.gsub(/ at | _at_ |\s*(atmark|@nospam@|-at?-|@at?@|<at?>|\[at?\]|\(at?\))\s*/, '@').gsub(/\s*(dot|\[d(ot)?\]|\.dot\.)\s*/, '.').gsub(/\s+com$/, '.com')
 59:         }
 60: 
 61:         bad, good = email.partition { |e| e !~ /^[\w.+-]+\@[\w.+-]+$/ }
 62: 
 63:         warn "Rejecting #{bad.size} email. I couldn't unmunge them." unless
 64:           bad.empty?
 65: 
 66:         puts good.join(", ")
 67: 
 68:         warn "Warning: couldn't extract any email addresses" if good.empty?
 69:       end
 70: 
 71:       desc "Fetch all the dependent gems of this gem into tarballs"
 72:       task :fetch do
 73:         deps = self.dependent_upon self.name
 74: 
 75:         mkdir "deps" unless File.directory? "deps"
 76:         Dir.chdir "deps" do
 77:           begin
 78:             deps.sort_by { |spec| spec.full_name }.each do |spec|
 79:               full_name = spec.full_name
 80:               tgz_name  = "#{full_name}.tgz"
 81:               gem_name  = "#{full_name}.gem"
 82: 
 83:               next if File.exist? tgz_name
 84:               FileUtils.rm_rf [full_name, gem_name]
 85: 
 86:               begin
 87:                 warn "downloading #{full_name}"
 88:                 Gem::RemoteFetcher.fetcher.download(spec, GEMURL, Dir.pwd)
 89:                 FileUtils.mv "cache/#{gem_name}", '.'
 90:               rescue Gem::RemoteFetcher::FetchError
 91:                 warn "  failed"
 92:                 next
 93:               end
 94: 
 95:               warn "converting #{gem_name} to tarball"
 96: 
 97:               system "gem unpack #{gem_name} 2> /dev/null"
 98:               system "gem spec -l #{gem_name} > #{full_name}/gemspec.rb"
 99:               system "tar zmcf #{tgz_name} #{full_name}"
100:               FileUtils.rm_rf [full_name, gem_name, "cache"]
101:             end
102:           ensure
103:             FileUtils.rm_rf "cache"
104:           end
105:         end
106:       end
107:     end
108: 
109:     desc 'Install missing dependencies.'
110:     task :check_extra_deps do
111:       # extra_deps = [["rubyforge", ">= 1.0.0"], ["rake", ">= 0.8.1"]]
112:       (extra_deps + extra_dev_deps).each do |dep|
113:         begin
114:           gem(*dep)
115:         rescue Gem::LoadError
116:           name, req, = dep
117: 
118:           install_gem name, req, false
119:         end
120:       end
121:     end
122: 
123:     desc 'Install missing plugins.'
124:     task :install_plugins do
125:       install_missing_plugins
126:     end
127:   end
dependent_upon(name) click to toggle source

Return all the dependencies on the named rubygem.

     # File lib/hoe/deps.rb, line 201
201:   def dependent_upon name
202:     get_latest_gems.find_all { |gem|
203:       gem.dependencies.any? { |dep| dep.name == name }
204:     }
205:   end
get_gems_by_name() click to toggle source

Return a hash of the latest rubygems keyed by name.

     # File lib/hoe/deps.rb, line 172
172:   def get_gems_by_name
173:     @@by_name ||= Hash[*get_latest_gems.map { |gem|
174:                          [gem.name, gem, gem.full_name, gem]
175:                        }.flatten]
176:   end
get_latest_gems() click to toggle source

Return the latest rubygems.

     # File lib/hoe/deps.rb, line 165
165:   def get_latest_gems
166:     @@cache ||= Hash[*get_source_index.flatten].values
167:   end
get_source_index() click to toggle source

Return the rubygems source index.

     # File lib/hoe/deps.rb, line 132
132:   def get_source_index
133:     @@index ||= nil
134: 
135:     return @@index if @@index
136: 
137:     dump = unless File.exist? '.source_index' then
138:              warn "Fetching full index and caching. This can take a while."
139:              url = GEMURL + "Marshal.#{Gem.marshal_version}.Z"
140:              dump = Gem::RemoteFetcher.fetcher.fetch_path url
141:              dump = Gem.inflate dump
142: 
143:              warn "stripping index to latest gems"
144:              ary = Marshal.load dump
145: 
146:              h = {}
147:              Hash[ary].values.sort.each { |spec| h[spec.name] = spec }
148:              ary = h.map { |k,v| [v.full_name, v] }
149: 
150:              dump = Marshal.dump ary
151: 
152:              open '.source_index', 'wb' do |io| io.write dump end
153: 
154:              dump
155:            else
156:              open '.source_index', 'rb' do |io| io.read end
157:            end
158: 
159:     @@index = Marshal.load dump
160:   end
install_missing_plugins(plugins = Hoe.bad_plugins) click to toggle source

Installs plugins that aren’t currently installed

     # File lib/hoe/deps.rb, line 181
181:   def install_missing_plugins plugins = Hoe.bad_plugins
182:     version = '>= 0'
183: 
184:     plugins.each do |name|
185:       dash_name = name.to_s.gsub '_', '-'
186: 
187:       next if have_gem?("hoe-#{name}") or
188:                 have_gem?(name) or
189:                 have_gem?(dash_name)
190: 
191:       install_gem("hoe-#{name}", version, false) or
192:         install_gem(name, version, false) or
193:         install_gem(dash_name, version, false) or
194:         warn "could not install gem for #{name} plugin"
195:     end
196:   end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.