basho 0.5.0 → 0.6.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 +9 -0
- data/README.ja.md +1 -1
- data/README.md +1 -1
- data/lib/basho/active_record/postal_auto_resolve.rb +8 -5
- data/lib/basho/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: 4eaf81565f8b05cc3f7de24fddbd5779a53d0cc9a5600d6b59d922c88826af78
|
|
4
|
+
data.tar.gz: 8d19ac60cbfbef252ccc944ed4a8e801f1efa34b6ce206bf6c27146f34a27e51
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d8c3695ed4ed27116623608683ff08d826673489ca5d4f2d485bbe368c8559dcd6a056f34e3d9e79185b143adc360c29fce5135e2ed37f815dfefd4d5aeb4d11
|
|
7
|
+
data.tar.gz: edd6ebc2f13d18af12001d5dbecd3d1e1972970559f0e3f016458234c0586dbdfdbbac4909d89c04c2a382e61def79372d4a8ca97a28a4581827c5c515a38517
|
data/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,15 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [0.6.0] - 2026-05-06
|
|
9
|
+
|
|
10
|
+
### Changed (BREAKING)
|
|
11
|
+
|
|
12
|
+
- `basho_postal` のマッピングオプション指定時の住所自動解決を `before_save` から
|
|
13
|
+
`before_validation` に変更。validation の前に住所が解決されるため、validation や
|
|
14
|
+
他の `before_validation` callback から解決済みの住所を参照できる。
|
|
15
|
+
既存ユーザーで `before_save` のタイミングに依存していた場合は要見直し。
|
|
16
|
+
|
|
8
17
|
## [0.5.0] - 2026-02-11
|
|
9
18
|
|
|
10
19
|
### Added
|
data/README.ja.md
CHANGED
|
@@ -235,7 +235,7 @@ shop.postal_address # => "東京都世田谷区上馬"
|
|
|
235
235
|
|
|
236
236
|
### 郵便番号から住所カラムを自動保存
|
|
237
237
|
|
|
238
|
-
`basho_postal`にマッピングオプションを渡すと、`
|
|
238
|
+
`basho_postal`にマッピングオプションを渡すと、`before_validation`コールバックを登録し、郵便番号カラムの変更時に住所カラムを自動入力します。validation 前に解決されるので、他の `before_validation` callback や validation が解決済みの住所を参照できます。
|
|
239
239
|
|
|
240
240
|
```ruby
|
|
241
241
|
class User < ApplicationRecord
|
data/README.md
CHANGED
|
@@ -235,7 +235,7 @@ shop.postal_address # => "東京都世田谷区上馬"
|
|
|
235
235
|
|
|
236
236
|
### Auto-save address columns from a postal code
|
|
237
237
|
|
|
238
|
-
When you pass mapping options to `basho_postal`, it registers a `
|
|
238
|
+
When you pass mapping options to `basho_postal`, it registers a `before_validation` callback that auto-fills address columns whenever the postal code column changes. Resolving in `before_validation` lets your other callbacks and validations see the resolved address.
|
|
239
239
|
|
|
240
240
|
```ruby
|
|
241
241
|
class User < ApplicationRecord
|
|
@@ -2,9 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
module Basho
|
|
4
4
|
module ActiveRecord
|
|
5
|
-
# 郵便番号変更時に +
|
|
5
|
+
# 郵便番号変更時に +before_validation+ で住所カラムを自動解決する。
|
|
6
6
|
# {Base#basho_postal} のマッピングオプション指定時に使用される。
|
|
7
7
|
#
|
|
8
|
+
# validation の前に住所が解決されるため、validation や他の before_validation
|
|
9
|
+
# callback が解決済みの住所を参照できる。
|
|
10
|
+
#
|
|
8
11
|
# @api private
|
|
9
12
|
module PostalAutoResolve
|
|
10
13
|
# サポートするマッピングキーの一覧
|
|
@@ -12,21 +15,21 @@ module Basho
|
|
|
12
15
|
|
|
13
16
|
module_function
|
|
14
17
|
|
|
15
|
-
# モデルに +
|
|
18
|
+
# モデルに +before_validation+ コールバックを登録する。
|
|
16
19
|
#
|
|
17
20
|
# @param model_class [Class] ActiveRecordモデルクラス
|
|
18
21
|
# @param postal_column [String] 郵便番号カラム名
|
|
19
22
|
# @param mappings [Hash] マッピング設定
|
|
20
23
|
# @return [void]
|
|
21
24
|
def install(model_class, postal_column, mappings)
|
|
22
|
-
unless model_class.respond_to?(:
|
|
23
|
-
raise Basho::Error, "#{model_class} does not support
|
|
25
|
+
unless model_class.respond_to?(:before_validation)
|
|
26
|
+
raise Basho::Error, "#{model_class} does not support before_validation callbacks"
|
|
24
27
|
end
|
|
25
28
|
|
|
26
29
|
postal_col = postal_column.to_s
|
|
27
30
|
resolved = mappings.slice(*MAPPING_KEYS).transform_values(&:to_s).freeze
|
|
28
31
|
|
|
29
|
-
model_class.
|
|
32
|
+
model_class.before_validation do
|
|
30
33
|
next unless will_save_change_to_attribute?(postal_col)
|
|
31
34
|
|
|
32
35
|
postal = Basho::PostalCode.find(send(postal_col))
|
data/lib/basho/version.rb
CHANGED