Class: Lumberjack::Tags
- Inherits:
-
Object
- Object
- Lumberjack::Tags
- Defined in:
- lib/lumberjack/tags.rb
Class Method Summary collapse
-
.expand_runtime_values(hash) ⇒ Hash
Ensure keys are strings and expand any values in a hash that are Proc’s by calling them and replacing the value with the result.
-
.stringify_keys(hash) ⇒ Hash
Transform hash keys to strings.
Class Method Details
.expand_runtime_values(hash) ⇒ Hash
Ensure keys are strings and expand any values in a hash that are Proc’s by calling them and replacing the value with the result. This allows setting global tags with runtime values.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/lumberjack/tags.rb', line 25 def (hash) return nil if hash.nil? if hash.all? { |key, value| key.is_a?(String) && !value.is_a?(Proc) } return hash end copy = {} hash.each do |key, value| if value.is_a?(Proc) && (value.arity == 0 || value.arity == -1) value = value.call end copy[key.to_s] = value end copy end |
.stringify_keys(hash) ⇒ Hash
Transform hash keys to strings. This method exists for optimization and backward compatibility. If a hash already has string keys, it will be returned as is.
11 12 13 14 15 16 17 18 |
# File 'lib/lumberjack/tags.rb', line 11 def stringify_keys(hash) return nil if hash.nil? if hash.keys.all? { |key| key.is_a?(String) } hash else hash.transform_keys(&:to_s) end end |