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 relaton_omg relaton_un relaton_w3c
  relaton_ieee relaton_iho relaton_bipm relaton_ecma relaton_cie relaton_bsi
  relaton_cen relaton_iana relaton_3gpp relaton_oasis
].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRegistry

Returns a new instance of Registry.



19
20
21
22
# File 'lib/relaton/registry.rb', line 19

def initialize
  @processors = {}
  register_gems
end

Instance Attribute Details

#processorsObject (readonly)

Returns the value of attribute processors.



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

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)


76
77
78
# File 'lib/relaton/registry.rb', line 76

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

#find_processor(short) ⇒ Object



48
49
50
# File 'lib/relaton/registry.rb', line 48

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

#find_processor_by_dataset(dataset) ⇒ Relaton::Processor?

Search a rpocessos by dataset name

Parameters:

  • dataset (String)

Returns:



64
65
66
# File 'lib/relaton/registry.rb', line 64

def find_processor_by_dataset(dataset)
  processors.values.detect { |p| p.datasets&.include? dataset }
end

#register(processor) ⇒ Object

Raises:



38
39
40
41
42
43
44
45
46
# File 'lib/relaton/registry.rb', line 38

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

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

  Util.log("[relaton] processor \"#{p.short}\" registered", :debug)
  processors[p.short] = p
end

#register_gemsObject



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

def register_gems
  # Util.log("[relaton] Info: detecting backends:", :info)

  SUPPORTED_GEMS.each do |b|
    require b
    require "#{b}/processor"
    register Kernel.const_get "#{camel_case(b)}::Processor"
  rescue LoadError => e
    Util.log("[relaton] Error: backend #{b} not present", :error)
    Util.log("[relaton] Error: #{e.message}", :error)
    Util.log("[relaton] Error: #{e.backtrace.join "\n"}", :error)
  end
end

#supported_processorsArray<Symbol>

Returns:

  • (Array<Symbol>)


53
54
55
# File 'lib/relaton/registry.rb', line 53

def supported_processors
  processors.keys
end