Class: ShotgridApiRuby::Entity

Inherits:
T::Struct
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/shotgrid_api_ruby/entity.rb

Overview

Represent each entity returned by Shotgrid

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type:, attributes:, relationships:, id:, links:) ⇒ void

Parameters:

  • type (String)

    .new(:type, :attributes, :relationships, :id, :links) do

  • attributes (OpenStruct)
  • relationships (Hash{T.untyped => T.untyped})
  • id (Integer)
  • links (Hash{String => String})


# File ''

const :type, String
const :attributes, OpenStruct
const :relationships, T::Hash[T.untyped, T.untyped]
const :id, Integer
const :links, T::Hash[String, String]

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ T.untyped

Parameters:

  • name (String, Symbol)
  • args (T.untyped)
  • block (T.untyped)

Returns:

  • (T.untyped)


20
21
22
23
24
25
26
27
# File 'lib/shotgrid_api_ruby/entity.rb', line 20

def method_missing(name, *args, &block)
  if attributes.respond_to?(name)
    define_singleton_method(name) { attributes.public_send(name) }
    public_send(name)
  else
    super
  end
end

Instance Attribute Details

#attributesOpenStruct (readonly)

Returns the value of attribute `attributes`.

Returns:

  • (OpenStruct)


# File ''

const :attributes, OpenStruct

#idInteger (readonly)

Returns the value of attribute `id`.

Returns:

  • (Integer)


# File ''

const :id, Integer

Returns the value of attribute `links`.

Returns:

  • (Hash{String => String})


# File ''

const :links, T::Hash[String, String]

#relationshipsHash{T.untyped => T.untyped} (readonly)

Returns the value of attribute `relationships`.

Returns:

  • (Hash{T.untyped => T.untyped})


# File ''

const :relationships, T::Hash[T.untyped, T.untyped]

#typeString (readonly)

.new(:type, :attributes, :relationships, :id, :links) do

Returns:

  • (String)


# File ''

const :type, String

Instance Method Details

#respond_to_missing?(name, _private_methods = false) ⇒ Boolean

Parameters:

  • name (String, Symbol)
  • _private_methods (T.untyped) (defaults to: false)

Returns:

  • (Boolean)


33
34
35
# File 'lib/shotgrid_api_ruby/entity.rb', line 33

def respond_to_missing?(name, _private_methods = false)
  attributes.respond_to?(name) || super
end