Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

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