Class: DatabaseCleaner::Configuration

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/database_cleaner/configuration.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



44
45
46
# File 'lib/database_cleaner/configuration.rb', line 44

def initialize
  @cleaners ||= Cleaners.new
end

Instance Attribute Details

#cleanersObject

Returns the value of attribute cleaners.



55
56
57
# File 'lib/database_cleaner/configuration.rb', line 55

def cleaners
  @cleaners
end

Instance Method Details

#add_cleaner(orm, opts = {}) ⇒ Object

TODO privatize the following methods in 2.0



121
122
123
124
125
126
# File 'lib/database_cleaner/configuration.rb', line 121

def add_cleaner(orm, opts = {})
  if DatabaseCleaner.called_externally?(__FILE__, caller)
    DatabaseCleaner.deprecate "Calling `DatabaseCleaner.add_cleaner` is deprecated, and will be removed in database_cleaner 2.0. Use `DatabaseCleaner.[]`, instead."
  end
  @cleaners.add_cleaner(orm, opts = {})
end

#app_rootObject



57
58
59
60
# File 'lib/database_cleaner/configuration.rb', line 57

def app_root
  DatabaseCleaner.deprecate "Calling `DatabaseCleaner.app_root` is deprecated, and will be removed in database_cleaner 2.0. Use `DatabaseCleaner::ActiveRecord.config_file_location`, instead."
  @app_root ||= Dir.pwd
end

#app_root=(value) ⇒ Object



62
63
64
65
# File 'lib/database_cleaner/configuration.rb', line 62

def app_root= value
  DatabaseCleaner.deprecate "Calling `DatabaseCleaner.app_root=` is deprecated, and will be removed in database_cleaner 2.0. Use `DatabaseCleaner::ActiveRecord.config_file_location=`, instead."
  @app_root = value
end

#cleanObject



81
82
83
# File 'lib/database_cleaner/configuration.rb', line 81

def clean
  connections.each { |connection| connection.clean }
end

#clean!Object

TODO remove the following methods in 2.0



97
98
99
100
# File 'lib/database_cleaner/configuration.rb', line 97

def clean!
  DatabaseCleaner.deprecate "Calling `DatabaseCleaner.clean!` is deprecated, and will be removed in database_cleaner 2.0. Use `DatabaseCleaner.clean`, instead."
  clean
end

#clean_with(*args) ⇒ Object



91
92
93
# File 'lib/database_cleaner/configuration.rb', line 91

def clean_with(*args)
  connections.each { |connection| connection.clean_with(*args) }
end

#clean_with!(*args) ⇒ Object



102
103
104
105
# File 'lib/database_cleaner/configuration.rb', line 102

def clean_with!(*args)
  DatabaseCleaner.deprecate "Calling `DatabaseCleaner.clean_with!` is deprecated, and will be removed in database_cleaner 2.0. Use `DatabaseCleaner.clean_with`, instead."
  clean_with(*args)
end

#cleaning(&inner_block) ⇒ Object



85
86
87
88
89
# File 'lib/database_cleaner/configuration.rb', line 85

def cleaning(&inner_block)
  connections.inject(inner_block) do |curr_block, connection|
    proc { connection.cleaning(&curr_block) }
  end.call
end

#connectionsObject



111
112
113
114
115
116
117
# File 'lib/database_cleaner/configuration.rb', line 111

def connections
  if DatabaseCleaner.called_externally?(__FILE__, caller)
    DatabaseCleaner.deprecate "Calling `DatabaseCleaner.connections` is deprecated, and will be removed in database_cleaner 2.0. Use `DatabaseCleaner.cleaners`, instead."
  end
  add_cleaner(:autodetect) if @cleaners.none?
  @cleaners.values
end

#init_cleanersObject



107
108
109
# File 'lib/database_cleaner/configuration.rb', line 107

def init_cleaners
  DatabaseCleaner.deprecate "Calling `DatabaseCleaner.init_cleaners` is deprecated, and will be removed in database_cleaner 2.0 with no replacement."
end

#loggerObject



67
68
69
70
# File 'lib/database_cleaner/configuration.rb', line 67

def logger
  DatabaseCleaner.deprecate "Calling `DatabaseCleaner.logger` is deprecated, and will be removed in database_cleaner 2.0 with no replacement."
  @logger ||= Logger.new(STDOUT).tap { |l| l.level = Logger::ERROR }
end

#logger=(value) ⇒ Object



72
73
74
75
# File 'lib/database_cleaner/configuration.rb', line 72

def logger= value
  DatabaseCleaner.deprecate "Calling `DatabaseCleaner.logger=` is deprecated, and will be removed in database_cleaner 2.0 with no replacement."
  @logger = value
end

#remove_duplicatesObject



128
129
130
131
132
133
# File 'lib/database_cleaner/configuration.rb', line 128

def remove_duplicates
  if DatabaseCleaner.called_externally?(__FILE__, caller)
    DatabaseCleaner.deprecate "Calling `DatabaseCleaner.remove_duplicates` is deprecated, and will be removed in database_cleaner 2.0 with no replacement."
  end
  @cleaners.remove_duplicates
end

#startObject



77
78
79
# File 'lib/database_cleaner/configuration.rb', line 77

def start
  connections.each { |connection| connection.start }
end