materialist 3.5.0 → 3.6.0

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: ad5a7f5ef0961f9e8cf3317baaf07cbb53d8e021
4
- data.tar.gz: 394077c4817dd29106c78f02124f6c145ab6dafd
3
+ metadata.gz: dc140c911742867585c275c7b87a08cce340b165
4
+ data.tar.gz: dd08e90c55127a4b8375f859613ec73cda95970d
5
5
  SHA512:
6
- metadata.gz: 1fc7dd6e7563ec9205631a5f8520c6928b8ca10c269c3c8f74cb2093080e500878b8a5220ae5fabab1a985090d8f66ffcd55dac2fdaed4253a6de679601ade13
7
- data.tar.gz: 4d293933436137b9daf41d3de5117eeb707653d0ce73f7865356d5fe1bfad6b8354a4073ae1ecfeec3adae7ad1c4b7ad38a2713f6668ca7a7b9d77e956e1fcfa
6
+ metadata.gz: 4bcb195f30deff05ab9c83de55475473f8efee6a599cb694f47fdb55438b5374988a6f12872d5078af57c76c978d45208f0829a962b1d41d79f9ef1c824740eb
7
+ data.tar.gz: 0d15e15c152b85765a3dca6c96dbe28787e780a15b68c505cf4dfd6d0c4e1b732c17c64275794733a096790999e3a0d59be32ba9e48a8c7d374c5fd1b4c6e33b
data/README.md CHANGED
@@ -25,6 +25,20 @@ Then do
25
25
  bundle
26
26
  ```
27
27
 
28
+ ### Release
29
+
30
+ After merging all of your PRs:
31
+
32
+ 1. Bump the version in `lib/materialist/version.rb` -- let's say `x.y.z`
33
+ 1. Build the gem: `gem build materialist.gemspec`
34
+ 1. Push the gem: `gem push materialist-x.y.z.gem`
35
+ 1. Commit changes: `git commit -am "Bump version"`
36
+ 1. Create a tag: `git tag -a vx.y.z`
37
+ 1. Push changes: `git push origin master`
38
+ 1. Push the new: `git push origin --tags`
39
+
40
+ ## Usage
41
+
28
42
  ### Entity
29
43
 
30
44
  Your materialised entity need to have a **unique** `source_url` column, alongside any other field you wish to materialise.
@@ -183,6 +197,12 @@ Passing an optional block allows you to extract an identifier from the URL.
183
197
  #### `capture <key>, as: <column> (default: key)`
184
198
  describes mapping a resource key to a database column.
185
199
 
200
+ You can optionally provide a block for parsing the value:
201
+
202
+ ```ruby
203
+ capture(:location, as: :latitude) { |location| location[:latitude] }
204
+ ```
205
+
186
206
  #### `capture_link_href <key>, as: <column>`
187
207
  describes mapping a link href (as it appears on the hateous response) to a database column.
188
208
 
data/RELEASE_NOTES.md CHANGED
@@ -1,6 +1,10 @@
1
1
  ## Next
2
2
 
3
- _description of next release_
3
+ _list pending release notes here..._
4
+
5
+ ## 3.6.0
6
+
7
+ - Add support for parsing value when using `capture`
4
8
 
5
9
  ## 3.5.0
6
10
 
@@ -6,8 +6,12 @@ module Materialist
6
6
  __materialist_options[:links_to_materialize][key] = { topic: topic }
7
7
  end
8
8
 
9
- def capture(key, as: key)
10
- __materialist_dsl_mapping_stack.last << FieldMapping.new(key: key, as: as)
9
+ def capture(key, as: key, &value_parser_block)
10
+ __materialist_dsl_mapping_stack.last << FieldMapping.new(
11
+ key: key,
12
+ as: as,
13
+ value_parser: value_parser_block
14
+ )
11
15
  end
12
16
 
13
17
  def capture_link_href(key, as:, &url_parser_block)
@@ -2,13 +2,14 @@ module Materialist
2
2
  module Materializer
3
3
  module Internals
4
4
  class FieldMapping
5
- def initialize(key:, as: key)
5
+ def initialize(key:, as: key, value_parser: nil)
6
6
  @key = key
7
7
  @as = as
8
+ @value_parser = value_parser || ->value { value }
8
9
  end
9
10
 
10
11
  def map(resource)
11
- { @as => resource.dig(@key) }
12
+ { @as => @value_parser.call(resource.dig(@key)) }
12
13
  end
13
14
  end
14
15
  end
@@ -1,3 +1,3 @@
1
1
  module Materialist
2
- VERSION = '3.5.0'
2
+ VERSION = '3.6.0'
3
3
  end
@@ -0,0 +1,36 @@
1
+ require 'spec_helper'
2
+ require 'materialist/materializer/internals'
3
+
4
+ include Materialist::Materializer::Internals
5
+
6
+ RSpec.describe Materialist::Materializer::Internals::FieldMapping, type: :internals do
7
+ let(:instance) { described_class.new(key: key, as: as, value_parser: value_parser_block) }
8
+
9
+ describe '#map' do
10
+ let(:key) { :b }
11
+ let(:as) { :z }
12
+ let(:value_parser_block) { nil }
13
+ let(:resource) do
14
+ {
15
+ a: 1,
16
+ b: {
17
+ c: 2
18
+ }
19
+ }
20
+ end
21
+ let(:map) { instance.map(resource) }
22
+
23
+ context 'when no parse block is passed' do
24
+ let(:expected_result) { { z: { c: 2 } } }
25
+
26
+ it { expect(map).to eq(expected_result) }
27
+ end
28
+
29
+ context 'when a value parse block is passed' do
30
+ let(:value_parser_block) { ->value { value[:c] } }
31
+ let(:expected_result) { { z: 2 } }
32
+
33
+ it { expect(map).to eq(expected_result) }
34
+ end
35
+ end
36
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: materialist
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.5.0
4
+ version: 3.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mo Valipour
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-10-18 00:00:00.000000000 Z
11
+ date: 2019-06-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sidekiq
@@ -219,6 +219,7 @@ files:
219
219
  - materialist.gemspec
220
220
  - spec/materialist/event_handler_spec.rb
221
221
  - spec/materialist/materialized_record_spec.rb
222
+ - spec/materialist/materializer/internals/field_mapping_spec.rb
222
223
  - spec/materialist/materializer/internals/link_mapping_spec.rb
223
224
  - spec/materialist/materializer_factory_spec.rb
224
225
  - spec/materialist/materializer_spec.rb
@@ -254,6 +255,7 @@ summary: Utilities to materialize routemaster topics
254
255
  test_files:
255
256
  - spec/materialist/event_handler_spec.rb
256
257
  - spec/materialist/materialized_record_spec.rb
258
+ - spec/materialist/materializer/internals/field_mapping_spec.rb
257
259
  - spec/materialist/materializer/internals/link_mapping_spec.rb
258
260
  - spec/materialist/materializer_factory_spec.rb
259
261
  - spec/materialist/materializer_spec.rb