Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 116 lines (99 sloc) 3.526 kb
da62a7c Duplicate AS code no longer needed
Yehuda Katz + Carl Lerche authored
1 require 'active_support/ordered_options'
657b4ff Alexey Gaziev Nice logic for deep_dup in rails
gazay authored
2 require 'active_support/core_ext/object'
b17e358 José Valim Move configuration to subfolders.
josevalim authored
3 require 'rails/paths'
4 require 'rails/rack'
ff8be66 Finish porting over the initializers to the app object and fix all the t...
Carl Lerche authored
5
3aad4d7 Separate Rails module methods, the config object, and the initializer in...
Yehuda Katz + Carl Lerche authored
6 module Rails
b17e358 José Valim Move configuration to subfolders.
josevalim authored
7 module Configuration
6b28c94 Carlos Antonio da Silva Add some docs for MiddlewareStackProxy methods and api_only!
carlosantoniodasilva authored
8 # MiddlewareStackProxy is a proxy for the Rails middleware stack that allows
9 # you to configure middlewares in your application. It works basically as a
10 # command recorder, saving each command to be applied after initialization
11 # over the default middleware stack, so you can add, swap, or remove any
12 # middleware in Rails.
13 #
14 # You can add your own middlewares by using the +config.middleware.use+ method:
15 #
16 # config.middleware.use Magical::Unicorns
17 #
8cc4159 Mark Rushakoff Use <tt>Foo::Bar</tt> instead of +Foo::Bar+
mark-rushakoff authored
18 # This will put the <tt>Magical::Unicorns</tt> middleware on the end of the stack.
6b28c94 Carlos Antonio da Silva Add some docs for MiddlewareStackProxy methods and api_only!
carlosantoniodasilva authored
19 # You can use +insert_before+ if you wish to add a middleware before another:
20 #
21 # config.middleware.insert_before ActionDispatch::Head, Magical::Unicorns
22 #
23 # There's also +insert_after+ which will insert a middleware after another:
24 #
25 # config.middleware.insert_after ActionDispatch::Head, Magical::Unicorns
26 #
27 # Middlewares can also be completely swapped out and replaced with others:
28 #
3bccd12 Guillermo Iguaran Remove BestStandardsSupport middleware
guilleiguaran authored
29 # config.middleware.swap ActionDispatch::Flash, Magical::Unicorns
6b28c94 Carlos Antonio da Silva Add some docs for MiddlewareStackProxy methods and api_only!
carlosantoniodasilva authored
30 #
31 # And finally they can also be removed from the stack completely:
32 #
3bccd12 Guillermo Iguaran Remove BestStandardsSupport middleware
guilleiguaran authored
33 # config.middleware.delete ActionDispatch::Flash
6b28c94 Carlos Antonio da Silva Add some docs for MiddlewareStackProxy methods and api_only!
carlosantoniodasilva authored
34 #
35 class MiddlewareStackProxy
99b38f3 José Valim Move AD::Cascade to the bottom of the middleware stack.
josevalim authored
36 def initialize
37 @operations = []
38 end
39
40 def insert_before(*args, &block)
edb87b1 Aaron Patterson using __method__ for the command method calls
tenderlove authored
41 @operations << [__method__, args, block]
99b38f3 José Valim Move AD::Cascade to the bottom of the middleware stack.
josevalim authored
42 end
43
44 alias :insert :insert_before
45
46 def insert_after(*args, &block)
edb87b1 Aaron Patterson using __method__ for the command method calls
tenderlove authored
47 @operations << [__method__, args, block]
99b38f3 José Valim Move AD::Cascade to the bottom of the middleware stack.
josevalim authored
48 end
49
50 def swap(*args, &block)
edb87b1 Aaron Patterson using __method__ for the command method calls
tenderlove authored
51 @operations << [__method__, args, block]
99b38f3 José Valim Move AD::Cascade to the bottom of the middleware stack.
josevalim authored
52 end
53
54 def use(*args, &block)
edb87b1 Aaron Patterson using __method__ for the command method calls
tenderlove authored
55 @operations << [__method__, args, block]
99b38f3 José Valim Move AD::Cascade to the bottom of the middleware stack.
josevalim authored
56 end
57
a210aff José Valim Add delete to middleware stack proxy.
josevalim authored
58 def delete(*args, &block)
edb87b1 Aaron Patterson using __method__ for the command method calls
tenderlove authored
59 @operations << [__method__, args, block]
a210aff José Valim Add delete to middleware stack proxy.
josevalim authored
60 end
61
6b28c94 Carlos Antonio da Silva Add some docs for MiddlewareStackProxy methods and api_only!
carlosantoniodasilva authored
62 def merge_into(other) #:nodoc:
99b38f3 José Valim Move AD::Cascade to the bottom of the middleware stack.
josevalim authored
63 @operations.each do |operation, args, block|
64 other.send(operation, *args, &block)
65 end
66 other
67 end
68 end
69
b17e358 José Valim Move configuration to subfolders.
josevalim authored
70 class Generators #:nodoc:
6958eac José Valim Add config.generators.templates to provide alternative paths for templat...
josevalim authored
71 attr_accessor :aliases, :options, :templates, :fallbacks, :colorize_logging
c1df442 Yehuda Katz Update generator config to support hiding namespaces and pass the app in...
wycats authored
72 attr_reader :hidden_namespaces
98240c4 José Valim Get rid of initializers global and create i18n railtie.
josevalim authored
73
74 def initialize
75 @aliases = Hash.new { |h,k| h[k] = {} }
76 @options = Hash.new { |h,k| h[k] = {} }
a8c5d22 José Valim Add config.generators.fallbacks.
josevalim authored
77 @fallbacks = {}
6958eac José Valim Add config.generators.templates to provide alternative paths for templat...
josevalim authored
78 @templates = []
98240c4 José Valim Get rid of initializers global and create i18n railtie.
josevalim authored
79 @colorize_logging = true
c1df442 Yehuda Katz Update generator config to support hiding namespaces and pass the app in...
wycats authored
80 @hidden_namespaces = []
98240c4 José Valim Get rid of initializers global and create i18n railtie.
josevalim authored
81 end
82
a5311ee Piotr Sarnacki Make deep copy of application generators on engine initialization.
drogus authored
83 def initialize_copy(source)
84 @aliases = @aliases.deep_dup
85 @options = @options.deep_dup
86 @fallbacks = @fallbacks.deep_dup
87 @templates = @templates.dup
88 end
89
c1df442 Yehuda Katz Update generator config to support hiding namespaces and pass the app in...
wycats authored
90 def hide_namespace(namespace)
91 @hidden_namespaces << namespace
92 end
93
98240c4 José Valim Get rid of initializers global and create i18n railtie.
josevalim authored
94 def method_missing(method, *args)
95 method = method.to_s.sub(/=$/, '').to_sym
96
6268fcd Fix the test_framework generator tests
Carl Lerche authored
97 return @options[method] if args.empty?
98
79d6f31 Santiago Pastorino We are doing the same in this conditions
spastorino authored
99 if method == :rails || args.first.is_a?(Hash)
98240c4 José Valim Get rid of initializers global and create i18n railtie.
josevalim authored
100 namespace, configuration = method, args.shift
101 else
102 namespace, configuration = args.shift, args.shift
e107c20 Santiago Pastorino Make config.generators accept string namespaces, you can do now config.g...
spastorino authored
103 namespace = namespace.to_sym if namespace.respond_to?(:to_sym)
98240c4 José Valim Get rid of initializers global and create i18n railtie.
josevalim authored
104 @options[:rails][method] = namespace
105 end
106
107 if configuration
108 aliases = configuration.delete(:aliases)
109 @aliases[namespace].merge!(aliases) if aliases
110 @options[namespace].merge!(configuration)
111 end
112 end
7fcf859 José Valim Massive cleanup in Railties and load stack.
josevalim authored
113 end
3aad4d7 Separate Rails module methods, the config object, and the initializer in...
Yehuda Katz + Carl Lerche authored
114 end
2699e9c José Valim Added config.generators with tests.
josevalim authored
115 end
Something went wrong with that request. Please try again.