Class: Mosaic::Sdk::Models::Base::Instance Abstract

Inherits:
Object
  • Object
show all
Defined in:
lib/mosaic/sdk/models/base.rb

Overview

This class is abstract.

Subclass and implement #uri

Abstract class representing an individual resource instance.

Handles lazy loading of data and associations to other resource types via the Instance.association class method.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, data: nil, **extra) ⇒ Instance

Initializes a resource instance.

Parameters:

  • id (String, Integer)

    the resource identifier

  • data (Hash, nil) (defaults to: nil)

    pre-loaded data (optional)

  • extra (Hash)

    additional context (e.g. parent IDs)

Class Method Details

.association(name) ⇒ void

This method returns an undefined value.

Declares an association to another resource type.

Dynamically defines an instance method that allows navigating to an associated collection or a specific instance.

Examples:

Declare an association

class Dna::Instance < Base::Instance
  association :clones
end

Use an association

dna = Mosaic::Sdk.Dna(42)
dna.clones        # => Clone (collection)
dna.clones(7)     # => Clone::Instance (specific instance)

Parameters:

  • name (Symbol)

    the association name (plural, e.g. :clones)

Instance Method Details

#dataHash

Returns the resource data, loading it from the API if needed (lazy loading).

Returns:

  • (Hash)

    the resource data