Class: Apiwork::Adapter::Wrapper::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/apiwork/adapter/wrapper/base.rb

Direct Known Subclasses

Collection::Base, Error::Base, Member::Base

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ Base

Returns a new instance of Base.



56
57
58
# File 'lib/apiwork/adapter/wrapper/base.rb', line 56

def initialize(data)
  @data = data
end

Instance Attribute Details

#dataHash (readonly)

The data for this wrapper.

Returns:

  • (Hash)


14
15
16
# File 'lib/apiwork/adapter/wrapper/base.rb', line 14

def data
  @data
end

Class Method Details

.shape(klass_or_callable = nil) { ... } ⇒ Class<Shape>?

Defines the response shape for contract generation.

Parameters:

  • klass_or_callable (Class<Shape>, Proc, nil) (defaults to: nil)

    (nil) A Shape subclass or callable.

Yields:

  • block that defines the shape using the Shape DSL

Returns:



24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/apiwork/adapter/wrapper/base.rb', line 24

def shape(klass_or_callable = nil, &block)
  callable = block || klass_or_callable

  if callable
    self.shape_class = if callable.respond_to?(:call)
                         wrap_callable(callable)
                       else
                         callable
                       end
  end

  shape_class
end

.wrapObject



38
39
40
# File 'lib/apiwork/adapter/wrapper/base.rb', line 38

def wrap(...)
  new(...).wrap
end

Instance Method Details

#wrapHash

Transforms the data into the final response format.

Returns:

  • (Hash)

Raises:

  • (NotImplementedError)


64
65
66
# File 'lib/apiwork/adapter/wrapper/base.rb', line 64

def wrap
  raise NotImplementedError
end