Skip to content

Commit

Permalink
Update railtie to install after known dependencies: SamSaffron/MiniPr…
Browse files Browse the repository at this point in the history
  • Loading branch information
jerryclinesmith authored and jeremyvdw committed Nov 27, 2015
1 parent 9f9a2de commit 0b1903a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
14 changes: 4 additions & 10 deletions lib/mini_profiler/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@ def self.attributes

attr_accessor :auto_inject, :base_url_path, :pre_authorize_cb, :position,
:backtrace_remove, :backtrace_includes, :backtrace_ignores, :skip_schema_queries,
:storage, :user_provider, :stateless, :storage_instance, :storage_options, :skip_paths, :authorization_mode,
:storage, :user_provider, :storage_instance, :storage_options, :skip_paths, :authorization_mode,
:toggle_shortcut, :start_hidden, :backtrace_threshold_ms, :storage_failure, :logger, :stateless

# Deprecated options
attr_accessor :use_existing_jquery

def self.default
new.instance_eval {
@auto_inject = true # automatically inject on every html page
@base_url_path = "/mini-profiler-resources/"
@disable_caching = true
@auto_inject = true # automatically inject on every html page
@base_url_path = "/mini-profiler-resources/"

# called prior to rack chain, to ensure we are allowed to profile
@pre_authorize_cb = lambda {|env| true}

Expand All @@ -38,7 +38,6 @@ def self.default
@start_hidden = false
@backtrace_threshold_ms = 0
@flamegraph_sample_rate = 0.5
@stateless = false
@storage_failure = Proc.new do |exception|
if @logger
@logger.warn("MiniProfiler storage failure: #{exception.message}")
Expand All @@ -47,11 +46,6 @@ def self.default
@enabled = true
@disable_env_dump = false
@stateless = false
@storage_failure = Proc.new do |exception|
if @logger
@logger.warn("MiniProfiler storage failure: #{exception.message}")
end
end
self
}
end
Expand Down
15 changes: 12 additions & 3 deletions lib/mini_profiler_rails/railtie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,6 @@ def self.initialize!(app)
c.backtrace_includes = [/^\/?(app|config|lib|test)/]
c.skip_schema_queries = (Rails.env.development? || Rails.env.test?)

# Install the Middleware
app.middleware.insert(0, Rack::MiniProfiler)

# Attach to various Rails methods
ActiveSupport.on_load(:action_controller) do
::Rack::MiniProfiler.profile_method(ActionController::Base, :process) {|action| "Executing action: #{action}"}
Expand Down Expand Up @@ -81,6 +78,18 @@ class Railtie < ::Rails::Railtie
Rack::MiniProfilerRails.initialize!(app)
end

config.after_initialize do |app|
# Install the Middleware - wait until all middlewares have been added
insert_position = 0
insert_after_middlewares = Array(Rack::MiniProfiler.config.insert_after_middlewares)

app.config.middleware.each_with_index do |middleware, index|
insert_position = (index + 1) if insert_after_middlewares.include?(middleware.klass.name)
end

app.middleware.insert(insert_position, Rack::MiniProfiler)
end

# TODO: Implement something better here
# config.after_initialize do
#
Expand Down

0 comments on commit 0b1903a

Please sign in to comment.