Ticket #8730: gem_generators.patch
| File gem_generators.patch, 5.3 kB (added by nicwilliams, 1 year ago) |
|---|
-
CHANGELOG
old new 1 1 *SVN* 2 2 3 * Plugin generators can be placed in /rails_generators folder, in addition to /generators folder (in fact, any folder /*generators); to allow RubyGems with generators (see below) to be directly usable as plugins, and include generators. [Dr Nic, topfunky] 4 5 * RubyGems can include Rails generators within /rails_generators/<generator_name>_generator.rb files (or /generators/... for generic generators), like you can do with plugins. GemSource renamed to GemGeneratorSource to free up meaningful namespace of Source subclasses [Dr Nic] 6 3 7 * Fixed that dispatcher preparation callbacks only run once in production mode. Mock Routes.reload so that dispatcher preparation callback tests run. [Rick] 4 8 5 9 * Fix syntax error in dispatcher than wrecked failsafe responses. #8625 [mtitorenko] -
lib/rails_generator/scripts.rb
old new 43 43 44 44 def usage_message 45 45 usage = "\nInstalled Generators\n" 46 Rails::Generator::Base.sources. each do |source|46 Rails::Generator::Base.sources.inject({}) do |mem, source| 47 47 label = source.label.to_s.capitalize 48 names = source.names 48 mem[label] ||= [] 49 mem[label] |= source.names 50 mem 51 end.each_pair do |label, names| 49 52 usage << " #{label}: #{names.join(', ')}\n" unless names.empty? 50 53 end 51 54 -
lib/rails_generator/lookup.rb
old new 46 46 # 47 47 # A spec is not a generator: it's a description of where to find 48 48 # the generator and how to create it. A source is anything that 49 # yields generators from #each. PathSource and Gem Source are provided.49 # yields generators from #each. PathSource and GemGeneratorSource are provided. 50 50 module Lookup 51 51 def self.included(base) 52 52 base.extend(ClassMethods) … … 100 100 if defined? ::RAILS_ROOT 101 101 sources << PathSource.new(:lib, "#{::RAILS_ROOT}/lib/generators") 102 102 sources << PathSource.new(:vendor, "#{::RAILS_ROOT}/vendor/generators") 103 sources << PathSource.new(:plugins, "#{::RAILS_ROOT}/vendor/plugins/*/**/ generators")103 sources << PathSource.new(:plugins, "#{::RAILS_ROOT}/vendor/plugins/*/**/*generators") 104 104 end 105 105 sources << PathSource.new(:user, "#{Dir.user_home}/.rails/generators") 106 sources << GemSource.new if Object.const_defined?(:Gem) 106 if Object.const_defined?(:Gem) 107 sources << GemGeneratorSource.new 108 sources << GemPathSource.new 109 end 107 110 sources << PathSource.new(:builtin, "#{File.dirname(__FILE__)}/generators/components") 108 111 end 109 112 … … 185 188 end 186 189 end 187 190 188 189 # GemSource hits the mines to quarry for generators. The latest versions 190 # of gems named *_generator are selected. 191 class GemSource < Source 191 class AbstractGemSource < Source 192 192 def initialize 193 193 super :RubyGems 194 194 end 195 end 195 196 197 # GemGeneratorSource hits the mines to quarry for generators. The latest versions 198 # of gems named *_generator are selected. 199 class GemGeneratorSource < AbstractGemSource 196 200 # Yield latest versions of generator gems. 197 201 def each 198 202 Gem::cache.search(/_generator$/).inject({}) { |latest, gem| … … 205 209 end 206 210 end 207 211 212 # GemPathSource looks for generators within any RubyGem's /rails_generators/<generator_name>_generator.rb file. 213 class GemPathSource < AbstractGemSource 214 # Yield each generator within rails_generator subdirectories. 215 def each 216 generator_full_paths.each do |generator| 217 yield Spec.new(File.basename(generator).sub(/_generator.rb$/, ''), File.dirname(generator), label) 218 end 219 end 220 221 private 222 def generator_full_paths 223 @generator_full_paths ||= 224 begin 225 Gem::cache.inject({}) do |latest, name_gem| 226 name, gem = name_gem 227 hem = latest[gem.name] 228 latest[gem.name] = gem if hem.nil? or gem.version > hem.version 229 latest 230 end.values.inject([]) do |mem, gem| 231 Dir[gem.full_gem_path + '/{rails_,}generators/**/*_generator.rb'].each do |generator| 232 mem << generator 233 end 234 mem 235 end 236 end 237 end 238 end 239 208 240 end 209 241 end -
lib/rails_generator/spec.rb
old new 2 2 module Generator 3 3 # A spec knows where a generator was found and how to instantiate it. 4 4 # Metadata include the generator's name, its base path, and the source 5 # which yielded it (PathSource, Gem Source, etc.)5 # which yielded it (PathSource, GemPathSource, etc.) 6 6 class Spec 7 7 attr_reader :name, :path, :source 8 8