Class: ROM::HTTP::Dataset::ResponseTransformers::Schemad
- Inherits:
-
Object
- Object
- ROM::HTTP::Dataset::ResponseTransformers::Schemad
- Defined in:
- lib/rom/http/dataset/response_transformers/schemad.rb
Instance Attribute Summary collapse
- #schema ⇒ Object readonly
Instance Method Summary collapse
- #call(response, dataset) ⇒ Object
-
#initialize(schema) ⇒ Schemad
constructor
A new instance of Schemad.
Constructor Details
#initialize(schema) ⇒ Schemad
Returns a new instance of Schemad.
10 11 12 |
# File 'lib/rom/http/dataset/response_transformers/schemad.rb', line 10 def initialize(schema) @schema = Types::Hash.schema(schema) end |
Instance Attribute Details
#schema ⇒ Object (readonly)
8 9 10 |
# File 'lib/rom/http/dataset/response_transformers/schemad.rb', line 8 def schema @schema end |
Instance Method Details
#call(response, dataset) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/rom/http/dataset/response_transformers/schemad.rb', line 14 def call(response, dataset) projections = dataset.projections if projections.size > 0 && schema.member_types.keys != projections projected_schema = Types::Hash.schema( schema.member_types.select { |k, _| projections.include?(k) } ) projected_schema[response] else response.map { |tuple| schema[tuple] } end end |