rom-http 0.5.0 → 0.6.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,30 +0,0 @@
1
- require 'rom/types'
2
-
3
- module ROM
4
- module HTTP
5
- class Dataset
6
- module ResponseTransformers
7
- class Schemad
8
- attr_reader :schema
9
-
10
- def initialize(schema)
11
- @schema = Types::Hash.schema(schema)
12
- end
13
-
14
- def call(response, dataset)
15
- projections = dataset.projections
16
-
17
- if projections.size > 0 && schema.member_types.keys != projections
18
- projected_schema = Types::Hash.schema(
19
- schema.member_types.select { |k, _| projections.include?(k) }
20
- )
21
- projected_schema[response]
22
- else
23
- response.map { |tuple| schema[tuple] }
24
- end
25
- end
26
- end
27
- end
28
- end
29
- end
30
- end
@@ -1,25 +0,0 @@
1
- require 'rom/http/support/transformations'
2
-
3
- module ROM
4
- module HTTP
5
- class Dataset
6
- module ResponseTransformers
7
- class Schemaless
8
- def call(response, dataset)
9
- if dataset.projections.empty?
10
- response
11
- else
12
- t(:map_array, t(:accept_keys, dataset.projections)).call(response)
13
- end
14
- end
15
-
16
- private
17
-
18
- def t(*args)
19
- ROM::HTTP::Support::Transformations[*args]
20
- end
21
- end
22
- end
23
- end
24
- end
25
- end
@@ -1,12 +0,0 @@
1
- module ROM
2
- module HTTP
3
- module Support
4
- class Transformations
5
- extend Transproc::Registry
6
-
7
- import :map_array, from: ::Transproc::ArrayTransformations
8
- import :accept_keys, from: ::Transproc::HashTransformations
9
- end
10
- end
11
- end
12
- end
@@ -1,45 +0,0 @@
1
- RSpec.describe ROM::HTTP::Dataset::ResponseTransformers::Schemad do
2
- subject(:transformer) { ROM::HTTP::Dataset::ResponseTransformers::Schemad.new(schema) }
3
-
4
- let(:schema) do
5
- { id: ROM::Types::Form::Int,
6
- name: ROM::Types::Strict::String,
7
- active: ROM::Types::Form::Bool }
8
- end
9
-
10
- describe '#call' do
11
- let(:response) do
12
- [
13
- {
14
- id: '1',
15
- name: 'Jill',
16
- email: 'jill@fakemail.com',
17
- active: 'true'
18
- }
19
- ]
20
- end
21
- let(:dataset) do
22
- double('ROM::HTTP::Dataset', projections: projections)
23
- end
24
-
25
- context 'with no projections' do
26
- let(:projections) { [] }
27
-
28
- it 'returns original tuples' do
29
- result = transformer.call(response, dataset)
30
-
31
- expect(result).to eql([id: 1, name: 'Jill', active: true])
32
- end
33
- end
34
-
35
- context 'with projections' do
36
- let(:projections) { [:id, :name, :active] }
37
-
38
- it 'returns projected relation tuples' do
39
- result = transformer.call(response, dataset)
40
-
41
- expect(result).to eql([id: 1, name: 'Jill', active: true])
42
- end
43
- end
44
- end
45
- end
@@ -1,39 +0,0 @@
1
- RSpec.describe ROM::HTTP::Dataset::ResponseTransformers::Schemaless do
2
- let(:transformer) { ROM::HTTP::Dataset::ResponseTransformers::Schemaless.new }
3
-
4
- describe '#call' do
5
- let(:response) do
6
- [
7
- {
8
- id: 1,
9
- name: 'Jill',
10
- email: 'jill@fakemail.com',
11
- active: true
12
- }
13
- ]
14
- end
15
- let(:dataset) do
16
- double('ROM::HTTP::Dataset', projections: projections)
17
- end
18
-
19
- subject! { transformer.call(response, dataset) }
20
-
21
- context 'with no projections' do
22
- let(:projections) { [] }
23
-
24
- it { is_expected.to eq(response) }
25
- end
26
-
27
- context 'with projections' do
28
- let(:projections) { [:id, :name, :active] }
29
-
30
- it do
31
- is_expected.to eq([
32
- id: 1,
33
- name: 'Jill',
34
- active: true
35
- ])
36
- end
37
- end
38
- end
39
- end