Module: DurableHuggingfaceHub::Struct::Loadable

Defined in:
lib/durable_huggingface_hub/types.rb

Overview

Base class for data structures that can be loaded from JSON/Hash.

Provides convenient methods for creating instances from API responses.

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Struct

Creates an instance from a hash (typically from JSON parsing).

Parameters:

  • data (Hash)

    Data hash

Returns:



169
170
171
# File 'lib/durable_huggingface_hub/types.rb', line 169

def self.included(base)
  base.extend(ClassMethods)
end

Instance Method Details

#to_hHash

Converts the struct to a hash.

Returns:

  • (Hash)

    Hash representation



192
193
194
# File 'lib/durable_huggingface_hub/types.rb', line 192

def to_h
  attributes.to_h
end

#to_json(*args) ⇒ String

Converts the struct to JSON.

Returns:

  • (String)

    JSON representation



199
200
201
202
# File 'lib/durable_huggingface_hub/types.rb', line 199

def to_json(*args)
  require "json"
  to_h.to_json(*args)
end