alba 3.3.1 → 3.3.3

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: 38b89f99bfe18cf66179ed46c6fdcb5cb25f3d34b8f709fcb9c9de634f7a129b
4
- data.tar.gz: b117d86ab11bb7a0b1abe8e2089ae869c8864fd37b066ea544d0ac51ad5082db
3
+ metadata.gz: d3168959e9726c35e28faf0f027dd78010b4b0cf5ead0564b8fa8a7f32e5bf84
4
+ data.tar.gz: b9cab46abe11f69ef40ef15d3cc673a279a6f1ab12ab8a8b908250a8462f65e8
5
5
  SHA512:
6
- metadata.gz: b62b63a9a7a4b1d85ba180941752a49d4bec97529794f328092b0bb7bc325daa683f5392a703d277f2c4e0b66e6af13b956706ecef6bfc729695aeff0c43e4d0
7
- data.tar.gz: 3336d2097e5e4c78b690c6b3c178fdcef2db47271e1b929c1aeb246fb832632b69c26923abaf5e5e8df1e165d62495da85adce3e66aa8c404b103e65b1a82df1
6
+ metadata.gz: 8d5b3c0513e7f706d484fdc19c8423fc6261bd7b670eee46009b0cf15b9b47f8bdfc14041937a57f15e75c679ad3073fa84ecaf1bcc782ab0615fdebd141a6cc
7
+ data.tar.gz: 017b40ee4d711a50bcd2c74719a0a4a27b4965058cfb8f37382765a84b7400fc78af754fb98b0d4aeb7ba5c935656b3d61687e9c0784a09a047269fbd2e7356f
data/CHANGELOG.md CHANGED
@@ -6,6 +6,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [3.3.3] 2024-11-09
10
+
11
+ ### Fixed
12
+
13
+ - TypedAttribute now respects prefer_resource_method! [#391](https://github.com/okuramasafumi/alba/pull/391)
14
+
15
+ ## [3.3.2] 2024-10-30
16
+
17
+ ### Fixed
18
+
19
+ - Rails integration with `ActionController::API`
20
+
9
21
  ## [3.3.1] 2024-10-17
10
22
 
11
23
  ### Fixed
data/Gemfile CHANGED
@@ -11,7 +11,7 @@ gem 'ffaker', require: false # For testing
11
11
  gem 'minitest', '~> 5.14' # For test
12
12
  gem 'railties', require: false # For Rails integration testing
13
13
  gem 'rake', '~> 13.0' # For test and automation
14
- gem 'rubocop', '~> 1.66.1', require: false # For lint
14
+ gem 'rubocop', '~> 1.68.0', require: false # For lint
15
15
  gem 'rubocop-gem_dev', '>= 0.3.0', require: false # For lint
16
16
  gem 'rubocop-md', '~> 1.0', require: false # For lint
17
17
  gem 'rubocop-minitest', '~> 0.36.0', require: false # For lint
data/lib/alba/railtie.rb CHANGED
@@ -7,11 +7,11 @@ module Alba
7
7
  Alba.inflector = :active_support
8
8
 
9
9
  ActiveSupport.on_load(:action_controller) do
10
- ActionController::Base.define_method(:serialize) do |obj, with: nil, &block|
10
+ define_method(:serialize) do |obj, with: nil, &block|
11
11
  with.nil? ? Alba.resource_with(obj, &block) : with.new(obj)
12
12
  end
13
13
 
14
- ActionController::Base.define_method(:render_serialized_json) do |obj, with: nil, &block|
14
+ define_method(:render_serialized_json) do |obj, with: nil, &block|
15
15
  json = with.nil? ? Alba.resource_with(obj, &block) : with.new(obj)
16
16
  render json: json
17
17
  end
data/lib/alba/resource.rb CHANGED
@@ -239,12 +239,12 @@ module Alba
239
239
  Alba.transform_key(key, transform_type: @_transform_type)
240
240
  end
241
241
 
242
- def fetch_attribute(obj, key, attribute) # rubocop:disable Metrics/CyclomaticComplexity
242
+ def fetch_attribute(obj, key, attribute) # rubocop:disable Metrics
243
243
  value = case attribute
244
244
  when Symbol then fetch_attribute_from_object_and_resource(obj, attribute)
245
245
  when Proc then instance_exec(obj, &attribute)
246
246
  when Alba::Association then yield_if_within(attribute.name.to_sym) { |within| attribute.to_h(obj, params: params, within: within) }
247
- when TypedAttribute then attribute.value(obj)
247
+ when TypedAttribute then attribute.value { |attr| fetch_attribute(obj, key, attr) }
248
248
  when NestedAttribute then attribute.value(object: obj, params: params, within: @within)
249
249
  when ConditionalAttribute then attribute.with_passing_condition(resource: self, object: obj) { |attr| fetch_attribute(obj, key, attr) }
250
250
  # :nocov:
@@ -18,10 +18,9 @@ module Alba
18
18
  end
19
19
  end
20
20
 
21
- # @param object [Object] target to check and convert type with
22
21
  # @return [String, Integer, Boolean] type-checked or type-converted object
23
- def value(object)
24
- v = object.__send__(@name)
22
+ def value
23
+ v = yield(@name)
25
24
  result = @type.check(v)
26
25
  result ? v : @type.convert(v)
27
26
  rescue TypeError
data/lib/alba/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Alba
4
- VERSION = '3.3.1'
4
+ VERSION = '3.3.3'
5
5
  end
data/lib/alba.rb CHANGED
@@ -261,7 +261,7 @@ module Alba
261
261
  inflector
262
262
  end
263
263
 
264
- def register_default_types # rubocop:disable Mertics/AbcSize
264
+ def register_default_types # rubocop:disable Metrics/AbcSize
265
265
  [String, :String].each do |t|
266
266
  register_type(t, check: ->(obj) { obj.is_a?(String) }, converter: lambda(&:to_s))
267
267
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: alba
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.3.1
4
+ version: 3.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - OKURA Masafumi
8
8
  bindir: exe
9
9
  cert_chain: []
10
- date: 2024-10-17 00:00:00.000000000 Z
10
+ date: 2024-11-09 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: ostruct