rom-http 0.5.0 → 0.6.0.rc1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.travis.yml +8 -11
- data/CHANGELOG.md +13 -0
- data/README.md +32 -20
- data/examples/repository_with_combine.rb +154 -0
- data/lib/rom/http/commands/create.rb +0 -1
- data/lib/rom/http/commands/update.rb +0 -1
- data/lib/rom/http/dataset.rb +39 -61
- data/lib/rom/http/error.rb +1 -0
- data/lib/rom/http/gateway.rb +2 -2
- data/lib/rom/http/relation.rb +87 -10
- data/lib/rom/http/transformer.rb +16 -0
- data/lib/rom/http/version.rb +1 -1
- data/rom-http.gemspec +5 -4
- data/spec/integration/abstract/commands/create_spec.rb +12 -4
- data/spec/integration/abstract/commands/delete_spec.rb +7 -1
- data/spec/integration/abstract/commands/update_spec.rb +12 -4
- data/spec/integration/abstract/relation_spec.rb +4 -6
- data/spec/shared/users_and_tasks.rb +6 -2
- data/spec/spec_helper.rb +1 -0
- data/spec/unit/rom/http/dataset_spec.rb +80 -121
- data/spec/unit/rom/http/relation_spec.rb +260 -12
- metadata +40 -25
- data/lib/rom/http/dataset/response_transformers/schemad.rb +0 -30
- data/lib/rom/http/dataset/response_transformers/schemaless.rb +0 -25
- data/lib/rom/http/support/transformations.rb +0 -12
- data/spec/unit/rom/http/dataset/response_transformers/schemad_spec.rb +0 -45
- data/spec/unit/rom/http/dataset/response_transformers/schemaless_spec.rb +0 -39
@@ -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,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
|