Skip to content

Commit

Permalink
Don't create rails engine unless user opts in
Browse files Browse the repository at this point in the history
  • Loading branch information
OsamaSayegh committed Jul 15, 2020
1 parent cdc9b2c commit 0f53df5
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
12 changes: 10 additions & 2 deletions lib/mini_profiler/config.rb
Expand Up @@ -60,8 +60,7 @@ def self.default
:base_url_path, :disable_caching, :enabled,
:flamegraph_sample_rate, :logger, :pre_authorize_cb, :skip_paths,
:skip_schema_queries, :storage, :storage_failure, :storage_instance,
:storage_options, :user_provider, :enable_advanced_debugging_tools,
:assets_url
:storage_options, :user_provider, :enable_advanced_debugging_tools
attr_accessor :skip_sql_param_names, :suppress_encoding, :max_sql_param_length

# ui accessors
Expand All @@ -72,6 +71,15 @@ def self.default
# Deprecated options
attr_accessor :use_existing_jquery

attr_reader :assets_url

def assets_url=(lmbda)
if defined?(Rack::MiniProfilerRails)
Rack::MiniProfilerRails.create_engine
end
@assets_url = lmbda
end

def vertical_position
position.include?('bottom') ? 'bottom' : 'top'
end
Expand Down
18 changes: 11 additions & 7 deletions lib/mini_profiler_rails/railtie.rb
Expand Up @@ -6,13 +6,6 @@
module Rack::MiniProfilerRails
extend Rack::MiniProfilerRailsMethods

class Engine < ::Rails::Engine
engine_name 'rack-mini-profiler'
config.assets.paths << File.expand_path('../../html', __FILE__)
config.assets.precompile << 'rack-mini-profiler.js'
config.assets.precompile << 'rack-mini-profiler.css'
end

# call direct if needed to do a defer init
def self.initialize!(app)

Expand Down Expand Up @@ -125,6 +118,17 @@ def self.initialize!(app)
@already_initialized = true
end

def self.create_engine
return if defined?(Rack::MiniProfilerRails::Engine)
klass = Class.new(::Rails::Engine) do
engine_name 'rack-mini-profiler'
config.assets.paths << File.expand_path('../../html', __FILE__)
config.assets.precompile << 'rack-mini-profiler.js'
config.assets.precompile << 'rack-mini-profiler.css'
end
Rack::MiniProfilerRails.const_set("Engine", klass)
end

def self.subscribe(event, &blk)
if ActiveSupport::Notifications.respond_to?(:monotonic_subscribe)
ActiveSupport::Notifications.monotonic_subscribe(event) { |*args| blk.call(*args) }
Expand Down

0 comments on commit 0f53df5

Please sign in to comment.