Class: CodeKindly::Utils::ActiveRecord
- Inherits:
-
Object
- Object
- CodeKindly::Utils::ActiveRecord
- Includes:
- Deprecation
- Defined in:
- lib/code_kindly/utils/active_record.rb
Constant Summary collapse
- RAILS =
Kernel.const_defined?(:Rails) ? ::Rails : nil
Class Method Summary collapse
- .active_record_classes_by_connection ⇒ Object
- .classes_by_connection ⇒ Object
- .clear_scope(scope) ⇒ Object
- .config(name = nil) ⇒ Object
- .configs ⇒ Object
- .configurations ⇒ Object
- .default_connection_class(connection = nil) ⇒ Object
Class Method Details
.active_record_classes_by_connection ⇒ Object
13 14 15 16 17 18 |
# File 'lib/code_kindly/utils/active_record.rb', line 13 def active_record_classes_by_connection deprecate :active_record_classes_by_connection, :classes_by_connection, :'0.1.0' classes_by_connection end |
.classes_by_connection ⇒ Object
20 21 22 |
# File 'lib/code_kindly/utils/active_record.rb', line 20 def classes_by_connection @classes_by_connection ||= find_classes_by_connection end |
.clear_scope(scope) ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'lib/code_kindly/utils/active_record.rb', line 24 def clear_scope(scope) if scope.count.zero? puts 'Nothing to clear' return end puts "Clearing #{scope.count} #{scope.name} records" scope.delete_all end |
.config(name = nil) ⇒ Object
33 34 35 |
# File 'lib/code_kindly/utils/active_record.rb', line 33 def config(name = nil) configs[name || default_name] end |
.configs ⇒ Object
37 38 39 |
# File 'lib/code_kindly/utils/active_record.rb', line 37 def configs @configs ||= ::ActiveRecord::Base.configurations end |
.configurations ⇒ Object
41 42 43 44 |
# File 'lib/code_kindly/utils/active_record.rb', line 41 def configurations deprecate :configurations, :configs, :'0.1.0' configs end |
.default_connection_class(connection = nil) ⇒ Object
46 47 48 49 50 51 52 53 54 55 |
# File 'lib/code_kindly/utils/active_record.rb', line 46 def default_connection_class(connection = nil) connection ||= default_name @default_connection_class ||= {}.with_indifferent_access @default_connection_class[connection] ||= begin it = classes_by_connection.fetch(connection, []).first key = classes_by_connection.keys.first it ||= classes_by_connection.fetch(key).first it end end |