userializer 0.3.0 → 0.3.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/pull_request_template.md +28 -0
- data/.github/workflows/ci.yml +25 -0
- data/lib/userializer/attribute.rb +6 -1
- data/lib/userializer/base_serializer.rb +10 -4
- data/lib/userializer/has_many.rb +8 -2
- data/lib/userializer/has_one.rb +1 -1
- data/lib/userializer/version.rb +1 -1
- metadata +5 -4
- data/.circleci/config.yml +0 -18
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3cb0544f358655737798992e56aca1d2b2637508bf05c1968788832028fe2048
|
4
|
+
data.tar.gz: e5ad28d55ce77894acbf6763553f478e257375d3f2cbb11e2c267d35e14d1841
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 59bcbc899d524be1e2804845cef37c3eddf446fdfb8f40c6d30ede4909561f5aadf2d9f7ad8b2564aa8e39d6bc79cf206c12966e020cca3528eb5e041fd2719b
|
7
|
+
data.tar.gz: 8a6e2acf4fb731529b867e0ef33f146a410662a0edd566c34a4a18edf08c67e822d9c2c0ac789cc657c3893bc906c90b974f78486ce4c91f4ae228e07b78c0a0
|
@@ -0,0 +1,28 @@
|
|
1
|
+
### What does this PR do?
|
2
|
+
|
3
|
+
<!-- A brief description of the context of this pull request and its purpose. -->
|
4
|
+
|
5
|
+
### What are the observable changes?
|
6
|
+
<!-- This question could be adequate with multiple use cases, for example: -->
|
7
|
+
|
8
|
+
<!-- Frontend: explain the feature created / updated, give instructions telling how to see the change in staging -->
|
9
|
+
<!-- Performance: what metric should be impacted, link to the right graphana dashboard for exemple -->
|
10
|
+
<!-- Bug: a given issue trail on sentry should stop happening -->
|
11
|
+
<!-- Feature: Implements X thrift service / Z HTTP REST API added, provide instructions on how leverage your feature from staging or your workstation -->
|
12
|
+
|
13
|
+
### Good PR checklist
|
14
|
+
|
15
|
+
- [ ] Title makes sense
|
16
|
+
- [ ] Is against the correct branch
|
17
|
+
- [ ] Only addresses one issue
|
18
|
+
- [ ] Properly assigned
|
19
|
+
- [ ] Added/updated tests
|
20
|
+
- [ ] Added/updated documentation
|
21
|
+
- [ ] Properly labeled
|
22
|
+
|
23
|
+
### Additional Notes
|
24
|
+
|
25
|
+
<!--
|
26
|
+
You can add anything you want here, an explanation on the way you built your implementation,
|
27
|
+
precisions on the origin of the bug, gotchas you need to mention.
|
28
|
+
-->
|
@@ -0,0 +1,25 @@
|
|
1
|
+
name: ci
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches:
|
6
|
+
- master
|
7
|
+
pull_request:
|
8
|
+
|
9
|
+
jobs:
|
10
|
+
test:
|
11
|
+
name: Run Tests
|
12
|
+
runs-on: ubuntu-20.04
|
13
|
+
strategy:
|
14
|
+
matrix:
|
15
|
+
ruby: [2.7, 3.0.3]
|
16
|
+
steps:
|
17
|
+
- name: Checkout
|
18
|
+
uses: actions/checkout@v2
|
19
|
+
- name: Install Ruby
|
20
|
+
uses: ruby/setup-ruby@v1
|
21
|
+
with:
|
22
|
+
ruby-version: ${{ matrix.ruby }}
|
23
|
+
bundler-cache: true
|
24
|
+
- name: Run the Test Suite
|
25
|
+
run: bundle exec rspec --color --require spec_helper --format progress spec
|
@@ -7,13 +7,18 @@ module USerializer
|
|
7
7
|
@opts = opts
|
8
8
|
@block = block
|
9
9
|
|
10
|
+
@skip_nil = opts[:skip_nil] || false
|
10
11
|
@conditional_block = opts[:if] || proc { true }
|
11
12
|
end
|
12
13
|
|
13
14
|
def merge_attributes(res, ser, opts)
|
14
15
|
return unless @conditional_block.call(ser.object, opts)
|
15
16
|
|
16
|
-
|
17
|
+
value = @block ? @block.call(ser.object, opts) : ser.send(@key)
|
18
|
+
|
19
|
+
return if value.nil? && @skip_nil
|
20
|
+
|
21
|
+
res[@key] = value
|
17
22
|
end
|
18
23
|
end
|
19
24
|
end
|
@@ -45,6 +45,7 @@ module USerializer
|
|
45
45
|
@opts = opts
|
46
46
|
@meta = opts[:meta]
|
47
47
|
@except = Set.new([opts[:except]].flatten.compact)
|
48
|
+
@only = Set.new([opts[:only]].flatten.compact)
|
48
49
|
|
49
50
|
@root_key = (opts[:root] || ActiveSupport::Inflector.underscore(
|
50
51
|
obj.class.name
|
@@ -99,15 +100,20 @@ module USerializer
|
|
99
100
|
private
|
100
101
|
|
101
102
|
def attributes
|
102
|
-
@attributes ||= (self.class.attrs || {}).values.
|
103
|
-
|
103
|
+
@attributes ||= (self.class.attrs || {}).values.select do |attr|
|
104
|
+
allow?(attr.key)
|
104
105
|
end
|
105
106
|
end
|
106
107
|
|
107
108
|
def relations
|
108
|
-
@relations ||= (self.class.relations || {}).values.
|
109
|
-
|
109
|
+
@relations ||= (self.class.relations || {}).values.select do |rel|
|
110
|
+
allow?(rel.key)
|
110
111
|
end
|
111
112
|
end
|
113
|
+
|
114
|
+
def allow?(key)
|
115
|
+
return @only.include?(key) if @only.any?
|
116
|
+
!@except.include?(key)
|
117
|
+
end
|
112
118
|
end
|
113
119
|
end
|
data/lib/userializer/has_many.rb
CHANGED
@@ -6,7 +6,7 @@ module USerializer
|
|
6
6
|
@key = key
|
7
7
|
|
8
8
|
@opts = opts
|
9
|
-
@
|
9
|
+
@ids_key = opts[:ids_key] || build_ids_key(key)
|
10
10
|
|
11
11
|
@embed_key = opts[:embed_key] || :id
|
12
12
|
@conditional_block = opts[:if] || proc { true }
|
@@ -15,7 +15,7 @@ module USerializer
|
|
15
15
|
def merge_attributes(res, ser, opts)
|
16
16
|
return unless @conditional_block.call(ser.object, opts)
|
17
17
|
|
18
|
-
res[@
|
18
|
+
res[@ids_key] = (entities(ser) || []).compact.map do |obj|
|
19
19
|
obj.nil? ? nil : obj.send(@embed_key)
|
20
20
|
end.compact
|
21
21
|
end
|
@@ -34,5 +34,11 @@ module USerializer
|
|
34
34
|
|
35
35
|
obj.send(@opts[:scope])
|
36
36
|
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
def build_ids_key(key)
|
41
|
+
"#{ActiveSupport::Inflector.singularize(key)}_ids".to_sym
|
42
|
+
end
|
37
43
|
end
|
38
44
|
end
|
data/lib/userializer/has_one.rb
CHANGED
data/lib/userializer/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: userializer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexis Montagne
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-05-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -87,7 +87,8 @@ executables: []
|
|
87
87
|
extensions: []
|
88
88
|
extra_rdoc_files: []
|
89
89
|
files:
|
90
|
-
- ".
|
90
|
+
- ".github/pull_request_template.md"
|
91
|
+
- ".github/workflows/ci.yml"
|
91
92
|
- ".gitignore"
|
92
93
|
- ".rspec"
|
93
94
|
- ".travis.yml"
|
@@ -123,7 +124,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
123
124
|
- !ruby/object:Gem::Version
|
124
125
|
version: '0'
|
125
126
|
requirements: []
|
126
|
-
rubygems_version: 3.1.
|
127
|
+
rubygems_version: 3.1.2
|
127
128
|
signing_key:
|
128
129
|
specification_version: 4
|
129
130
|
summary: Write a short summary, because RubyGems requires one.
|
data/.circleci/config.yml
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
version: 2
|
2
|
-
jobs:
|
3
|
-
run_tests:
|
4
|
-
docker:
|
5
|
-
- image: circleci/ruby:2.7
|
6
|
-
|
7
|
-
working_directory: ~/userializer
|
8
|
-
|
9
|
-
steps:
|
10
|
-
- checkout
|
11
|
-
- run: bundle install --path=vendor/bundle
|
12
|
-
- run: bundle exec rspec --color --require spec_helper --format progress spec
|
13
|
-
|
14
|
-
workflows:
|
15
|
-
version: 2
|
16
|
-
test:
|
17
|
-
jobs:
|
18
|
-
- run_tests
|