date_values-rails 0.1.0 → 0.1.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5c1bf3a457deec7273dfaa168ac05e53502775d7877d6c02159ec25639c7fdd8
4
- data.tar.gz: 7c17fd631f2035b8e68899e4d1b9ae5393e578c77db2429ad69222e8532a525f
3
+ metadata.gz: 9d69e9f5fb786a06d1d506e6d9d6c9b0fce4732e67dd27e0ddd5baa339da9558
4
+ data.tar.gz: 715f6f5ce06d89af3cfce70b83a4b13e409588e98842e0174d1e335e2d9d7e03
5
5
  SHA512:
6
- metadata.gz: 3fb2a359513982c11b69c290af20f23d1b651069474879525153387b96a97921165da07078e493f84634929ea31fec8c1c2b6eb796a13b865ffb6b4a0d52e6fb
7
- data.tar.gz: 7bfdab0ce9089d8ab4fd7d121765255c2ccc9e7cfe2eabd4ab736714fbf6714d76dbce638f4e6eecbad05abd6b77ea3244b1de72aa2957dbc3b3271d9cf8c543
6
+ metadata.gz: 67855c8a6e39ebfd6142d11879b1338e4e01bf9e5661bcd3f2d86d722f6139b300da8ad4ae66724a236a84954f00b8c9442a60f61be2c93b4d9a80850d3037d3
7
+ data.tar.gz: 9297fc6c03be8b45c73bfea934177c3452205ce42d9aff5d20627124c6199dd39c3f0e47774d2a0ca521a6e44940bfb00b99ab16e4a161dcadfebf29e14fa002
data/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.1.2] - 2026-03-21
4
+
5
+ - Add ActiveJob serializers for `YearMonth`, `MonthDay`, and `TimeOfDay` (auto-registered)
6
+
7
+ ## [0.1.1] - 2026-03-20
8
+
9
+ - Auto-require via Bundler — no explicit `require 'date_values/rails'` needed in Rails apps
10
+
3
11
  ## [0.1.0] - 2026-03-20
4
12
 
5
13
  - Extracted from [date_values](https://github.com/ursm/date_values) gem
data/README.md CHANGED
@@ -13,8 +13,6 @@ This will also install `date_values` as a dependency.
13
13
  ## Usage
14
14
 
15
15
  ```ruby
16
- require 'date_values/rails'
17
-
18
16
  class Shop < ApplicationRecord
19
17
  attribute :billing_month, :year_month # string column "2026-03"
20
18
  attribute :anniversary, :month_day # string column "--03-19"
@@ -22,17 +20,24 @@ class Shop < ApplicationRecord
22
20
  end
23
21
  ```
24
22
 
25
- ### Form Input
23
+ ### Type Casting
26
24
 
27
- Cast accepts Hash params from forms, so select-based inputs work naturally:
25
+ Attributes accept strings, Hash params, and native objects:
28
26
 
29
27
  ```ruby
28
+ # String (lenient — "3/19", "03-19", "--03-19" all work)
29
+ shop = Shop.new(anniversary: '3/19')
30
+
31
+ # Hash (from select-based form inputs)
30
32
  # params[:shop][:anniversary] => {"month" => "3", "day" => "19"}
33
+ shop = Shop.new(anniversary: params[:shop][:anniversary])
34
+
35
+ # Native object
36
+ shop = Shop.new(anniversary: MonthDay.new(3, 19))
37
+
31
38
  shop.anniversary # => #<DateValues::MonthDay --03-19>
32
39
  ```
33
40
 
34
- String input is lenient — `"3/19"`, `"03-19"`, and `"--03-19"` are all accepted.
35
-
36
41
  ### Queries
37
42
 
38
43
  Values are automatically serialized in queries:
@@ -112,6 +117,20 @@ I18n.l YearMonth.new(2026, 3), locale: :ja # => "2026年3月"
112
117
  I18n.l TimeOfDay.new(14, 30), format: :long # => "2:30:00 PM"
113
118
  ```
114
119
 
120
+ ### ActiveJob
121
+
122
+ Values can be passed directly as job arguments — serializers are registered automatically:
123
+
124
+ ```ruby
125
+ class BillingJob < ApplicationJob
126
+ def perform(month)
127
+ # month is a YearMonth
128
+ end
129
+ end
130
+
131
+ BillingJob.perform_later(YearMonth.new(2026, 3))
132
+ ```
133
+
115
134
  ## License
116
135
 
117
136
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DateValues
4
+ module Rails
5
+ class YearMonthSerializer < ActiveJob::Serializers::ObjectSerializer
6
+ def serialize(value)
7
+ super('value' => value.to_s)
8
+ end
9
+
10
+ def deserialize(hash)
11
+ DateValues::YearMonth.parse(hash['value'])
12
+ end
13
+
14
+ def klass = DateValues::YearMonth
15
+ end
16
+
17
+ class MonthDaySerializer < ActiveJob::Serializers::ObjectSerializer
18
+ def serialize(value)
19
+ super('value' => value.to_s)
20
+ end
21
+
22
+ def deserialize(hash)
23
+ DateValues::MonthDay.parse(hash['value'])
24
+ end
25
+
26
+ def klass = DateValues::MonthDay
27
+ end
28
+
29
+ class TimeOfDaySerializer < ActiveJob::Serializers::ObjectSerializer
30
+ def serialize(value)
31
+ super('value' => value.to_s)
32
+ end
33
+
34
+ def deserialize(hash)
35
+ DateValues::TimeOfDay.parse(hash['value'])
36
+ end
37
+
38
+ def klass = DateValues::TimeOfDay
39
+ end
40
+ end
41
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module DateValues
4
4
  module Rails
5
- VERSION = '0.1.0'
5
+ VERSION = '0.1.2'
6
6
  end
7
7
  end
@@ -21,3 +21,13 @@ ActiveSupport.on_load(:active_record) do
21
21
  end
22
22
 
23
23
  I18n::Backend::Base.prepend(DateValues::Rails::I18nBackend)
24
+
25
+ ActiveSupport.on_load(:active_job) do
26
+ require_relative 'rails/active_job_serializer'
27
+
28
+ ActiveJob::Serializers.add_serializers(
29
+ DateValues::Rails::YearMonthSerializer,
30
+ DateValues::Rails::MonthDaySerializer,
31
+ DateValues::Rails::TimeOfDaySerializer
32
+ )
33
+ end
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'date_values/rails'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: date_values-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Keita Urashima
@@ -47,7 +47,9 @@ files:
47
47
  - LICENSE.txt
48
48
  - README.md
49
49
  - Rakefile
50
+ - lib/date_values-rails.rb
50
51
  - lib/date_values/rails.rb
52
+ - lib/date_values/rails/active_job_serializer.rb
51
53
  - lib/date_values/rails/date_value_validator.rb
52
54
  - lib/date_values/rails/i18n_backend.rb
53
55
  - lib/date_values/rails/month_day_type.rb