materialist 3.5.0 → 3.6.0
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/README.md +20 -0
- data/RELEASE_NOTES.md +5 -1
- data/lib/materialist/materializer/internals/dsl.rb +6 -2
- data/lib/materialist/materializer/internals/field_mapping.rb +3 -2
- data/lib/materialist/version.rb +1 -1
- data/spec/materialist/materializer/internals/field_mapping_spec.rb +36 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dc140c911742867585c275c7b87a08cce340b165
|
4
|
+
data.tar.gz: dd08e90c55127a4b8375f859613ec73cda95970d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
@@ -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(
|
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
|
data/lib/materialist/version.rb
CHANGED
@@ -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.
|
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:
|
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
|