Module: DbLogTag::MultipleDb

Defined in:
lib/db_log_tag/multiple_db.rb

Class Method Summary collapse

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 = (db_tags[clazz] || db_tags[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_tagsObject



7
8
9
10
11
12
13
# File 'lib/db_log_tag/multiple_db.rb', line 7

def db_tags
  @@db_tags ||= {
    nil => {
      proc: lambda { |db, shard, role| "[shard:#{shard}|role:#{role}|db:#{db}]" }
    }
  }
end

.resetObject



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, **options)
  tag_config = {
    proc: format_tag_proc,
    **options
  }

  if clazz.nil?
    db_tags[nil] = tag_config
  elsif clazz.is_a?(String) or clazz.is_a?(Symbol)
    db_tags[clazz.to_s.classify] = tag_config
  end
end