rom-http 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0a5d2946beb3f147e7b8e09a390d1db24006b131
4
- data.tar.gz: 3780c786affbb10b47987b63a7344e6765ab4964
3
+ metadata.gz: 2ce3a61436daffaff61852afe728b5850da68b1b
4
+ data.tar.gz: 8bc48f9985acd7b96d464df0d10c8c8976cc27c8
5
5
  SHA512:
6
- metadata.gz: 1d12b8a1740657967ed774d8bfd61af0f738123ca92e857a7eeb5a82deb53c4c1defeca7229216e636abbb3f3c3f4ce51de211b2dd9bc2822f41f597ec2f6f5f
7
- data.tar.gz: 2b39120ff86cf082e57395c2b188b40acd72e746d5d26a567b4d89bad4e7cb8dacd518889450d208b7342956ce378ffb0519af828f60bf2236e115f612523cc7
6
+ metadata.gz: 66e218d1b3750f3cab5e00fba20113843beca95aa2728a06ea71dad2c5a0a132369a0797ac09f1ecb751ebed66a1674e773f8042fcbbd88537bdec68e49567f1
7
+ data.tar.gz: f72e94b554cec39f994d9bf85e6054906eebc8dc28f0d615f43130c764dc592bade46fe3f7cbe8530744ad2243be3b19c8f2afc950dde0a78c5a5db20a0cd870
@@ -1,6 +1,6 @@
1
1
  # This configuration was generated by
2
2
  # `rubocop --auto-gen-config`
3
- # on 2015-09-03 20:59:57 +0100 using RuboCop version 0.33.0.
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: 104
12
+ Max: 118
@@ -1,3 +1,10 @@
1
+ # v0.1.2 2015-09-16
2
+ ### Added
3
+
4
+ - Projections (`container.relation(:users).project(:id, :name)`) (AMHOL)
5
+
6
+ [Compare v0.1.1...v0.1.2](https://github.com/rom-rb/rom-http/compare/v0.1.1...v0.1.2)
7
+
1
8
  # v0.1.1 2015-09-03
2
9
  ### Added
3
10
 
@@ -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
- response_handler.call(request_handler.call(self), self)
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
@@ -6,7 +6,7 @@ module ROM
6
6
  adapter :http
7
7
 
8
8
  forward :with_request_method, :with_path, :append_path, :with_options,
9
- :with_params, :clear_params
9
+ :with_params, :clear_params, :project
10
10
 
11
11
  def insert(*args)
12
12
  dataset.insert(*args)
@@ -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
@@ -1,5 +1,5 @@
1
1
  module ROM
2
2
  module HTTP
3
- VERSION = '0.1.1'.freeze
3
+ VERSION = '0.1.2'.freeze
4
4
  end
5
5
  end
@@ -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
@@ -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.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-03 00:00:00.000000000 Z
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