Skip to content

Commit

Permalink
Update generator config to support hiding namespaces and pass the app…
Browse files Browse the repository at this point in the history
… into generator blocks
  • Loading branch information
wycats committed May 24, 2011
1 parent ac3503c commit 9f815ee
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 4 deletions.
5 changes: 3 additions & 2 deletions railties/lib/rails/application.rb
Expand Up @@ -103,9 +103,10 @@ def load_tasks
self
end

def load_generators
def load_generators(app=self)
initialize_generators
railties.all { |r| r.load_generators }
railties.all { |r| r.load_generators(app) }

super
self
end
Expand Down
6 changes: 6 additions & 0 deletions railties/lib/rails/configuration.rb
Expand Up @@ -43,13 +43,15 @@ def merge_into(other)

class Generators #:nodoc:
attr_accessor :aliases, :options, :templates, :fallbacks, :colorize_logging
attr_reader :hidden_namespaces

def initialize
@aliases = Hash.new { |h,k| h[k] = {} }
@options = Hash.new { |h,k| h[k] = {} }
@fallbacks = {}
@templates = []
@colorize_logging = true
@hidden_namespaces = []
end

def initialize_copy(source)
Expand All @@ -59,6 +61,10 @@ def initialize_copy(source)
@templates = @templates.dup
end

def hide_namespace(namespace)
@hidden_namespaces << namespace
end

def method_missing(method, *args)
method = method.to_s.sub(/=$/, '').to_sym

Expand Down
1 change: 1 addition & 0 deletions railties/lib/rails/generators.rb
Expand Up @@ -75,6 +75,7 @@ def self.configure!(config = Rails.application.config.generators) #:nodoc:
fallbacks.merge! config.fallbacks
templates_path.concat config.templates
templates_path.uniq!
hide_namespaces *config.hidden_namespaces
end

def self.templates_path
Expand Down
4 changes: 2 additions & 2 deletions railties/lib/rails/railtie.rb
Expand Up @@ -189,8 +189,8 @@ def load_tasks
end
end

def load_generators
self.class.generators.each(&:call)
def load_generators(app)
self.class.generators.each { |block| block.call(app) }
end
end
end

0 comments on commit 9f815ee

Please sign in to comment.