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 ].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.
- #find_processor(short) ⇒ Object
-
#initialize ⇒ Registry
constructor
A new instance of Registry.
- #register(processor) ⇒ Object
- #register_gems ⇒ Object
- #supported_processors ⇒ Array<Symbol>
Constructor Details
#initialize ⇒ Registry
Returns a new instance of Registry.
18 19 20 21 |
# File 'lib/relaton/registry.rb', line 18 def initialize @processors = {} register_gems end |
Instance Attribute Details
#processors ⇒ Object (readonly)
Returns the value of attribute processors.
16 17 18 |
# File 'lib/relaton/registry.rb', line 16 def processors @processors end |
Instance Method Details
#by_type(type) ⇒ RelatonIso::Processor, ...
Find processor by type
64 65 66 |
# File 'lib/relaton/registry.rb', line 64 def by_type(type) processors.values.detect { |v| v.prefix == type&.upcase } end |
#find_processor(short) ⇒ Object
47 48 49 |
# File 'lib/relaton/registry.rb', line 47 def find_processor(short) processors[short.to_sym] end |
#register(processor) ⇒ Object
37 38 39 40 41 42 43 44 45 |
# File 'lib/relaton/registry.rb', line 37 def register(processor) raise Error unless processor < ::Relaton::Processor p = processor.new return if processors[p.short] Util.log("[relaton] processor \"#{p.short}\" registered", :info) processors[p.short] = p end |
#register_gems ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/relaton/registry.rb', line 23 def register_gems Util.log("[relaton] Info: detecting backends:", :info) SUPPORTED_GEMS.each do |b| begin require b require "#{b}/processor" register Kernel.const_get "#{camel_case(b)}::Processor" rescue LoadError Util.log("[relaton] Error: backend #{b} not present", :error) end end end |
#supported_processors ⇒ Array<Symbol>
52 53 54 |
# File 'lib/relaton/registry.rb', line 52 def supported_processors processors.keys end |