userializer 0.3.3 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3cb0544f358655737798992e56aca1d2b2637508bf05c1968788832028fe2048
4
- data.tar.gz: e5ad28d55ce77894acbf6763553f478e257375d3f2cbb11e2c267d35e14d1841
3
+ metadata.gz: f8f6728d125ec0a77596d0915484d2daed9322bae58be84aed2e0e1c2d5c1a78
4
+ data.tar.gz: f73b384888194553dd67a935f3eb4b7537b26fe9fd6ec82e7cc1ebe130f696fe
5
5
  SHA512:
6
- metadata.gz: 59bcbc899d524be1e2804845cef37c3eddf446fdfb8f40c6d30ede4909561f5aadf2d9f7ad8b2564aa8e39d6bc79cf206c12966e020cca3528eb5e041fd2719b
7
- data.tar.gz: 8a6e2acf4fb731529b867e0ef33f146a410662a0edd566c34a4a18edf08c67e822d9c2c0ac789cc657c3893bc906c90b974f78486ce4c91f4ae228e07b78c0a0
6
+ metadata.gz: 0b236a2d033b3813216b4de8ba7ec64709890e47ef3c7a806247e44d2dcb9b206d6c6bc102188e6d2909468a09cebd535708dfff6a74adcc1a27451979780e0a
7
+ data.tar.gz: 2031d2e8ef3a9c62f14bbf5651ab463e818677672298b1f1e9913c3ba7c62ddd05f3f91cfd95490e2719e5d86fa29d8ea2a490a17ee40333cee29212b9095377
@@ -9,17 +9,5 @@ on:
9
9
  jobs:
10
10
  test:
11
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
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
@@ -14,7 +14,7 @@ module USerializer
14
14
 
15
15
  raise HeterogeneousArray if clss.count > 1
16
16
 
17
- @root_key = opts[:root]
17
+ @root_key = opts[:root]&.to_sym
18
18
  @root_key ||= ActiveSupport::Inflector.pluralize(
19
19
  ActiveSupport::Inflector.underscore(obj_class.name).split('/').last
20
20
  ).to_sym if obj_class
@@ -55,8 +55,8 @@ module USerializer
55
55
  def serializable_hash(opts)
56
56
  res = {}
57
57
 
58
- attributes.each { |attr| attr.merge_attributes(res, self, opts) }
59
- relations.each do |rel|
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
- relations.each { |rel| rel.merge_root(res, self, opts) }
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 attributes
103
- @attributes ||= (self.class.attrs || {}).values.select do |attr|
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 relations
109
- @relations ||= (self.class.relations || {}).values.select do |rel|
108
+ def _relations
109
+ @_relations ||= (self.class.relations || {}).values.select do |rel|
110
110
  allow?(rel.key)
111
111
  end
112
112
  end
@@ -1,3 +1,3 @@
1
1
  module USerializer
2
- VERSION = "0.3.3"
2
+ VERSION = "0.3.5"
3
3
  end
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.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: 2022-05-31 00:00:00.000000000 Z
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.1.2
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.