Class: RailsSpotlight::Configuration
- Inherits:
-
Object
- Object
- RailsSpotlight::Configuration
- Defined in:
- lib/rails_spotlight/configuration.rb
Constant Summary collapse
- DEFAULT_NOT_ENCODABLE_EVENT_VALUES =
{ 'ActiveRecord' => [ 'ActiveRecord::ConnectionAdapters::AbstractAdapter', 'ActiveRecord::ConnectionAdapters::PostgreSQLAdapter', 'ActiveRecord::ConnectionAdapters::RealTransaction', 'ActiveRecord::Transaction', 'ActiveRecord::SchemaMigration' ], 'ActionDispatch' => ['ActionDispatch::Request', 'ActionDispatch::Response'] }.freeze
- MAXIMUM_EVENT_VALUE_SIZE =
100000
- DEFAULT_DIRECTORY_INDEX_IGNORE =
%w[ /.git **/*.lock **/.DS_Store /app/assets/images/** /app/assets/fonts/** /app/assets/builds/** **/.keep ].freeze
- SKIP_RENDERED_IVARS =
%i[ @_routes @_config @view_renderer @lookup_context @_assigns @_controller @_request @_default_form_builder @view_flow @output_buffer @virtual_path @tag_builder @assets_environment @asset_resolver_strategies @_main_app @_devise_route_context @devise_mapping ].freeze
Instance Attribute Summary collapse
-
#block_editing_files ⇒ Object
readonly
Returns the value of attribute block_editing_files.
-
#block_editing_files_outside_of_the_project ⇒ Object
readonly
Returns the value of attribute block_editing_files_outside_of_the_project.
-
#cable_mount_path ⇒ Object
readonly
Returns the value of attribute cable_mount_path.
-
#data_access_token ⇒ Object
readonly
Returns the value of attribute data_access_token.
-
#default_rs_src ⇒ Object
readonly
Returns the value of attribute default_rs_src.
-
#directory_index_ignore ⇒ Object
readonly
Returns the value of attribute directory_index_ignore.
-
#disable_active_support_subscriptions ⇒ Object
readonly
Returns the value of attribute disable_active_support_subscriptions.
-
#enabled ⇒ Object
readonly
Returns the value of attribute enabled.
-
#file_manager_enabled ⇒ Object
(also: #file_manager_enabled?)
readonly
Returns the value of attribute file_manager_enabled.
-
#form_js_execution_token ⇒ Object
readonly
Returns the value of attribute form_js_execution_token.
-
#irb_console_enabled ⇒ Object
(also: #irb_console_enabled?)
readonly
Returns the value of attribute irb_console_enabled.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#logs_enabled ⇒ Object
(also: #logs_enabled?)
readonly
Returns the value of attribute logs_enabled.
-
#maximum_event_value_size ⇒ Object
readonly
Returns the value of attribute maximum_event_value_size.
-
#middleware_skipped_paths ⇒ Object
readonly
Returns the value of attribute middleware_skipped_paths.
-
#not_encodable_event_values ⇒ Object
readonly
Returns the value of attribute not_encodable_event_values.
-
#project_name ⇒ Object
readonly
Returns the value of attribute project_name.
-
#rubocop_config_path ⇒ Object
readonly
Returns the value of attribute rubocop_config_path.
-
#rubocop_enabled ⇒ Object
(also: #rubocop_enabled?)
readonly
Returns the value of attribute rubocop_enabled.
-
#sidekiq_logs_enabled ⇒ Object
(also: #sidekiq_logs_enabled?)
readonly
Returns the value of attribute sidekiq_logs_enabled.
-
#skip_rendered_ivars ⇒ Object
readonly
Returns the value of attribute skip_rendered_ivars.
-
#source_path ⇒ Object
readonly
Returns the value of attribute source_path.
-
#sql_console_enabled ⇒ Object
(also: #sql_console_enabled?)
readonly
Returns the value of attribute sql_console_enabled.
-
#storage_path ⇒ Object
readonly
Returns the value of attribute storage_path.
-
#storage_pool_size ⇒ Object
readonly
Returns the value of attribute storage_pool_size.
-
#use_cable ⇒ Object
(also: #use_cable?)
readonly
Returns the value of attribute use_cable.
Class Method Summary collapse
Instance Method Summary collapse
- #action_cable_present? ⇒ Boolean
- #auto_mount_cable ⇒ Object (also: #auto_mount_cable?)
- #cable_console_enabled ⇒ Object (also: #cable_console_enabled?)
- #cable_logs_enabled ⇒ Object (also: #cable_logs_enabled?)
-
#enabled? ⇒ Boolean
We do not recommend using Rails Spotlight in production.
-
#initialize(opts = {}) ⇒ Configuration
constructor
rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity, Metrics/AbcSize.
- #rails_root ⇒ Object
- #request_completed_broadcast_enabled ⇒ Object (also: #request_completed_broadcast_enabled?)
Constructor Details
#initialize(opts = {}) ⇒ Configuration
rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity, Metrics/AbcSize
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/rails_spotlight/configuration.rb', line 52 def initialize(opts = {}) # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity, Metrics/AbcSize @enabled = bool_val(:enabled, opts, default: false) @sidekiq_logs_enabled = bool_val(:logs_enabled, opts, default: false) @logs_enabled = bool_val(:logs_enabled, opts, default: true) @project_name = opts[:project_name] || detect_project_name @source_path = opts[:source_path] || self.class.rails_root @logger = opts[:logger] || Logger.new(File.join(self.class.rails_root, 'log', 'rails_spotlight.log')) @storage_path = opts[:storage_path] || File.join(self.class.rails_root, 'tmp', 'data', 'rails_spotlight') @storage_pool_size = opts[:storage_pool_size] || 20 @cable_console_enabled = bool_val(:cable_console_enabled, opts) @request_completed_broadcast_enabled = bool_val(:request_completed_broadcast_enabled, opts) @middleware_skipped_paths = opts[:middleware_skipped_paths] || [] @not_encodable_event_values = DEFAULT_NOT_ENCODABLE_EVENT_VALUES.merge(opts[:not_encodable_event_values] || {}) @use_cable = bool_val(:use_cable, opts) @auto_mount_cable = bool_val(:auto_mount_cable, opts) @cable_mount_path = opts[:cable_mount_path] || '/cable' @block_editing_files = bool_val(:block_editing_files, opts) @block_editing_files_outside_of_the_project = bool_val(:block_editing_files_outside_of_the_project, opts, default: true) @file_manager_enabled = bool_val(:file_manager_enabled, opts, default: true) @skip_rendered_ivars = SKIP_RENDERED_IVARS + (opts[:skip_rendered_ivars] || []).map(&:to_sym) @directory_index_ignore = Array(opts[:directory_index_ignore] || DEFAULT_DIRECTORY_INDEX_IGNORE) @rubocop_enabled = bool_val(:rubocop_enabled, opts, default: true) @rubocop_config_path = opts[:rubocop_config_path] ? File.join(self.class.rails_root, opts[:rubocop_config_path]) : nil @cable_logs_enabled = bool_val(:cable_logs_enabled, opts) @default_rs_src = opts[:default_rs_src] || 'default' @form_js_execution_token = opts[:form_js_execution_token] || Digest::MD5.hexdigest(detect_project_name) @sql_console_enabled = bool_val(:sql_console_enabled, opts, default: true) @irb_console_enabled = bool_val(:irb_console_enabled, opts, default: true) @data_access_token = opts[:data_access_token].present? ? opts[:data_access_token] : nil @disable_active_support_subscriptions = Array(opts[:disable_active_support_subscriptions] || []) @maximum_event_value_size = opts[:maximum_event_value_size] || MAXIMUM_EVENT_VALUE_SIZE end |
Instance Attribute Details
#block_editing_files ⇒ Object (readonly)
Returns the value of attribute block_editing_files.
45 46 47 |
# File 'lib/rails_spotlight/configuration.rb', line 45 def block_editing_files @block_editing_files end |
#block_editing_files_outside_of_the_project ⇒ Object (readonly)
Returns the value of attribute block_editing_files_outside_of_the_project.
45 46 47 |
# File 'lib/rails_spotlight/configuration.rb', line 45 def block_editing_files_outside_of_the_project @block_editing_files_outside_of_the_project end |
#cable_mount_path ⇒ Object (readonly)
Returns the value of attribute cable_mount_path.
45 46 47 |
# File 'lib/rails_spotlight/configuration.rb', line 45 def cable_mount_path @cable_mount_path end |
#data_access_token ⇒ Object (readonly)
Returns the value of attribute data_access_token.
45 46 47 |
# File 'lib/rails_spotlight/configuration.rb', line 45 def data_access_token @data_access_token end |
#default_rs_src ⇒ Object (readonly)
Returns the value of attribute default_rs_src.
45 46 47 |
# File 'lib/rails_spotlight/configuration.rb', line 45 def default_rs_src @default_rs_src end |
#directory_index_ignore ⇒ Object (readonly)
Returns the value of attribute directory_index_ignore.
45 46 47 |
# File 'lib/rails_spotlight/configuration.rb', line 45 def directory_index_ignore @directory_index_ignore end |
#disable_active_support_subscriptions ⇒ Object (readonly)
Returns the value of attribute disable_active_support_subscriptions.
45 46 47 |
# File 'lib/rails_spotlight/configuration.rb', line 45 def disable_active_support_subscriptions @disable_active_support_subscriptions end |
#enabled ⇒ Object (readonly)
Returns the value of attribute enabled.
45 46 47 |
# File 'lib/rails_spotlight/configuration.rb', line 45 def enabled @enabled end |
#file_manager_enabled ⇒ Object (readonly) Also known as: file_manager_enabled?
Returns the value of attribute file_manager_enabled.
45 46 47 |
# File 'lib/rails_spotlight/configuration.rb', line 45 def file_manager_enabled @file_manager_enabled end |
#form_js_execution_token ⇒ Object (readonly)
Returns the value of attribute form_js_execution_token.
45 46 47 |
# File 'lib/rails_spotlight/configuration.rb', line 45 def form_js_execution_token @form_js_execution_token end |
#irb_console_enabled ⇒ Object (readonly) Also known as: irb_console_enabled?
Returns the value of attribute irb_console_enabled.
45 46 47 |
# File 'lib/rails_spotlight/configuration.rb', line 45 def irb_console_enabled @irb_console_enabled end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
45 46 47 |
# File 'lib/rails_spotlight/configuration.rb', line 45 def logger @logger end |
#logs_enabled ⇒ Object (readonly) Also known as: logs_enabled?
Returns the value of attribute logs_enabled.
45 46 47 |
# File 'lib/rails_spotlight/configuration.rb', line 45 def logs_enabled @logs_enabled end |
#maximum_event_value_size ⇒ Object (readonly)
Returns the value of attribute maximum_event_value_size.
45 46 47 |
# File 'lib/rails_spotlight/configuration.rb', line 45 def maximum_event_value_size @maximum_event_value_size end |
#middleware_skipped_paths ⇒ Object (readonly)
Returns the value of attribute middleware_skipped_paths.
45 46 47 |
# File 'lib/rails_spotlight/configuration.rb', line 45 def middleware_skipped_paths @middleware_skipped_paths end |
#not_encodable_event_values ⇒ Object (readonly)
Returns the value of attribute not_encodable_event_values.
45 46 47 |
# File 'lib/rails_spotlight/configuration.rb', line 45 def not_encodable_event_values @not_encodable_event_values end |
#project_name ⇒ Object (readonly)
Returns the value of attribute project_name.
45 46 47 |
# File 'lib/rails_spotlight/configuration.rb', line 45 def project_name @project_name end |
#rubocop_config_path ⇒ Object (readonly)
Returns the value of attribute rubocop_config_path.
45 46 47 |
# File 'lib/rails_spotlight/configuration.rb', line 45 def rubocop_config_path @rubocop_config_path end |
#rubocop_enabled ⇒ Object (readonly) Also known as: rubocop_enabled?
Returns the value of attribute rubocop_enabled.
45 46 47 |
# File 'lib/rails_spotlight/configuration.rb', line 45 def rubocop_enabled @rubocop_enabled end |
#sidekiq_logs_enabled ⇒ Object (readonly) Also known as: sidekiq_logs_enabled?
Returns the value of attribute sidekiq_logs_enabled.
45 46 47 |
# File 'lib/rails_spotlight/configuration.rb', line 45 def sidekiq_logs_enabled @sidekiq_logs_enabled end |
#skip_rendered_ivars ⇒ Object (readonly)
Returns the value of attribute skip_rendered_ivars.
45 46 47 |
# File 'lib/rails_spotlight/configuration.rb', line 45 def skip_rendered_ivars @skip_rendered_ivars end |
#source_path ⇒ Object (readonly)
Returns the value of attribute source_path.
45 46 47 |
# File 'lib/rails_spotlight/configuration.rb', line 45 def source_path @source_path end |
#sql_console_enabled ⇒ Object (readonly) Also known as: sql_console_enabled?
Returns the value of attribute sql_console_enabled.
45 46 47 |
# File 'lib/rails_spotlight/configuration.rb', line 45 def sql_console_enabled @sql_console_enabled end |
#storage_path ⇒ Object (readonly)
Returns the value of attribute storage_path.
45 46 47 |
# File 'lib/rails_spotlight/configuration.rb', line 45 def storage_path @storage_path end |
#storage_pool_size ⇒ Object (readonly)
Returns the value of attribute storage_pool_size.
45 46 47 |
# File 'lib/rails_spotlight/configuration.rb', line 45 def storage_pool_size @storage_pool_size end |
#use_cable ⇒ Object (readonly) Also known as: use_cable?
Returns the value of attribute use_cable.
45 46 47 |
# File 'lib/rails_spotlight/configuration.rb', line 45 def use_cable @use_cable end |
Class Method Details
.load_config ⇒ Object
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/rails_spotlight/configuration.rb', line 110 def self.load_config config_file = File.join(rails_root, 'config', 'rails_spotlight.yml') return new unless File.exist?(config_file) erb_result = ERB.new(File.read(config_file)).result data = YAML.safe_load(erb_result) || {} # Support older versions of Ruby and Rails opts = data.each_with_object({}) do |(key, value), memo| new_key = key.is_a?(String) ? key.downcase.to_sym : key memo[new_key] = value end new(opts) end |
.rails_root ⇒ Object
126 |
# File 'lib/rails_spotlight/configuration.rb', line 126 def self.rails_root = @rails_root ||= (Rails.root.to_s.presence || Dir.pwd).freeze |
Instance Method Details
#action_cable_present? ⇒ Boolean
89 |
# File 'lib/rails_spotlight/configuration.rb', line 89 def action_cable_present? = defined?(ActionCable) && true |
#auto_mount_cable ⇒ Object Also known as: auto_mount_cable?
88 |
# File 'lib/rails_spotlight/configuration.rb', line 88 def auto_mount_cable = @auto_mount_cable && use_cable && action_cable_present? |
#cable_console_enabled ⇒ Object Also known as: cable_console_enabled?
85 |
# File 'lib/rails_spotlight/configuration.rb', line 85 def cable_console_enabled = @cable_console_enabled && use_cable && action_cable_present? |
#cable_logs_enabled ⇒ Object Also known as: cable_logs_enabled?
86 |
# File 'lib/rails_spotlight/configuration.rb', line 86 def cable_logs_enabled = @cable_logs_enabled && use_cable && action_cable_present? |
#enabled? ⇒ Boolean
We do not recommend using Rails Spotlight in production. However, if you still want to do it, a data_access_token is required
104 105 106 107 108 |
# File 'lib/rails_spotlight/configuration.rb', line 104 def enabled? return enabled unless Rails.env.production? enabled && data_access_token.present? end |
#rails_root ⇒ Object
127 |
# File 'lib/rails_spotlight/configuration.rb', line 127 def rails_root = self.class.rails_root |
#request_completed_broadcast_enabled ⇒ Object Also known as: request_completed_broadcast_enabled?
87 |
# File 'lib/rails_spotlight/configuration.rb', line 87 def request_completed_broadcast_enabled = @request_completed_broadcast_enabled && use_cable && action_cable_present? |