userializer 0.3.4 → 0.3.5
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/.github/workflows/ci.yml +2 -14
- data/README.md +25 -0
- data/lib/userializer/base_serializer.rb +7 -7
- data/lib/userializer/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f8f6728d125ec0a77596d0915484d2daed9322bae58be84aed2e0e1c2d5c1a78
|
4
|
+
data.tar.gz: f73b384888194553dd67a935f3eb4b7537b26fe9fd6ec82e7cc1ebe130f696fe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0b236a2d033b3813216b4de8ba7ec64709890e47ef3c7a806247e44d2dcb9b206d6c6bc102188e6d2909468a09cebd535708dfff6a74adcc1a27451979780e0a
|
7
|
+
data.tar.gz: 2031d2e8ef3a9c62f14bbf5651ab463e818677672298b1f1e9913c3ba7c62ddd05f3f91cfd95490e2719e5d86fa29d8ea2a490a17ee40333cee29212b9095377
|
data/.github/workflows/ci.yml
CHANGED
@@ -9,17 +9,5 @@ on:
|
|
9
9
|
jobs:
|
10
10
|
test:
|
11
11
|
name: Run Tests
|
12
|
-
|
13
|
-
|
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
|
12
|
+
uses: upfluence/actions/.github/workflows/lib-ruby-test.yml@master
|
13
|
+
secrets: inherit
|
data/README.md
CHANGED
@@ -105,6 +105,31 @@ Way nicer, right?
|
|
105
105
|
Just like AMS, USerializer supports `has_one` and `has_many`
|
106
106
|
relationships
|
107
107
|
|
108
|
+
### Collection Attributes Filtering
|
109
|
+
|
110
|
+
For `has_many` relationships, USerializer allow you to serialize only
|
111
|
+
part of the collection that matches some criterias.
|
112
|
+
It relies on the ActiveRecord `scope` feature :
|
113
|
+
|
114
|
+
```ruby
|
115
|
+
class Product < ActiveRecord::Base
|
116
|
+
has_many :variants
|
117
|
+
end
|
118
|
+
|
119
|
+
class Variant < ActiveRecord::Base
|
120
|
+
belongs_to :product
|
121
|
+
|
122
|
+
scope :available, -> { where(delete_at: nil) }
|
123
|
+
end
|
124
|
+
|
125
|
+
class ProductSerializer < USerializer::BaseSerializer
|
126
|
+
has_many :variants, scope: :available
|
127
|
+
end
|
128
|
+
|
129
|
+
class VariantSerializer < USerializer::BaseSerializer
|
130
|
+
end
|
131
|
+
```
|
132
|
+
|
108
133
|
### Serialized Output
|
109
134
|
|
110
135
|
The following outputs will be based an on our `Order` object in
|
@@ -55,8 +55,8 @@ module USerializer
|
|
55
55
|
def serializable_hash(opts)
|
56
56
|
res = {}
|
57
57
|
|
58
|
-
|
59
|
-
|
58
|
+
_attributes.each { |attr| attr.merge_attributes(res, self, opts) }
|
59
|
+
_relations.each do |rel|
|
60
60
|
rel.merge_attributes(res, self, opts)
|
61
61
|
end
|
62
62
|
|
@@ -78,7 +78,7 @@ module USerializer
|
|
78
78
|
end
|
79
79
|
end
|
80
80
|
|
81
|
-
|
81
|
+
_relations.each { |rel| rel.merge_root(res, self, opts) }
|
82
82
|
end
|
83
83
|
|
84
84
|
def to_hash
|
@@ -99,14 +99,14 @@ module USerializer
|
|
99
99
|
|
100
100
|
private
|
101
101
|
|
102
|
-
def
|
103
|
-
@
|
102
|
+
def _attributes
|
103
|
+
@_attributes ||= (self.class.attrs || {}).values.select do |attr|
|
104
104
|
allow?(attr.key)
|
105
105
|
end
|
106
106
|
end
|
107
107
|
|
108
|
-
def
|
109
|
-
@
|
108
|
+
def _relations
|
109
|
+
@_relations ||= (self.class.relations || {}).values.select do |rel|
|
110
110
|
allow?(rel.key)
|
111
111
|
end
|
112
112
|
end
|
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.5
|
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: 2025-06-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -124,7 +124,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
124
124
|
- !ruby/object:Gem::Version
|
125
125
|
version: '0'
|
126
126
|
requirements: []
|
127
|
-
rubygems_version: 3.
|
127
|
+
rubygems_version: 3.3.7
|
128
128
|
signing_key:
|
129
129
|
specification_version: 4
|
130
130
|
summary: Write a short summary, because RubyGems requires one.
|