Class: Voom::Presenters::Registry

Inherits:
Object
  • Object
show all
Extended by:
Trace
Defined in:
lib/voom/presenters/registry.rb

Class Method Summary collapse

Class Method Details

.define(name, namespace, options, &block) ⇒ Object



14
15
16
17
18
# File 'lib/voom/presenters/registry.rb', line 14

def self.define(name, namespace, options, &block)
  namespace = Array(namespace).map(&:to_s)
  fq_name = namespace.any? ? namespace.join(':') + ':' + name.to_s : name.to_s
  registry[fq_name] = Voom::Presenters::DSL::Definition.new(name, namespace, options, &block)
end

.finalizeObject



27
28
29
30
31
32
33
34
35
36
# File 'lib/voom/presenters/registry.rb', line 27

def self.finalize
  registry.each do |key, definition|
    begin
      register(key, build(definition))
    rescue Exception => e
      logger.error {"Failed to load presenter #{key}: #{e.inspect}."}
      raise e
    end
  end
end

.load(directory) ⇒ Object



20
21
22
23
24
25
# File 'lib/voom/presenters/registry.rb', line 20

def self.load(directory)
  files = File.join(directory, '**', '*.pom')
  Dir.glob(files) do |file|
    Kernel.load file
  end
end

.registryObject



10
11
12
# File 'lib/voom/presenters/registry.rb', line 10

def self.registry
  @registry
end

.reset!Object

This method empties out the dsl definitions It should ONLY be used for testing purposes



40
41
42
# File 'lib/voom/presenters/registry.rb', line 40

def self.reset!
  registry.clear
end