alba 3.0.0 → 3.0.1

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
  SHA256:
3
- metadata.gz: d76423c125b10f3a012066e6df3924c1dde50c1842e78be87179d99da8707a9e
4
- data.tar.gz: 23bba5622260ac6926a669b1d4d4aa44e6a4189838b2c77b23f6e846c56ea14f
3
+ metadata.gz: a659a06525b2938d8115b64712344d9dc173ad86a3c6c2b392c283eccd5048fd
4
+ data.tar.gz: 9a9fa379c582928259580396277472438ce1afe566088214b08cccddd5836bae
5
5
  SHA512:
6
- metadata.gz: d57037b9ea77550953a6e8dc4f6896e314ce1e63e36925ec960ebca1e2cce043f61a289091f09c74ef308de50d541e2b2624ce977dcf613165175328c546b32c
7
- data.tar.gz: 21ab608e1844f3a575985927f81ed892f1cb50c8bf9008302c4572d1acc9c9bebbc66c1afce173af29a22b03f67a6e0b117197d037ae64061401e5a19d1779e6
6
+ metadata.gz: 6985bbc1306bc15d7173cab450df98aa8382dcaf9384975558b0a590e2f056c1d3fa16e53684033baabbeabc202fce975487afa34170691f174eafcca43043f7
7
+ data.tar.gz: 16eab414db7324830348eff012f269a670879138110c0595341101649acc7cf6432a9d916d44b65b885d91923d1387e6a19ca4094654f82ef60b152d94778d1d
data/CHANGELOG.md CHANGED
@@ -6,8 +6,21 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [3.0.1] 2023-10-13
10
+
11
+ ### Fixed
12
+
13
+ - Fixed a bug where methods such as `test` or `params` cannot be used as attribute name [#344](https://github.com/okuramasafumi/alba/pull/344)
14
+ - Remove redundant code
15
+
9
16
  ## [3.0.0] 2023-10-11
10
17
 
18
+ ### IMPORTANT
19
+
20
+ **This release contains an important bug fix that can cause data corruption.**
21
+ **If you're using Ruby 3, it's highly recommended to upgrade to [v3.0.0](https://rubygems.org/gems/alba/versions/3.0.0)**
22
+ **If you're using Ruby 2, please upgrade to [v2.4.2](https://rubygems.org/gems/alba/versions/2.4.2) that contains bug fix only as soon as possible.**
23
+
11
24
  ### Added
12
25
 
13
26
  - Custom type [#333](https://github.com/okuramasafumi/alba/pull/333)
data/README.md CHANGED
@@ -11,6 +11,14 @@
11
11
 
12
12
  Alba is a JSON serializer for Ruby, JRuby, and TruffleRuby.
13
13
 
14
+ ## IMPORTANT NOTICE
15
+
16
+ Both version `3.0.0` and `2.4.2` contain important bug fix.
17
+ However, version `3.0.0` has some bugs (see https://github.com/okuramasafumi/alba/issues/342).
18
+ Until they get fixed, it's highly recommended to upgrade to version `2.4.2`.
19
+ Dependabot and similar tools might create an automated Pull Request to upgrade to `3.0.0`, so it might be required to upgrade to `2.4.2` manually.
20
+ Sorry for the inconvenience.
21
+
14
22
  ## TL;DR
15
23
 
16
24
  Alba allows you to do something like below.
@@ -57,7 +57,6 @@ module Alba
57
57
  when Class
58
58
  resource
59
59
  when Symbol, String
60
- Object.const_get(resource)
61
60
  self.class.const_cache.fetch(resource) do
62
61
  self.class.const_cache[resource] = Object.const_get(resource)
63
62
  end
@@ -51,6 +51,8 @@ module Alba
51
51
 
52
52
  # OpenStruct is used as a simple solution for converting Hash or Array of Hash into an object
53
53
  # Using OpenStruct is not good in general, but in this case there's no other solution
54
+ # rubocop:disable Style/OpenStructUse
55
+ # rubocop:disable Performance/OpenStruct
54
56
  def objectize(fetched_attribute)
55
57
  return fetched_attribute unless @body.is_a?(Alba::Association)
56
58
 
@@ -62,5 +64,7 @@ module Alba
62
64
  OpenStruct.new(fetched_attribute)
63
65
  end
64
66
  end
67
+ # rubocop:enable Style/OpenStructUse
68
+ # rubocop:enable Performance/OpenStruct
65
69
  end
66
70
  end
data/lib/alba/resource.rb CHANGED
@@ -12,7 +12,7 @@ module Alba
12
12
  module Resource
13
13
  # @!parse include InstanceMethods
14
14
  # @!parse extend ClassMethods
15
- INTERNAL_VARIABLES = {_attributes: {}, _key: nil, _key_for_collection: nil, _meta: nil, _transform_type: :none, _transforming_root_key: false, _key_transformation_cascade: true, _on_error: nil, _on_nil: nil, _layout: nil, _collection_key: nil, _helper: nil}.freeze # rubocop:disable Layout/LineLength
15
+ INTERNAL_VARIABLES = {_attributes: {}, _key: nil, _key_for_collection: nil, _meta: nil, _transform_type: :none, _transforming_root_key: false, _key_transformation_cascade: true, _on_error: nil, _on_nil: nil, _layout: nil, _collection_key: nil, _helper: nil, _resource_methods: []}.freeze # rubocop:disable Layout/LineLength
16
16
  private_constant :INTERNAL_VARIABLES
17
17
 
18
18
  WITHIN_DEFAULT = Object.new.freeze
@@ -265,9 +265,15 @@ module Alba
265
265
  end
266
266
 
267
267
  def _fetch_attribute_from_resource_first(obj, attribute)
268
- __send__(attribute, obj)
269
- rescue NoMethodError
270
- obj.__send__(attribute)
268
+ if @_resource_methods.include?(attribute)
269
+ begin
270
+ __send__(attribute, obj)
271
+ rescue NoMethodError
272
+ obj.__send__(attribute)
273
+ end
274
+ else
275
+ obj.__send__(attribute)
276
+ end
271
277
  end
272
278
 
273
279
  def nil_handler
@@ -302,6 +308,12 @@ module Alba
302
308
  module ClassMethods
303
309
  attr_reader(*INTERNAL_VARIABLES.keys)
304
310
 
311
+ # This `method_added` is used for defining "resource methods"
312
+ def method_added(method_name)
313
+ _resource_methods << method_name.to_sym unless method_name.to_sym == :_setup
314
+ super
315
+ end
316
+
305
317
  # @private
306
318
  def inherited(subclass)
307
319
  super
data/lib/alba/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Alba
2
- VERSION = '3.0.0'.freeze
2
+ VERSION = '3.0.1'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: alba
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0
4
+ version: 3.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - OKURA Masafumi
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-10-11 00:00:00.000000000 Z
11
+ date: 2023-10-13 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Alba is the fastest JSON serializer for Ruby. It focuses on performance,
14
14
  flexibility and usability.
@@ -94,7 +94,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
94
94
  - !ruby/object:Gem::Version
95
95
  version: '0'
96
96
  requirements: []
97
- rubygems_version: 3.4.14
97
+ rubygems_version: 3.4.20
98
98
  signing_key:
99
99
  specification_version: 4
100
100
  summary: Alba is the fastest JSON serializer for Ruby.