Class: Hws::Instruments::Models::InstrumentConfig

Inherits:
Base
  • Object
show all
Defined in:
lib/hws-instruments/models/instrument_config.rb

Overview

:nodoc:

Constant Summary collapse

MANDATORY_FIELDS =
%I[connector_id executor_id connector_credentials connector_actions].freeze

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#set_uuid

Class Method Details

.create_config(params) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/hws-instruments/models/instrument_config.rb', line 10

def self.create_config(params)
  raise 'Missing mandatory param' unless params.keys.all? { |x| MANDATORY_FIELDS.include?(x) }

  begin
    unless Object.const_defined?(params[:connector_id])
      raise Hws::Instruments::Exceptions::UnknownEntityError, "Connector not found: #{params[:connector_id]}"
    end
  rescue NameError => _e
    raise Hws::Instruments::Exceptions::UnknownEntityError, "Connector not found: #{params[:connector_id]}"
  end

  begin
    unless Object.const_defined?(params[:executor_id])
      raise Hws::Instruments::Exceptions::UnknownEntityError, "Executor not found: #{params[:executor_id]}"
    end
  rescue NameError => _e
    raise Hws::Instruments::Exceptions::UnknownEntityError, "Executor not found: #{params[:executor_id]}"
  end

  self.create(params)
end

Instance Method Details

#connectorObject



37
38
39
40
41
42
43
# File 'lib/hws-instruments/models/instrument_config.rb', line 37

def connector
  unless Object.const_defined?(self.connector_id)
    raise "Invalid connector configuration. conn_id: #{self.connector_id}"
  end

  self.connector_id.constantize.new(self.connector_credentials)
end

#create_instrument(_external_identifier = nil) ⇒ Object



32
33
34
35
# File 'lib/hws-instruments/models/instrument_config.rb', line 32

def create_instrument(_external_identifier = nil)
  instrument = self.instruments.create
  instrument.execute(action: :create)
end

#executorObject



45
46
47
48
49
# File 'lib/hws-instruments/models/instrument_config.rb', line 45

def executor
  raise "Invalid instrument executor with id: #{self.executor_id}" unless Object.const_defined?(self.executor_id)

  self.executor_id.constantize
end