Skip to content

Commit

Permalink
Update hidden namespace mechanism to work better with alternate choic…
Browse files Browse the repository at this point in the history
…es and to support full namespaces (not just entire groups)
  • Loading branch information
wycats committed May 5, 2010
1 parent f2072a3 commit 743d77f
Showing 1 changed file with 42 additions and 4 deletions.
46 changes: 42 additions & 4 deletions railties/lib/rails/generators.rb
Expand Up @@ -166,6 +166,38 @@ def self.invoke(namespace, args=ARGV, config={})
end
end

def self.hidden_namespaces
@hidden_namespaces ||= begin
orm = options[:rails][:orm]
test = options[:rails][:test_framework]
template = options[:rails][:template_engine]

[
"rails",
"#{orm}:migration",
"#{orm}:model",
"#{orm}:observer",
"#{test}:controller",
"#{test}:helper",
"#{test}:integration",
"#{test}:mailer",
"#{test}:model",
"#{test}:observer",
"#{test}:scaffold",
"#{test}:view",
"#{template}:controller",
"#{template}:scaffold"
]
end
end

class << self
def hide_namespaces(*namespaces)
hidden_namespaces.concat(namespaces)
end
alias hide_namespace hide_namespaces
end

# Show help message with available generators.
def self.help(command = 'generate')
lookup!
Expand Down Expand Up @@ -197,9 +229,7 @@ def self.help(command = 'generate')
rails.delete("app")
print_list("rails", rails)

groups.delete("active_record") if options[:rails][:orm] == :active_record
groups.delete("test_unit") if options[:rails][:test_framework] == :test_unit
groups.delete("erb") if options[:rails][:template_engine] == :erb
hidden_namespaces.each {|n| groups.delete(n.to_s) }

groups.sort.each { |b, n| print_list(b, n) }
end
Expand All @@ -208,9 +238,17 @@ def self.help(command = 'generate')

# Prints a list of generators.
def self.print_list(base, namespaces) #:nodoc:
namespaces = namespaces.reject do |n|
hidden_namespaces.include?(n)
end

return if namespaces.empty?
puts "#{base.camelize}:"
namespaces.each { |namespace| puts(" #{namespace}") }

namespaces.each do |namespace|
puts(" #{namespace}")
end

puts
end

Expand Down

2 comments on commit 743d77f

@jocker
Copy link

@jocker jocker commented on 743d77f May 30, 2010

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm sorry, but i can't see metal generator here

@mitchellh
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

jocker,

Rails metal was removed in a previous commit a couple days ago (see http://github.com/rails/rails/commit/45e60283e733a535d68d499aa20e095c905f43b0)

Please sign in to comment.