mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Add convenience method to hide a generator from the available ones
It is usually useful to be able to hide a generator when running rails generate command. Such generators might be used only to dry up generators code and shouldn't be available to end users.
This commit is contained in:
parent
2abaa19e77
commit
c6ef45d6c4
4 changed files with 25 additions and 1 deletions
|
@ -1,5 +1,8 @@
|
|||
## Rails 4.0.0 (unreleased) ##
|
||||
|
||||
* Add convenience `hide!` method to Rails generators to hide current generator
|
||||
namespace from showing when running `rails generate`. *Carlos Antonio da Silva*
|
||||
|
||||
* Scaffold now uses `content_tag_for` in index.html.erb *José Valim*
|
||||
|
||||
* Rails::Plugin has gone. Instead of adding plugins to vendor/plugins use gems or bundler with path or git dependencies. *Santiago Pastorino*
|
||||
|
|
|
@ -48,6 +48,12 @@ module Rails
|
|||
@namespace ||= super.sub(/_generator$/, '').sub(/:generators:/, ':')
|
||||
end
|
||||
|
||||
# Convenience method to hide this generator from the available ones when
|
||||
# running rails generator command.
|
||||
def self.hide!
|
||||
Rails::Generators.hide_namespace self.namespace
|
||||
end
|
||||
|
||||
# Invoke a generator based on the value supplied by the user to the
|
||||
# given option named "name". A class option is created when this method
|
||||
# is invoked and you can set a hash to customize it.
|
||||
|
|
|
@ -108,6 +108,15 @@ class NamedBaseTest < Rails::Generators::TestCase
|
|||
assert_name g, 'sheep_index', :index_helper
|
||||
end
|
||||
|
||||
def test_hide_namespace
|
||||
g = generator ['Hidden']
|
||||
g.class.stubs(:namespace).returns('hidden')
|
||||
|
||||
assert !Rails::Generators.hidden_namespaces.include?('hidden')
|
||||
g.class.hide!
|
||||
assert Rails::Generators.hidden_namespaces.include?('hidden')
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def assert_name(generator, value, method)
|
||||
|
|
|
@ -207,4 +207,10 @@ class GeneratorsTest < Rails::Generators::TestCase
|
|||
output = capture(:stdout) { Rails::Generators.invoke :usage_template, ['--help'] }
|
||||
assert_match /:: 2 ::/, output
|
||||
end
|
||||
|
||||
def test_hide_namespace
|
||||
assert !Rails::Generators.hidden_namespaces.include?("special:namespace")
|
||||
Rails::Generators.hide_namespace("special:namespace")
|
||||
assert Rails::Generators.hidden_namespaces.include?("special:namespace")
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue