rom-http 0.1.1 → 0.1.2
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/.rubocop_todo.yml +2 -2
- data/CHANGELOG.md +7 -0
- data/lib/rom/http/dataset.rb +22 -1
- data/lib/rom/http/relation.rb +1 -1
- data/lib/rom/http/support/transformations.rb +17 -0
- data/lib/rom/http/version.rb +1 -1
- data/spec/integration/abstract/commands/create_spec.rb +2 -2
- data/spec/integration/abstract/commands/delete_spec.rb +2 -2
- data/spec/integration/abstract/commands/update_spec.rb +2 -2
- data/spec/integration/abstract/relation_spec.rb +2 -2
- data/spec/shared/setup.rb +2 -2
- data/spec/unit/rom/http/dataset_spec.rb +52 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2ce3a61436daffaff61852afe728b5850da68b1b
|
4
|
+
data.tar.gz: 8bc48f9985acd7b96d464df0d10c8c8976cc27c8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 66e218d1b3750f3cab5e00fba20113843beca95aa2728a06ea71dad2c5a0a132369a0797ac09f1ecb751ebed66a1674e773f8042fcbbd88537bdec68e49567f1
|
7
|
+
data.tar.gz: f72e94b554cec39f994d9bf85e6054906eebc8dc28f0d615f43130c764dc592bade46fe3f7cbe8530744ad2243be3b19c8f2afc950dde0a78c5a5db20a0cd870
|
data/.rubocop_todo.yml
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# This configuration was generated by
|
2
2
|
# `rubocop --auto-gen-config`
|
3
|
-
# on 2015-09-
|
3
|
+
# on 2015-09-16 21:35:53 +0100 using RuboCop version 0.34.1.
|
4
4
|
# The point is for the user to remove these configuration records
|
5
5
|
# one by one as the offenses are removed from the code base.
|
6
6
|
# Note that changes in the inspected code, or installation of new
|
@@ -9,4 +9,4 @@
|
|
9
9
|
# Offense count: 1
|
10
10
|
# Configuration parameters: CountComments.
|
11
11
|
Metrics/ClassLength:
|
12
|
-
Max:
|
12
|
+
Max: 118
|
data/CHANGELOG.md
CHANGED
data/lib/rom/http/dataset.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'rom/http/support/transformations'
|
2
|
+
|
1
3
|
module ROM
|
2
4
|
module HTTP
|
3
5
|
class Dataset
|
@@ -7,6 +9,7 @@ module ROM
|
|
7
9
|
|
8
10
|
attr_reader :config
|
9
11
|
|
12
|
+
option :projections, type: ::Array, default: [], reader: true
|
10
13
|
option :request_method, type: ::Symbol, default: :get, reader: true
|
11
14
|
option :path, type: ::String, default: ''
|
12
15
|
option :params, type: ::Hash, default: {}, reader: true
|
@@ -61,6 +64,14 @@ module ROM
|
|
61
64
|
__new__(config, options.merge(opts))
|
62
65
|
end
|
63
66
|
|
67
|
+
def project(*args)
|
68
|
+
projections = args.first.is_a?(::Array) ? args.first : args
|
69
|
+
|
70
|
+
with_options(
|
71
|
+
projections: (self.projections + projections)
|
72
|
+
)
|
73
|
+
end
|
74
|
+
|
64
75
|
def with_path(path)
|
65
76
|
with_options(path: path)
|
66
77
|
end
|
@@ -103,7 +114,9 @@ module ROM
|
|
103
114
|
end
|
104
115
|
|
105
116
|
def response
|
106
|
-
|
117
|
+
response_transformer.call(
|
118
|
+
response_handler.call(request_handler.call(self), self)
|
119
|
+
)
|
107
120
|
end
|
108
121
|
|
109
122
|
private
|
@@ -128,6 +141,14 @@ module ROM
|
|
128
141
|
self.class.default_request_handler
|
129
142
|
end
|
130
143
|
|
144
|
+
def response_transformer
|
145
|
+
if projections.empty?
|
146
|
+
ROM::HTTP::Support::Transformations[:noop]
|
147
|
+
else
|
148
|
+
ROM::HTTP::Support::Transformations[:project, projections]
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
131
152
|
def __new__(*args, &block)
|
132
153
|
self.class.new(*args, &block)
|
133
154
|
end
|
data/lib/rom/http/relation.rb
CHANGED
@@ -0,0 +1,17 @@
|
|
1
|
+
module ROM
|
2
|
+
module HTTP
|
3
|
+
module Support
|
4
|
+
class Transformations
|
5
|
+
extend Transproc::Registry
|
6
|
+
|
7
|
+
uses :map_array, from: ::Transproc::ArrayTransformations
|
8
|
+
uses :accept_keys, from: ::Transproc::HashTransformations
|
9
|
+
import :identity, from: ::Transproc::Coercions, as: :noop
|
10
|
+
|
11
|
+
def self.project(value, projections)
|
12
|
+
t(:map_array, t(:accept_keys, projections)).call(value)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/rom/http/version.rb
CHANGED
@@ -3,8 +3,8 @@ RSpec.describe ROM::HTTP::Commands::Create do
|
|
3
3
|
let(:headers) { { accept: 'application/json' } }
|
4
4
|
let(:rom) { ROM::Environment.new }
|
5
5
|
let(:container) { rom.finalize.env }
|
6
|
-
let(:request_handler) { double(Proc) }
|
7
|
-
let(:response_handler) { double(Proc) }
|
6
|
+
let(:request_handler) { double(Proc, freeze: self) }
|
7
|
+
let(:response_handler) { double(Proc, freeze: self) }
|
8
8
|
let(:relation) do
|
9
9
|
Class.new(ROM::HTTP::Relation) do
|
10
10
|
dataset :users
|
@@ -3,8 +3,8 @@ RSpec.describe ROM::HTTP::Commands::Delete do
|
|
3
3
|
let(:headers) { { accept: 'application/json' } }
|
4
4
|
let(:rom) { ROM::Environment.new }
|
5
5
|
let(:container) { rom.finalize.env }
|
6
|
-
let(:request_handler) { double(Proc) }
|
7
|
-
let(:response_handler) { double(Proc) }
|
6
|
+
let(:request_handler) { double(Proc, freeze: self) }
|
7
|
+
let(:response_handler) { double(Proc, freeze: self) }
|
8
8
|
let(:relation) do
|
9
9
|
Class.new(ROM::HTTP::Relation) do
|
10
10
|
dataset :users
|
@@ -3,8 +3,8 @@ RSpec.describe ROM::HTTP::Commands::Update do
|
|
3
3
|
let(:headers) { { accept: 'application/json' } }
|
4
4
|
let(:rom) { ROM::Environment.new }
|
5
5
|
let(:container) { rom.finalize.env }
|
6
|
-
let(:request_handler) { double(Proc) }
|
7
|
-
let(:response_handler) { double(Proc) }
|
6
|
+
let(:request_handler) { double(Proc, freeze: self) }
|
7
|
+
let(:response_handler) { double(Proc, freeze: self) }
|
8
8
|
let(:relation) do
|
9
9
|
Class.new(ROM::HTTP::Relation) do
|
10
10
|
dataset :users
|
@@ -3,8 +3,8 @@ RSpec.describe ROM::HTTP::Relation do
|
|
3
3
|
let(:headers) { { accept: 'application/json' } }
|
4
4
|
let(:rom) { ROM::Environment.new }
|
5
5
|
let(:container) { rom.finalize.env }
|
6
|
-
let(:request_handler) { double(Proc) }
|
7
|
-
let(:response_handler) { double(Proc) }
|
6
|
+
let(:request_handler) { double(Proc, freeze: self) }
|
7
|
+
let(:response_handler) { double(Proc, freeze: self) }
|
8
8
|
let(:relation) do
|
9
9
|
Class.new(ROM::HTTP::Relation) do
|
10
10
|
dataset :users
|
data/spec/shared/setup.rb
CHANGED
@@ -9,6 +9,6 @@ RSpec.shared_context 'setup' do
|
|
9
9
|
)
|
10
10
|
end
|
11
11
|
let(:rom) { setup.finalize }
|
12
|
-
let(:request_handler) { double(Proc) }
|
13
|
-
let(:response_handler) { double(Proc) }
|
12
|
+
let(:request_handler) { double(Proc, freeze: self) }
|
13
|
+
let(:response_handler) { double(Proc, freeze: self) }
|
14
14
|
end
|
@@ -39,6 +39,7 @@ RSpec.describe ROM::HTTP::Dataset do
|
|
39
39
|
is_expected.to eq(
|
40
40
|
request_method: :put,
|
41
41
|
path: '',
|
42
|
+
projections: [],
|
42
43
|
params: {},
|
43
44
|
headers: {
|
44
45
|
'Accept' => 'application/json'
|
@@ -52,6 +53,7 @@ RSpec.describe ROM::HTTP::Dataset do
|
|
52
53
|
is_expected.to eq(
|
53
54
|
request_method: :get,
|
54
55
|
path: '',
|
56
|
+
projections: [],
|
55
57
|
params: {},
|
56
58
|
headers: {}
|
57
59
|
)
|
@@ -274,6 +276,7 @@ RSpec.describe ROM::HTTP::Dataset do
|
|
274
276
|
expect(new_dataset.options).to eq(
|
275
277
|
request_method: :get,
|
276
278
|
path: '',
|
279
|
+
projections: [],
|
277
280
|
params: {},
|
278
281
|
headers: headers
|
279
282
|
)
|
@@ -328,6 +331,7 @@ RSpec.describe ROM::HTTP::Dataset do
|
|
328
331
|
expect(new_dataset.options).to eq(
|
329
332
|
request_method: :get,
|
330
333
|
path: '',
|
334
|
+
projections: [],
|
331
335
|
params: {
|
332
336
|
name: name
|
333
337
|
},
|
@@ -338,6 +342,54 @@ RSpec.describe ROM::HTTP::Dataset do
|
|
338
342
|
it { is_expected.to be_a(ROM::HTTP::Dataset) }
|
339
343
|
end
|
340
344
|
|
345
|
+
describe '#project' do
|
346
|
+
let(:data) do
|
347
|
+
[
|
348
|
+
{ id: 1, name: 'John', email: 'john@hotmail.com' },
|
349
|
+
{ id: 2, name: 'Jill', email: 'jill@hotmail.com' }
|
350
|
+
]
|
351
|
+
end
|
352
|
+
|
353
|
+
before do
|
354
|
+
allow(request_handler).to receive(:call)
|
355
|
+
allow(response_handler).to receive(:call).and_return(data)
|
356
|
+
end
|
357
|
+
|
358
|
+
subject! { dataset.project(*projections).to_a }
|
359
|
+
|
360
|
+
context 'with projections' do
|
361
|
+
context 'with a list of arguments' do
|
362
|
+
let(:projections) { [:id, :name] }
|
363
|
+
|
364
|
+
it 'applies the projections to the result set' do
|
365
|
+
is_expected.to match_array([
|
366
|
+
{ id: 1, name: 'John' },
|
367
|
+
{ id: 2, name: 'Jill' }
|
368
|
+
])
|
369
|
+
end
|
370
|
+
end
|
371
|
+
|
372
|
+
context 'with a single array argument' do
|
373
|
+
let(:projections) { [[:id, :name]] }
|
374
|
+
|
375
|
+
it 'applies the projections to the result set' do
|
376
|
+
is_expected.to match_array([
|
377
|
+
{ id: 1, name: 'John' },
|
378
|
+
{ id: 2, name: 'Jill' }
|
379
|
+
])
|
380
|
+
end
|
381
|
+
end
|
382
|
+
end
|
383
|
+
|
384
|
+
context 'without projections' do
|
385
|
+
let(:projections) { [] }
|
386
|
+
|
387
|
+
it 'returns the original data' do
|
388
|
+
is_expected.to match_array(data)
|
389
|
+
end
|
390
|
+
end
|
391
|
+
end
|
392
|
+
|
341
393
|
describe '#with_path' do
|
342
394
|
let(:path) { '/users/tasks' }
|
343
395
|
let(:new_dataset) { double(ROM::HTTP::Dataset) }
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rom-http
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Piotr Solnica
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-09-
|
12
|
+
date: 2015-09-16 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rom
|
@@ -135,6 +135,7 @@ files:
|
|
135
135
|
- lib/rom/http/error.rb
|
136
136
|
- lib/rom/http/gateway.rb
|
137
137
|
- lib/rom/http/relation.rb
|
138
|
+
- lib/rom/http/support/transformations.rb
|
138
139
|
- lib/rom/http/version.rb
|
139
140
|
- rakelib/rubocop.rake
|
140
141
|
- rom-http.gemspec
|