mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Create generators http_only! setup and hide some common namespaces for now
[Carlos Antonio da Silva & Santiago Pastorino]
This commit is contained in:
parent
124838b508
commit
c825e9a5ea
3 changed files with 42 additions and 4 deletions
|
@ -44,14 +44,14 @@ module Rails
|
|||
# Cookies, Session and Flash, BestStandardsSupport, and MethodOverride. You
|
||||
# can always add any of them later manually if you want.
|
||||
class MiddlewareStackProxy
|
||||
attr_reader :http_only
|
||||
alias :http_only? :http_only
|
||||
|
||||
def initialize
|
||||
@operations = []
|
||||
@http_only = false
|
||||
end
|
||||
|
||||
attr_reader :http_only
|
||||
alias :http_only? :http_only
|
||||
|
||||
def http_only!
|
||||
@http_only = true
|
||||
end
|
||||
|
@ -90,6 +90,9 @@ module Rails
|
|||
attr_accessor :aliases, :options, :templates, :fallbacks, :colorize_logging
|
||||
attr_reader :hidden_namespaces
|
||||
|
||||
attr_reader :http_only
|
||||
alias :http_only? :http_only
|
||||
|
||||
def initialize
|
||||
@aliases = Hash.new { |h,k| h[k] = {} }
|
||||
@options = Hash.new { |h,k| h[k] = {} }
|
||||
|
@ -97,6 +100,7 @@ module Rails
|
|||
@templates = []
|
||||
@colorize_logging = true
|
||||
@hidden_namespaces = []
|
||||
@http_only = false
|
||||
end
|
||||
|
||||
def initialize_copy(source)
|
||||
|
@ -110,6 +114,10 @@ module Rails
|
|||
@hidden_namespaces << namespace
|
||||
end
|
||||
|
||||
def http_only!
|
||||
@http_only = true
|
||||
end
|
||||
|
||||
def method_missing(method, *args)
|
||||
method = method.to_s.sub(/=$/, '').to_sym
|
||||
|
||||
|
|
|
@ -68,6 +68,7 @@ module Rails
|
|||
templates_path.concat config.templates
|
||||
templates_path.uniq!
|
||||
hide_namespaces(*config.hidden_namespaces)
|
||||
http_only! if config.http_only?
|
||||
end
|
||||
|
||||
def self.templates_path
|
||||
|
@ -104,6 +105,11 @@ module Rails
|
|||
Thor::Base.shell = Thor::Shell::Basic
|
||||
end
|
||||
|
||||
# Configure generators for http only
|
||||
def self.http_only!
|
||||
hide_namespaces "assets", "css", "js", "session_migration"
|
||||
end
|
||||
|
||||
# Track all generators subclasses.
|
||||
def self.subclasses
|
||||
@subclasses ||= []
|
||||
|
@ -235,7 +241,7 @@ module Rails
|
|||
rails.delete("plugin_new")
|
||||
print_list("rails", rails)
|
||||
|
||||
hidden_namespaces.each {|n| groups.delete(n.to_s) }
|
||||
hidden_namespaces.each { |n| groups.delete(n.to_s) }
|
||||
|
||||
groups.sort.each { |b, n| print_list(b, n) }
|
||||
end
|
||||
|
|
|
@ -213,4 +213,28 @@ class GeneratorsTest < Rails::Generators::TestCase
|
|||
Rails::Generators.hide_namespace("special:namespace")
|
||||
assert Rails::Generators.hidden_namespaces.include?("special:namespace")
|
||||
end
|
||||
|
||||
def test_http_only_hides_generators
|
||||
generators = %w(assets js css session_migration)
|
||||
|
||||
generators.each do |generator|
|
||||
assert !Rails::Generators.hidden_namespaces.include?(generator)
|
||||
end
|
||||
|
||||
with_http_only! do
|
||||
generators.each do |generator|
|
||||
assert Rails::Generators.hidden_namespaces.include?(generator),
|
||||
"http only should hide #{generator} generator"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def with_http_only!
|
||||
Rails::Generators.http_only!
|
||||
yield
|
||||
ensure
|
||||
Rails::Generators.instance_variable_set(:@http_only, false)
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue