Class: LittleGhost::Models::Target

Inherits:
Data
  • Object
show all
Defined in:
lib/little_ghost/models/target.rb

Overview

Identifies one physical model through a named provider connection.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(provider:, model_id:) ⇒ Target

Returns a new instance of Target.

Raises:



7
8
9
10
11
12
13
14
# File 'lib/little_ghost/models/target.rb', line 7

def initialize(provider:, model_id:)
  provider = provider.to_s.strip
  model_id = model_id.to_s.strip
  raise ConfigurationError, "Model target provider is required" if provider.empty?
  raise ConfigurationError, "Model target model ID is required" if model_id.empty?

  super(provider: provider.freeze, model_id: model_id.freeze)
end

Instance Attribute Details

#model_idObject (readonly)

Returns the value of attribute model_id

Returns:

  • (Object)

    the current value of model_id



6
7
8
# File 'lib/little_ghost/models/target.rb', line 6

def model_id
  @model_id
end

#providerObject (readonly)

Returns the value of attribute provider

Returns:

  • (Object)

    the current value of provider



6
7
8
# File 'lib/little_ghost/models/target.rb', line 6

def provider
  @provider
end

Class Method Details

.parse(value) ⇒ Object

Parses provider:model-id, splitting only at the first colon.

Raises:



17
18
19
20
21
22
23
24
# File 'lib/little_ghost/models/target.rb', line 17

def self.parse(value)
  return value if value.is_a?(self)

  provider, separator, model_id = value.to_s.partition(":")
  raise ConfigurationError, "Model target must use provider:model-id" if separator.empty?

  new(provider:, model_id:)
end

Instance Method Details

#to_sObject



26
# File 'lib/little_ghost/models/target.rb', line 26

def to_s = "#{provider}:#{model_id}"