Class: Rails::Application

Inherits:
Engine
  • Object
show all
Defined in:
lib/rails-api/application.rb

Instance Method Summary collapse

Instance Method Details

#default_middleware_stackObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/rails-api/application.rb', line 6

def default_middleware_stack
  ActionDispatch::MiddlewareStack.new.tap do |middleware|
    if rack_cache = config.action_controller.perform_caching && config.action_dispatch.rack_cache
      require "action_dispatch/http/rack_cache"
      middleware.use ::Rack::Cache, rack_cache
    end

    if config.force_ssl
      middleware.use ::ActionDispatch::SSL, config.ssl_options
    end

    if config.action_dispatch.x_sendfile_header.present?
      middleware.use ::Rack::Sendfile, config.action_dispatch.x_sendfile_header
    end

    if config.serve_static_assets
      middleware.use ::ActionDispatch::Static, paths["public"].first, config.static_cache_control
    end

    middleware.use ::Rack::Lock unless config.allow_concurrency
    middleware.use ::Rack::Runtime
    middleware.use ::ActionDispatch::RequestId
    middleware.use ::Rails::Rack::Logger, config.log_tags # must come after Rack::MethodOverride to properly log overridden methods
    middleware.use ::ActionDispatch::ShowExceptions, config.exceptions_app || ActionDispatch::PublicExceptions.new(Rails.public_path)
    middleware.use ::ActionDispatch::DebugExceptions
    middleware.use ::ActionDispatch::RemoteIp, config.action_dispatch.ip_spoofing_check, config.action_dispatch.trusted_proxies

    unless config.cache_classes
      app = self
      middleware.use ::ActionDispatch::Reloader, lambda { app.reload_dependencies? }
    end

    middleware.use ::ActionDispatch::Callbacks

    middleware.use ::ActionDispatch::ParamsParser
    middleware.use ::ActionDispatch::Head
    middleware.use ::Rack::ConditionalGet
    middleware.use ::Rack::ETag, "no-cache"
  end
end

#load_generators(app = self) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/rails-api/application.rb', line 48

def load_generators(app=self)
  super
  require 'rails/generators/rails/resource/resource_generator'
  Rails::Generators::ResourceGenerator.class_eval do
    def add_resource_route
      return if options[:actions].present?
      route_config =  regular_class_path.collect{|namespace| "namespace :#{namespace} do " }.join(" ")
      route_config << "resources :#{file_name.pluralize}"
      route_config << ", except: :edit"
      route_config << " end" * regular_class_path.size
      route route_config
    end
  end
  self
end