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 +4 -4
- data/CHANGELOG.md +12 -0
- data/Gemfile +1 -1
- data/lib/alba/railtie.rb +2 -2
- data/lib/alba/resource.rb +2 -2
- data/lib/alba/typed_attribute.rb +2 -3
- data/lib/alba/version.rb +1 -1
- data/lib/alba.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d3168959e9726c35e28faf0f027dd78010b4b0cf5ead0564b8fa8a7f32e5bf84
|
4
|
+
data.tar.gz: b9cab46abe11f69ef40ef15d3cc673a279a6f1ab12ab8a8b908250a8462f65e8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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.
|
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
|
-
|
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
|
-
|
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
|
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:
|
data/lib/alba/typed_attribute.rb
CHANGED
@@ -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
|
24
|
-
v =
|
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
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
|
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.
|
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
|
+
date: 2024-11-09 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
12
12
|
- !ruby/object:Gem::Dependency
|
13
13
|
name: ostruct
|