Class: Helium::Console::Registry

Inherits:
Object
  • Object
show all
Defined in:
lib/helium/console/registry.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.class_formattersObject



13
14
15
# File 'lib/helium/console/registry.rb', line 13

def self.class_formatters
  @class_formatters ||= new
end

.instance_formattersObject



9
10
11
# File 'lib/helium/console/registry.rb', line 9

def self.instance_formatters
  @instance_formatters ||= new
end

Instance Method Details

#add(mod, formatter) ⇒ Object



17
18
19
# File 'lib/helium/console/registry.rb', line 17

def add(mod, formatter)
  handlers[mod] = formatter
end

#define(mod, &block) ⇒ Object



21
22
23
# File 'lib/helium/console/registry.rb', line 21

def define(mod, &block)
  add(mod, Class.new(Formatter, &block))
end

#handler_for(klass) ⇒ Object



25
26
27
28
29
30
31
# File 'lib/helium/console/registry.rb', line 25

def handler_for(klass)
  klass.ancestors.each do |ancestor|
    result = handlers[ancestor] || handlers[ancestor.name]
    return result if result
  end
  handlers[BasicObject]
end