Class: DatabaseRecorder::Config

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Singleton
Defined in:
lib/database_recorder/config.rb

Constant Summary collapse

DEFAULT_DB_DRIVER =
:active_record
DEFAULT_LOG_FORMAT =
'[DB] %sql [%name]'
DEFAULT_STORAGE =
DatabaseRecorder::Storage::File
DB_DRIVER_VALUES =
%i[active_record mysql2 pg].freeze
[false, true, :color].freeze
STORAGE_VALUES =
{
  file: DatabaseRecorder::Storage::File,
  redis: DatabaseRecorder::Storage::Redis
}.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#db_driverObject

Returns the value of attribute db_driver.



21
22
23
# File 'lib/database_recorder/config.rb', line 21

def db_driver
  @db_driver
end

#log_formatObject

Returns the value of attribute log_format.



21
22
23
# File 'lib/database_recorder/config.rb', line 21

def log_format
  @log_format
end

Returns the value of attribute print_queries.



21
22
23
# File 'lib/database_recorder/config.rb', line 21

def print_queries
  @print_queries
end

#replay_recordingsObject

Returns the value of attribute replay_recordings.



21
22
23
# File 'lib/database_recorder/config.rb', line 21

def replay_recordings
  @replay_recordings
end

#storageObject

Returns the value of attribute storage.



21
22
23
# File 'lib/database_recorder/config.rb', line 21

def storage
  @storage
end

#storage_optionsObject

Returns the value of attribute storage_options.



21
22
23
# File 'lib/database_recorder/config.rb', line 21

def storage_options
  @storage_options
end

Class Method Details

.db_driver=(value) ⇒ Object



38
39
40
# File 'lib/database_recorder/config.rb', line 38

def db_driver=(value)
  instance.db_driver = DB_DRIVER_VALUES.include?(value) ? value : DEFAULT_DB_DRIVER
end

.load_defaultsObject



29
30
31
32
33
34
35
36
# File 'lib/database_recorder/config.rb', line 29

def load_defaults
  instance.db_driver = DEFAULT_DB_DRIVER
  instance.log_format = DEFAULT_LOG_FORMAT
  instance.print_queries = false
  instance.replay_recordings = false
  instance.storage = DEFAULT_STORAGE
  instance.storage_options = {}
end


42
43
44
# File 'lib/database_recorder/config.rb', line 42

def print_queries=(value)
  instance.print_queries = PRINT_QUERIES_VALUES.include?(value) ? value : false
end

.storage=(value) ⇒ Object



46
47
48
49
50
51
52
53
# File 'lib/database_recorder/config.rb', line 46

def storage=(value)
  instance.storage =
    if value.is_a?(Class) && value < Storage::Base
      value
    else
      STORAGE_VALUES[value]
    end
end