Class: RailsSpotlight::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/rails_spotlight/configuration.rb

Overview

rubocop:disable Metrics/ClassLength

Constant Summary collapse

DEFAULT_NOT_ENCODABLE_EVENT_VALUES =
{
  'ActiveRecord' => [
    'ActiveRecord::ConnectionAdapters::AbstractAdapter',
    'ActiveRecord::ConnectionAdapters::PostgreSQLAdapter',
    'ActiveRecord::ConnectionAdapters::RealTransaction'
  ],
  'ActionDispatch' => ['ActionDispatch::Request', 'ActionDispatch::Response']
}.freeze
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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Configuration

rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity, Metrics/AbcSize



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/rails_spotlight/configuration.rb', line 47

def initialize(opts = {}) # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity, Metrics/AbcSize
  @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
  @live_console_enabled = opts[:live_console_enabled].nil? ? false : true?(opts[:live_console_enabled])
  @request_completed_broadcast_enabled = opts[:request_completed_broadcast_enabled].nil? ? false : true?(opts[:request_completed_broadcast_enabled])
  @middleware_skipped_paths = opts[:middleware_skipped_paths] || []
  @not_encodable_event_values = DEFAULT_NOT_ENCODABLE_EVENT_VALUES.merge(opts[:not_encodable_event_values] || {})
  @use_action_cable = opts[:use_action_cable].nil? ? false : true?(opts[:use_action_cable])
  @auto_mount_action_cable = opts[:auto_mount_action_cable].nil? ? false : true?(opts[:auto_mount_action_cable])
  @action_cable_mount_path = opts[:action_cable_mount_path] || '/cable'
  @block_editing_files = opts[:block_editing_files].nil? ? false : true?(opts[:block_editing_files])
  @block_editing_files_outside_of_the_project = opts[:block_editing_files_outside_of_the_project].nil? ? true : true?(opts[:block_editing_files_outside_of_the_project])
  @skip_rendered_ivars = SKIP_RENDERED_IVARS + (opts[:skip_rendered_ivars] || []).map(&:to_sym)
  @directory_index_ignore = opts[:directory_index_ignore] || DEFAULT_DIRECTORY_INDEX_IGNORE
  @rubocop_config_path = opts[:rubocop_config_path] ? File.join(self.class.rails_root, opts[:rubocop_config_path]) : nil
  @live_logs_enabled = opts[:live_logs_enabled].nil? ? false : true?(opts[:live_logs_enabled])
  @default_rs_src = opts[:default_rs_src] || 'default'
  @form_js_execution_token = opts[:form_js_execution_token] || Digest::MD5.hexdigest(detect_project_name)
end

Instance Attribute Details

#action_cable_mount_pathObject (readonly)

Returns the value of attribute action_cable_mount_path.



41
42
43
# File 'lib/rails_spotlight/configuration.rb', line 41

def action_cable_mount_path
  @action_cable_mount_path
end

#block_editing_filesObject (readonly)

Returns the value of attribute block_editing_files.



41
42
43
# File 'lib/rails_spotlight/configuration.rb', line 41

def block_editing_files
  @block_editing_files
end

#block_editing_files_outside_of_the_projectObject (readonly)

Returns the value of attribute block_editing_files_outside_of_the_project.



41
42
43
# File 'lib/rails_spotlight/configuration.rb', line 41

def block_editing_files_outside_of_the_project
  @block_editing_files_outside_of_the_project
end

#default_rs_srcObject (readonly)

Returns the value of attribute default_rs_src.



41
42
43
# File 'lib/rails_spotlight/configuration.rb', line 41

def default_rs_src
  @default_rs_src
end

#directory_index_ignoreObject (readonly)

Returns the value of attribute directory_index_ignore.



41
42
43
# File 'lib/rails_spotlight/configuration.rb', line 41

def directory_index_ignore
  @directory_index_ignore
end

#form_js_execution_tokenObject (readonly)

Returns the value of attribute form_js_execution_token.



41
42
43
# File 'lib/rails_spotlight/configuration.rb', line 41

def form_js_execution_token
  @form_js_execution_token
end

#loggerObject (readonly)

Returns the value of attribute logger.



41
42
43
# File 'lib/rails_spotlight/configuration.rb', line 41

def logger
  @logger
end

#middleware_skipped_pathsObject (readonly)

Returns the value of attribute middleware_skipped_paths.



41
42
43
# File 'lib/rails_spotlight/configuration.rb', line 41

def middleware_skipped_paths
  @middleware_skipped_paths
end

#not_encodable_event_valuesObject (readonly)

Returns the value of attribute not_encodable_event_values.



41
42
43
# File 'lib/rails_spotlight/configuration.rb', line 41

def not_encodable_event_values
  @not_encodable_event_values
end

#project_nameObject (readonly)

Returns the value of attribute project_name.



41
42
43
# File 'lib/rails_spotlight/configuration.rb', line 41

def project_name
  @project_name
end

#rubocop_config_pathObject (readonly)

Returns the value of attribute rubocop_config_path.



41
42
43
# File 'lib/rails_spotlight/configuration.rb', line 41

def rubocop_config_path
  @rubocop_config_path
end

#skip_rendered_ivarsObject (readonly)

Returns the value of attribute skip_rendered_ivars.



41
42
43
# File 'lib/rails_spotlight/configuration.rb', line 41

def skip_rendered_ivars
  @skip_rendered_ivars
end

#source_pathObject (readonly)

Returns the value of attribute source_path.



41
42
43
# File 'lib/rails_spotlight/configuration.rb', line 41

def source_path
  @source_path
end

#storage_pathObject (readonly)

Returns the value of attribute storage_path.



41
42
43
# File 'lib/rails_spotlight/configuration.rb', line 41

def storage_path
  @storage_path
end

#storage_pool_sizeObject (readonly)

Returns the value of attribute storage_pool_size.



41
42
43
# File 'lib/rails_spotlight/configuration.rb', line 41

def storage_pool_size
  @storage_pool_size
end

#use_action_cableObject (readonly) Also known as: use_action_cable?

Returns the value of attribute use_action_cable.



41
42
43
# File 'lib/rails_spotlight/configuration.rb', line 41

def use_action_cable
  @use_action_cable
end

Class Method Details

.load_configObject



98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/rails_spotlight/configuration.rb', line 98

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_rootObject



114
115
116
# File 'lib/rails_spotlight/configuration.rb', line 114

def self.rails_root
  @rails_root ||= (Rails.root.to_s.presence || Dir.pwd).freeze
end

Instance Method Details

#action_cable_present?Boolean

Returns:

  • (Boolean)


94
95
96
# File 'lib/rails_spotlight/configuration.rb', line 94

def action_cable_present?
  defined?(ActionCable) && true
end

#auto_mount_action_cableObject Also known as: auto_mount_action_cable?



88
89
90
# File 'lib/rails_spotlight/configuration.rb', line 88

def auto_mount_action_cable
  @auto_mount_action_cable && use_action_cable && action_cable_present?
end

#live_console_enabledObject Also known as: live_console_enabled?



70
71
72
# File 'lib/rails_spotlight/configuration.rb', line 70

def live_console_enabled
  @live_console_enabled && use_action_cable && action_cable_present?
end

#live_logs_enabledObject Also known as: live_logs_enabled?



74
75
76
# File 'lib/rails_spotlight/configuration.rb', line 74

def live_logs_enabled
  @live_logs_enabled && use_action_cable && action_cable_present?
end

#rails_rootObject



118
119
120
# File 'lib/rails_spotlight/configuration.rb', line 118

def rails_root
  self.class.rails_root
end

#request_completed_broadcast_enabledObject Also known as: request_completed_broadcast_enabled?



82
83
84
# File 'lib/rails_spotlight/configuration.rb', line 82

def request_completed_broadcast_enabled
  @request_completed_broadcast_enabled && use_action_cable && action_cable_present?
end