Class: Apiwork::Adapter::Wrapper::Collection::Default

Inherits:
Base
  • Object
show all
Defined in:
lib/apiwork/adapter/wrapper/collection/default.rb

Overview

Default collection response wrapper.

Wraps serialized records under a pluralized root key with optional meta and capability metadata.

Examples:

Configuration

class MyAdapter < Adapter::Base
  collection_wrapper Wrapper::Collection::Default
end

Output

{
  "invoices": [
    { "id": 1, "number": "INV-001" },
    { "id": 2, "number": "INV-002" }
  ],
  "meta": { ... },
  "pagination": { "current": 1, "total": 5 }
}

Instance Attribute Summary

Attributes inherited from Base

#meta, #metadata, #root_key

Attributes inherited from Base

#data

Instance Method Summary collapse

Methods inherited from Base

#initialize

Methods inherited from Base

#initialize, shape, wrap

Constructor Details

This class inherits a constructor from Apiwork::Adapter::Wrapper::Collection::Base

Instance Method Details

#wrapObject



36
37
38
39
40
41
42
# File 'lib/apiwork/adapter/wrapper/collection/default.rb', line 36

def wrap
  {
    root_key.plural.to_sym => data,
    meta: meta.presence,
    **,
  }.compact
end