Class: Apiwork::Adapter::Capability::Transformer::Response::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/apiwork/adapter/capability/transformer/response/base.rb

Overview

Base class for response transformers.

Response transformers modify responses before they are returned. Register transformers in capabilities using Base.response_transformer.

Examples:

Add generated_at to response

class MyResponseTransformer < Capability::Transformer::Response::Base
  def transform
    response.transform_body { |body| body.merge(generated_at: Time.zone.now) }
  end
end

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ Base

Returns a new instance of Base.



29
30
31
# File 'lib/apiwork/adapter/capability/transformer/response/base.rb', line 29

def initialize(response)
  @response = response
end

Instance Attribute Details

#responseObject (readonly)



21
22
23
# File 'lib/apiwork/adapter/capability/transformer/response/base.rb', line 21

def response
  @response
end

Class Method Details

.transform(response) ⇒ Object



24
25
26
# File 'lib/apiwork/adapter/capability/transformer/response/base.rb', line 24

def transform(response)
  new(response).transform
end

Instance Method Details

#transformResponse

Transforms the response.

Returns:

Raises:

  • (NotImplementedError)


37
38
39
# File 'lib/apiwork/adapter/capability/transformer/response/base.rb', line 37

def transform
  raise NotImplementedError
end