Class: Relaton::Registry

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/relaton/registry.rb

Constant Summary collapse

SUPPORTED_GEMS =
%w[
  relaton_gb relaton_iec relaton_ietf relaton_iso relaton_itu relaton_nist
  relaton_ogc relaton_calconnect
].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRegistry

Returns a new instance of Registry.



17
18
19
20
# File 'lib/relaton/registry.rb', line 17

def initialize
  @processors = {}
  register_gems
end

Instance Attribute Details

#processorsObject (readonly)

Returns the value of attribute processors.



15
16
17
# File 'lib/relaton/registry.rb', line 15

def processors
  @processors
end

Instance Method Details

#by_type(type) ⇒ RelatonIso::Processor, ...

Find processor by type

Parameters:

  • type (String)

Returns:

  • (RelatonIso::Processor, RelatonIec::Processor, RelatonNist::Processor, RelatonIetf::Processot, RelatonItu::Processor, RelatonGb::Processor, RelatonOgc::Processor, RelatonCalconnect::Processor)


61
62
63
# File 'lib/relaton/registry.rb', line 61

def by_type(type)
  processors.values.detect { |v| v.prefix == type.upcase }
end

#find_processor(short) ⇒ Object



45
46
47
# File 'lib/relaton/registry.rb', line 45

def find_processor(short)
  processors[short.to_sym]
end

#register(processor) ⇒ Object

Raises:



35
36
37
38
39
40
41
42
43
# File 'lib/relaton/registry.rb', line 35

def register(processor)
  raise Error unless processor < ::Relaton::Processor

  p = processor.new
  return if processors[p.short]

  puts "[relaton] processor \"#{p.short}\" registered"
  processors[p.short] = p
end

#register_gemsObject



22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/relaton/registry.rb', line 22

def register_gems
  puts "[relaton] Info: detecting backends:"
  SUPPORTED_GEMS.each do |b|
    begin
      require b
      require "#{b}/processor"
      register Kernel.const_get "#{camel_case(b)}::Processor"
    rescue LoadError
      puts "[relaton] Error: backend #{b} not present"
    end
  end
end

#supported_processorsArray<Symbol>

Returns:

  • (Array<Symbol>)


50
51
52
# File 'lib/relaton/registry.rb', line 50

def supported_processors
  processors.keys
end