Module: DbLogTag::MultipleDb
- Defined in:
- lib/db_log_tag/multiple_db.rb
Class Method Summary collapse
- .db_info(clazz) ⇒ Object
- .db_tags ⇒ Object
- .reset ⇒ Object
- .set_db_tag(clazz, format_tag_proc, **options) ⇒ Object
Class Method Details
.db_info(clazz) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/db_log_tag/multiple_db.rb', line 32 def db_info(clazz) return unless db_tag_config = ([clazz] || [nil]) clazz_const = clazz.constantize db_info_tag = db_tag_config[:proc].call( clazz_const.connection_pool.db_config.name, clazz_const.current_shard, clazz_const.current_role ) DbLogTag::Colors.set_color(db_info_tag, db_tag_config[:color], db_tag_config[:font] || :bold) end |
.db_tags ⇒ Object
7 8 9 10 11 12 13 |
# File 'lib/db_log_tag/multiple_db.rb', line 7 def @@db_tags ||= { nil => { proc: lambda { |db, shard, role| "[shard:#{shard}|role:#{role}|db:#{db}]" } } } end |
.reset ⇒ Object
28 29 30 |
# File 'lib/db_log_tag/multiple_db.rb', line 28 def reset @@db_tags = nil end |
.set_db_tag(clazz, format_tag_proc, **options) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/db_log_tag/multiple_db.rb', line 15 def set_db_tag(clazz, format_tag_proc, **) tag_config = { proc: format_tag_proc, ** } if clazz.nil? [nil] = tag_config elsif clazz.is_a?(String) or clazz.is_a?(Symbol) [clazz.to_s.classify] = tag_config end end |