Class: LittleGhost::Models::Target
- Inherits:
-
Data
- Object
- Data
- LittleGhost::Models::Target
- Defined in:
- lib/little_ghost/models/target.rb
Overview
Identifies one physical model through a named provider connection.
Instance Attribute Summary collapse
-
#model_id ⇒ Object
readonly
Returns the value of attribute model_id.
-
#provider ⇒ Object
readonly
Returns the value of attribute provider.
Class Method Summary collapse
-
.parse(value) ⇒ Object
Parses
provider:model-id, splitting only at the first colon.
Instance Method Summary collapse
-
#initialize(provider:, model_id:) ⇒ Target
constructor
A new instance of Target.
- #to_s ⇒ Object
Constructor Details
#initialize(provider:, model_id:) ⇒ Target
Returns a new instance of Target.
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_id ⇒ Object (readonly)
Returns the value of attribute model_id
6 7 8 |
# File 'lib/little_ghost/models/target.rb', line 6 def model_id @model_id end |
#provider ⇒ Object (readonly)
Returns the value of attribute 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.
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_s ⇒ Object
26 |
# File 'lib/little_ghost/models/target.rb', line 26 def to_s = "#{provider}:#{model_id}" |