Class: ActiveSupport::TaggedLogging::TagStack

Inherits:
Object
  • Object
show all
Defined in:
activesupport/lib/active_support/tagged_logging.rb

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeTagStack

Returns a new instance of TagStack.



72
73
74
75
# File 'activesupport/lib/active_support/tagged_logging.rb', line 72

def initialize
  @tags = []
  @tags_string = nil
end

Instance Attribute Details

#tagsObject (readonly)

Returns the value of attribute tags



70
71
72
# File 'activesupport/lib/active_support/tagged_logging.rb', line 70

def tags
  @tags
end

Instance Method Details

#clearObject



90
91
92
93
# File 'activesupport/lib/active_support/tagged_logging.rb', line 90

def clear
  @tags_string = nil
  @tags.clear
end

#format_message(message) ⇒ Object



95
96
97
98
99
100
101
102
103
104
# File 'activesupport/lib/active_support/tagged_logging.rb', line 95

def format_message(message)
  if @tags.empty?
    message
  elsif @tags.size == 1
    "[#{@tags[0]}] #{message}"
  else
    @tags_string ||= "[#{@tags.join("] [")}] "
    "#{@tags_string}#{message}"
  end
end

#pop_tags(count) ⇒ Object



85
86
87
88
# File 'activesupport/lib/active_support/tagged_logging.rb', line 85

def pop_tags(count)
  @tags_string = nil
  @tags.pop(count)
end

#push_tags(tags) ⇒ Object



77
78
79
80
81
82
83
# File 'activesupport/lib/active_support/tagged_logging.rb', line 77

def push_tags(tags)
  @tags_string = nil
  tags.flatten!
  tags.reject!(&:blank?)
  @tags.concat(tags)
  tags
end