Sha256: 1a539769bcc86c04fd20c556175035f43fa81b0d60709e24f07c744c99d9002b

Contents?: true

Size: 853 Bytes

Versions: 4

Compression:

Stored size: 853 Bytes

Contents

require 'rom/http/support/transformations'

module ROM
  module HTTP
    class Dataset
      module ResponseTransformers
        class Schemad
          attr_reader :schema

          def initialize(schema)
            @schema = schema
          end

          def call(response, dataset)
            t(:map_array,
              t(:accept_keys, projections(dataset.projections)) >> ->(tuple) { schema.apply(tuple) }
             ).call(response)
          end

          private

          def t(*args)
            ROM::HTTP::Support::Transformations[*args]
          end

          def projections(projections)
            if projections.empty?
              schema.attribute_names
            else
              projections.reject { |attr| !schema.attribute_names.include?(attr) }
            end
          end
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rom-http-0.4.0 lib/rom/http/dataset/response_transformers/schemad.rb
rom-http-0.3.0 lib/rom/http/dataset/response_transformers/schemad.rb
rom-http-0.2.0 lib/rom/http/dataset/response_transformers/schemad.rb
rom-http-0.2.0.beta1 lib/rom/http/dataset/response_transformers/schemad.rb