Module: Cogger::Registry
- Included in:
- Cogger
- Defined in:
- lib/cogger/registry.rb
Overview
Provides a global regsitry for global configuration.
Class Method Summary collapse
Instance Method Summary collapse
- #add_alias(key, *styles) ⇒ Object
- #add_emoji(key, value) ⇒ Object
- #add_filter(key) ⇒ Object
- #add_formatter(key, formatter, template = nil) ⇒ Object
- #aliases ⇒ Object
- #color ⇒ Object
- #defaults ⇒ Object
- #emojis ⇒ Object
- #filters ⇒ Object
- #formatters ⇒ Object
- #get_emoji(key) ⇒ Object
- #get_formatter(key) ⇒ Object
- #templates ⇒ Object
Class Method Details
.extended(descendant) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/cogger/registry.rb', line 8 def self.extended descendant descendant.add_alias(:debug, :white) .add_alias(:info, :green) .add_alias(:warn, :yellow) .add_alias(:error, :red) .add_alias(:fatal, :bold, :white, :on_red) .add_alias(:any, :dim, :bright_white) .add_emoji(:debug, "🔎") .add_emoji(:info, "🟢") .add_emoji(:warn, "⚠️") .add_emoji(:error, "🛑") .add_emoji(:fatal, "🔥") .add_emoji(:any, "⚫️") .add_formatter(:color, Cogger::Formatters::Color) .add_formatter( :detail, Cogger::Formatters::Simple, "[%<id>s] [%<level>s] [%<at>s] %<message>s" ) .add_formatter(:emoji, Cogger::Formatters::Emoji) .add_formatter(:json, Cogger::Formatters::JSON) .add_formatter(:property, Cogger::Formatters::Property) .add_formatter(:simple, Cogger::Formatters::Simple) .add_formatter :rack, Cogger::Formatters::Simple, "[%<id>s] [%<level>s] [%<at>s] %<verb>s %<status>s " \ "%<duration>s %<ip>s %<path>s %<length>s %<params>s" end |
Instance Method Details
#add_alias(key, *styles) ⇒ Object
37 38 39 40 |
# File 'lib/cogger/registry.rb', line 37 def add_alias(key, *styles) color.add_alias(key, *styles) self end |
#add_emoji(key, value) ⇒ Object
44 45 46 47 |
# File 'lib/cogger/registry.rb', line 44 def add_emoji key, value emojis[key.to_sym] = value self end |
#add_filter(key) ⇒ Object
55 56 57 58 |
# File 'lib/cogger/registry.rb', line 55 def add_filter key filters.add key.to_sym self end |
#add_formatter(key, formatter, template = nil) ⇒ Object
62 63 64 65 66 67 |
# File 'lib/cogger/registry.rb', line 62 def add_formatter key, formatter, template = nil formatters[key.to_sym] = [formatter, template || formatter::TEMPLATE] self rescue NameError raise NameError, "#{formatter}::TEMPLATE must be defined with a default template string." end |
#aliases ⇒ Object
42 |
# File 'lib/cogger/registry.rb', line 42 def aliases = color.aliases |
#color ⇒ Object
81 |
# File 'lib/cogger/registry.rb', line 81 def color = @color ||= Tone.new |
#defaults ⇒ Object
83 |
# File 'lib/cogger/registry.rb', line 83 def defaults = {emojis:, aliases:, formatters:, filters:, color:} |
#emojis ⇒ Object
53 |
# File 'lib/cogger/registry.rb', line 53 def emojis = @emojis ||= {} |
#filters ⇒ Object
60 |
# File 'lib/cogger/registry.rb', line 60 def filters = @filters ||= Set.new |
#formatters ⇒ Object
73 |
# File 'lib/cogger/registry.rb', line 73 def formatters = @formatters ||= {} |
#get_emoji(key) ⇒ Object
49 50 51 |
# File 'lib/cogger/registry.rb', line 49 def get_emoji key emojis.fetch(key.to_sym) { fail KeyError, "Unregistered emoji: #{key}." } end |
#get_formatter(key) ⇒ Object
69 70 71 |
# File 'lib/cogger/registry.rb', line 69 def get_formatter key formatters.fetch(key.to_sym) { fail KeyError, "Unregistered formatter: #{key}." } end |
#templates ⇒ Object
75 76 77 78 79 |
# File 'lib/cogger/registry.rb', line 75 def templates formatters.each.with_object({}) do |(key, (_formatter, template)), collection| collection[key] = template end end |