Class: Relaton::Registry
- Inherits:
-
Object
- Object
- Relaton::Registry
- 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 relaton_doi relaton_jis relaton_xsf ].freeze
Instance Attribute Summary collapse
-
#processors ⇒ Object
readonly
Returns the value of attribute processors.
Instance Method Summary collapse
-
#by_type(type) ⇒ RelatonIso::Processor, ...
Find processor by type.
-
#class_by_ref(ref) ⇒ Symbol?
Find processor by refernce or prefix.
- #find_processor(short) ⇒ Object
-
#find_processor_by_dataset(dataset) ⇒ Relaton::Processor?
Search a rpocessos by dataset name.
-
#initialize ⇒ Registry
constructor
A new instance of Registry.
-
#processor_by_ref(ref) ⇒ Relaton::Processor
Find processor by reference or prefix.
- #register(processor) ⇒ Object
- #register_gems ⇒ Object
- #supported_processors ⇒ Array<Symbol>
Constructor Details
#initialize ⇒ Registry
Returns a new instance of Registry.
20 21 22 23 |
# File 'lib/relaton/registry.rb', line 20 def initialize @processors = {} register_gems end |
Instance Attribute Details
#processors ⇒ Object (readonly)
Returns the value of attribute processors.
18 19 20 |
# File 'lib/relaton/registry.rb', line 18 def processors @processors end |
Instance Method Details
#by_type(type) ⇒ RelatonIso::Processor, ...
Find processor by type
77 78 79 |
# File 'lib/relaton/registry.rb', line 77 def by_type(type) processors.values.detect { |v| v.prefix == type&.upcase } end |
#class_by_ref(ref) ⇒ Symbol?
Find processor by refernce or prefix
99 100 101 102 103 104 105 106 107 |
# File 'lib/relaton/registry.rb', line 99 def class_by_ref(ref) @processors.each do |class_name, processor| return class_name if /^(urn:)?#{processor.prefix}(?!\w)/i.match?(ref) || processor.defaultprefix.match(ref) end Util.log <<~WARN, :info [relaton] #{ref} does not have a recognised prefix WARN end |
#find_processor(short) ⇒ Object
49 50 51 |
# File 'lib/relaton/registry.rb', line 49 def find_processor(short) processors[short.to_sym] end |
#find_processor_by_dataset(dataset) ⇒ Relaton::Processor?
Search a rpocessos by dataset name
65 66 67 |
# File 'lib/relaton/registry.rb', line 65 def find_processor_by_dataset(dataset) processors.values.detect { |p| p.datasets&.include? dataset } end |
#processor_by_ref(ref) ⇒ Relaton::Processor
Find processor by reference or prefix
88 89 90 |
# File 'lib/relaton/registry.rb', line 88 def processor_by_ref(ref) @processors[class_by_ref(ref)] end |
#register(processor) ⇒ Object
39 40 41 42 43 44 45 46 47 |
# File 'lib/relaton/registry.rb', line 39 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_gems ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/relaton/registry.rb', line 25 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.}", :error) Util.log("[relaton] Error: #{e.backtrace.join "\n"}", :error) end end |
#supported_processors ⇒ Array<Symbol>
54 55 56 |
# File 'lib/relaton/registry.rb', line 54 def supported_processors processors.keys end |