configuration.rb 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. require 'active_support/deprecation'
  2. require 'active_support/ordered_options'
  3. require 'active_support/core_ext/hash/deep_dup'
  4. require 'rails/paths'
  5. require 'rails/rack'
  6. module Rails
  7. module Configuration
  8. class MiddlewareStackProxy #:nodoc:
  9. def initialize
  10. @operations = []
  11. end
  12. def insert_before(*args, &block)
  13. @operations << [:insert_before, args, block]
  14. end
  15. alias :insert :insert_before
  16. def insert_after(*args, &block)
  17. @operations << [:insert_after, args, block]
  18. end
  19. def swap(*args, &block)
  20. @operations << [:swap, args, block]
  21. end
  22. def use(*args, &block)
  23. @operations << [:use, args, block]
  24. end
  25. def delete(*args, &block)
  26. @operations << [:delete, args, block]
  27. end
  28. def merge_into(other)
  29. @operations.each do |operation, args, block|
  30. other.send(operation, *args, &block)
  31. end
  32. other
  33. end
  34. end
  35. class Generators #:nodoc:
  36. attr_accessor :aliases, :options, :templates, :fallbacks, :colorize_logging
  37. attr_reader :hidden_namespaces
  38. def initialize
  39. @aliases = Hash.new { |h,k| h[k] = {} }
  40. @options = Hash.new { |h,k| h[k] = {} }
  41. @fallbacks = {}
  42. @templates = []
  43. @colorize_logging = true
  44. @hidden_namespaces = []
  45. end
  46. def initialize_copy(source)
  47. @aliases = @aliases.deep_dup
  48. @options = @options.deep_dup
  49. @fallbacks = @fallbacks.deep_dup
  50. @templates = @templates.dup
  51. end
  52. def hide_namespace(namespace)
  53. @hidden_namespaces << namespace
  54. end
  55. def method_missing(method, *args)
  56. method = method.to_s.sub(/=$/, '').to_sym
  57. return @options[method] if args.empty?
  58. if method == :rails || args.first.is_a?(Hash)
  59. namespace, configuration = method, args.shift
  60. else
  61. namespace, configuration = args.shift, args.shift
  62. namespace = namespace.to_sym if namespace.respond_to?(:to_sym)
  63. @options[:rails][method] = namespace
  64. end
  65. if configuration
  66. aliases = configuration.delete(:aliases)
  67. @aliases[namespace].merge!(aliases) if aliases
  68. @options[namespace].merge!(configuration)
  69. end
  70. end
  71. end
  72. end
  73. end