alba 3.7.4 → 3.8.0
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/CHANGELOG.md +11 -0
- data/README.md +15 -1
- data/lib/alba/resource.rb +1 -0
- data/lib/alba/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 2ff1f7d9c2cf5b49ee88a9cf864e3a66251ccdb502515a1ea91c64837f84d22d
|
|
4
|
+
data.tar.gz: d26b6be0d948d848ba35f216392f9bafe3581925816cc9ee9eeaf651a3face3b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b4b114df3e7e26bf2249f6f683efd1c856594cea376d6b8e33078f1cb9e3810132cf4cb120cfbc6682a556f84ca40115e157f09376c8a81af0160e20efcb2e23
|
|
7
|
+
data.tar.gz: 314f599a9564c053ed653178dd743291cb9125965e8bef7146bed5c049ec44568a40bb1b201df700fe0025e344ae4586af769a377db4f2a50527875aaf2c2c04
|
data/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
6
6
|
|
|
7
7
|
## [Unreleased]
|
|
8
8
|
|
|
9
|
+
## 3.8.0 2025-08-02
|
|
10
|
+
|
|
11
|
+
### Added
|
|
12
|
+
|
|
13
|
+
- add support for ignoring key when using proc for on_error [#450](https://github.com/okuramasafumi/alba/pull/450)
|
|
14
|
+
- Thank you, @mainmethod
|
|
15
|
+
|
|
16
|
+
### Note
|
|
17
|
+
|
|
18
|
+
This change is supposed to be released as 3.8.0 with the change in 3.7.4, but I overlooked this commit. So 3.8.0 is essentially the same as 3.7.4, just making it clear that this version adds a new feature.
|
|
19
|
+
|
|
9
20
|
## 3.7.4 2025-07-24
|
|
10
21
|
|
|
11
22
|
### Fixed
|
data/README.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
[](https://badge.fury.io/rb/alba)
|
|
4
4
|
[](https://github.com/okuramasafumi/alba/actions/workflows/main.yml)
|
|
5
5
|
[](https://codecov.io/gh/okuramasafumi/alba)
|
|
6
|
-
[](https://qlty.sh/gh/okuramasafumi/projects/alba)
|
|
7
7
|

|
|
8
8
|

|
|
9
9
|
[](CODE_OF_CONDUCT.md)
|
|
@@ -371,6 +371,7 @@ You can pass a Hash to the resource for internal use. It can be used as "flags"
|
|
|
371
371
|
```ruby
|
|
372
372
|
class UserResource
|
|
373
373
|
include Alba::Resource
|
|
374
|
+
|
|
374
375
|
attribute :name do |user|
|
|
375
376
|
params[:upcase] ? user.name.upcase : user.name
|
|
376
377
|
end
|
|
@@ -1229,6 +1230,7 @@ The block receives five arguments, `error`, `object`, `key`, `attribute` and `re
|
|
|
1229
1230
|
```ruby
|
|
1230
1231
|
class ExampleResource
|
|
1231
1232
|
include Alba::Resource
|
|
1233
|
+
|
|
1232
1234
|
on_error do |error, object, key, attribute, resource_class|
|
|
1233
1235
|
if resource_class == MyResource
|
|
1234
1236
|
['error_fallback', object.error_fallback]
|
|
@@ -1526,6 +1528,7 @@ Alba supports serializing JSON in a layout. You need a file for layout and then
|
|
|
1526
1528
|
```ruby
|
|
1527
1529
|
class FooResource
|
|
1528
1530
|
include Alba::Resource
|
|
1531
|
+
|
|
1529
1532
|
layout file: 'my_layout.json.erb'
|
|
1530
1533
|
end
|
|
1531
1534
|
```
|
|
@@ -1543,6 +1546,7 @@ In case you don't want to have a file for layout, Alba lets you define and apply
|
|
|
1543
1546
|
```ruby
|
|
1544
1547
|
class FooResource
|
|
1545
1548
|
include Alba::Resource
|
|
1549
|
+
|
|
1546
1550
|
layout inline: proc {
|
|
1547
1551
|
{
|
|
1548
1552
|
header: 'my header',
|
|
@@ -1559,6 +1563,7 @@ You can also use a Proc which returns String, not a Hash, for an inline layout.
|
|
|
1559
1563
|
```ruby
|
|
1560
1564
|
class FooResource
|
|
1561
1565
|
include Alba::Resource
|
|
1566
|
+
|
|
1562
1567
|
layout inline: proc {
|
|
1563
1568
|
%({
|
|
1564
1569
|
"header": "my header",
|
|
@@ -1659,6 +1664,7 @@ In `attribute` block we can call instance method so we can improve the code belo
|
|
|
1659
1664
|
```ruby
|
|
1660
1665
|
class FooResource
|
|
1661
1666
|
include Alba::Resource
|
|
1667
|
+
|
|
1662
1668
|
# other attributes
|
|
1663
1669
|
attribute :created_at do |foo|
|
|
1664
1670
|
foo.created_at.strftime('%m/%d/%Y')
|
|
@@ -1671,6 +1677,7 @@ end
|
|
|
1671
1677
|
|
|
1672
1678
|
class BarResource
|
|
1673
1679
|
include Alba::Resource
|
|
1680
|
+
|
|
1674
1681
|
# other attributes
|
|
1675
1682
|
attribute :created_at do |bar|
|
|
1676
1683
|
bar.created_at.strftime('%m/%d/%Y')
|
|
@@ -1694,6 +1701,7 @@ end
|
|
|
1694
1701
|
class FooResource
|
|
1695
1702
|
include Alba::Resource
|
|
1696
1703
|
include SharedLogic
|
|
1704
|
+
|
|
1697
1705
|
# other attributes
|
|
1698
1706
|
attribute :created_at do |foo|
|
|
1699
1707
|
format_time(foo.created_at)
|
|
@@ -1707,6 +1715,7 @@ end
|
|
|
1707
1715
|
class BarResource
|
|
1708
1716
|
include Alba::Resource
|
|
1709
1717
|
include SharedLogic
|
|
1718
|
+
|
|
1710
1719
|
# other attributes
|
|
1711
1720
|
attribute :created_at do |bar|
|
|
1712
1721
|
format_time(bar.created_at)
|
|
@@ -1738,6 +1747,7 @@ end
|
|
|
1738
1747
|
class FooResource
|
|
1739
1748
|
include Alba::Resource
|
|
1740
1749
|
extend AlbaExtension
|
|
1750
|
+
|
|
1741
1751
|
# other attributes
|
|
1742
1752
|
formatted_time_attributes :created_at, :updated_at
|
|
1743
1753
|
end
|
|
@@ -1745,6 +1755,7 @@ end
|
|
|
1745
1755
|
class BarResource
|
|
1746
1756
|
include Alba::Resource
|
|
1747
1757
|
extend AlbaExtension
|
|
1758
|
+
|
|
1748
1759
|
# other attributes
|
|
1749
1760
|
formatted_time_attributes :created_at, :updated_at
|
|
1750
1761
|
end
|
|
@@ -1760,6 +1771,7 @@ When we `extend AlbaExtension` like above, it's not available in inline associat
|
|
|
1760
1771
|
class BarResource
|
|
1761
1772
|
include Alba::Resource
|
|
1762
1773
|
extend AlbaExtension
|
|
1774
|
+
|
|
1763
1775
|
# other attributes
|
|
1764
1776
|
formatted_time_attributes :created_at, :updated_at
|
|
1765
1777
|
|
|
@@ -1775,6 +1787,7 @@ In this case, we can use [helper](#helper) instead of `extend`.
|
|
|
1775
1787
|
```ruby
|
|
1776
1788
|
class BarResource
|
|
1777
1789
|
include Alba::Resource
|
|
1790
|
+
|
|
1778
1791
|
helper AlbaExtension # HERE!
|
|
1779
1792
|
# other attributes
|
|
1780
1793
|
formatted_time_attributes :created_at, :updated_at
|
|
@@ -1811,6 +1824,7 @@ The typical code looks like this:
|
|
|
1811
1824
|
```ruby
|
|
1812
1825
|
class FooResource
|
|
1813
1826
|
include Alba::Resource
|
|
1827
|
+
|
|
1814
1828
|
attributes :id
|
|
1815
1829
|
end
|
|
1816
1830
|
FooResource.new(foo).serialize
|
data/lib/alba/resource.rb
CHANGED
data/lib/alba/version.rb
CHANGED