Ticket #8730: gem_generators2.patch
| File gem_generators2.patch, 5.2 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; to allow RubyGems with rails_generators (see below) to be directly usable as plugins, and have their generators available. [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 * MySQL, PostgreSQL: database.yml defaults to utf-8. #8701 [matt] 4 8 5 9 * Added db:version to get the current schema number [via Err The Blog] -
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) … … 101 101 sources << PathSource.new(:lib, "#{::RAILS_ROOT}/lib/generators") 102 102 sources << PathSource.new(:vendor, "#{::RAILS_ROOT}/vendor/generators") 103 103 sources << PathSource.new(:plugins, "#{::RAILS_ROOT}/vendor/plugins/*/**/generators") 104 sources << PathSource.new(:plugins, "#{::RAILS_ROOT}/vendor/plugins/*/**/rails_generators") 104 105 end 105 106 sources << PathSource.new(:user, "#{Dir.user_home}/.rails/generators") 106 sources << GemSource.new if Object.const_defined?(:Gem) 107 if Object.const_defined?(:Gem) 108 sources << GemGeneratorSource.new 109 sources << GemPathSource.new 110 end 107 111 sources << PathSource.new(:builtin, "#{File.dirname(__FILE__)}/generators/components") 108 112 end 109 113 … … 185 189 end 186 190 end 187 191 188 189 # GemSource hits the mines to quarry for generators. The latest versions 190 # of gems named *_generator are selected. 191 class GemSource < Source 192 class AbstractGemSource < Source 192 193 def initialize 193 194 super :RubyGems 194 195 end 196 end 195 197 198 # GemGeneratorSource hits the mines to quarry for generators. The latest versions 199 # of gems named *_generator are selected. 200 class GemGeneratorSource < AbstractGemSource 196 201 # Yield latest versions of generator gems. 197 202 def each 198 203 Gem::cache.search(/_generator$/).inject({}) { |latest, gem| … … 205 210 end 206 211 end 207 212 213 # GemPathSource looks for generators within any RubyGem's /rails_generators/<generator_name>_generator.rb file. 214 class GemPathSource < AbstractGemSource 215 # Yield each generator within rails_generator subdirectories. 216 def each 217 generator_full_paths.each do |generator| 218 yield Spec.new(File.basename(generator).sub(/_generator.rb$/, ''), File.dirname(generator), label) 219 end 220 end 221 222 private 223 def generator_full_paths 224 @generator_full_paths ||= 225 begin 226 Gem::cache.inject({}) do |latest, name_gem| 227 name, gem = name_gem 228 hem = latest[gem.name] 229 latest[gem.name] = gem if hem.nil? or gem.version > hem.version 230 latest 231 end.values.inject([]) do |mem, gem| 232 Dir[gem.full_gem_path + '/{rails_,}generators/**/*_generator.rb'].each do |generator| 233 mem << generator 234 end 235 mem 236 end 237 end 238 end 239 end 240 208 241 end 209 242 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