Class: Apiwork::Adapter::Wrapper::Base
- Inherits:
-
Object
- Object
- Apiwork::Adapter::Wrapper::Base
- Defined in:
- lib/apiwork/adapter/wrapper/base.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#data ⇒ Hash
readonly
The data for this wrapper.
Class Method Summary collapse
-
.shape(klass_or_callable = nil) { ... } ⇒ Class<Shape>?
Defines the response shape for contract generation.
- .wrap ⇒ Object
Instance Method Summary collapse
-
#initialize(data) ⇒ Base
constructor
A new instance of Base.
-
#wrap ⇒ Hash
Transforms the data into the final response format.
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
#data ⇒ Hash (readonly)
The data for this wrapper.
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.
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 |
.wrap ⇒ Object
38 39 40 |
# File 'lib/apiwork/adapter/wrapper/base.rb', line 38 def wrap(...) new(...).wrap end |
Instance Method Details
#wrap ⇒ Hash
Transforms the data into the final response format.
64 65 66 |
# File 'lib/apiwork/adapter/wrapper/base.rb', line 64 def wrap raise NotImplementedError end |