active_date_range 0.5.3 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fa7f0092dab70e955754434aa37df4f7c0c11c5461d54b377c68d935ad115330
4
- data.tar.gz: 44658f76ff5dca0336804ce7b7dc44fee1b96699365bd04e8bbf93741ff77f75
3
+ metadata.gz: 8f3c8036025bdc70d1d72d08a4d46d5f72ccefc6e072782b15f266fb783b6397
4
+ data.tar.gz: 8b5dd01d16009fbd7d2df94c3bf65dd71de81f31c610288277bd1dba96cdb610
5
5
  SHA512:
6
- metadata.gz: e7363eeba6c6e8747afd3e3f576fe2d3b24fbe03b17b30de980458fe4e65b9a13a31344a31207d9ae09fe8d0f7a7e97589e6c697f9564fa7977bbf227e80ac01
7
- data.tar.gz: 5a3d15754ce33007ae78e56a0790ac5ede08f34a043d72e0e9866f61f912b2ebec9081af7df285927f83b3d6fd762c20bb4cbb11ae0bf411b7499966f7306e6e
6
+ metadata.gz: bf8dfe1ba846c42abf2c544819b2938ab477c611d3b8a38775f692fe69e02fdaaa098b5c3634a7369c18cc6ebb4e41cb76b7591acd49736ea2543e146c9764a3
7
+ data.tar.gz: 4f10617d476efd7275a37e6a3594a2d193bd59aa95c86f25aadc1ae2cc6200e28a0081f55b69b64ed2d1cefc2a7d9a3a938a09b5199c3798c5de0c53c2900d4d
data/CHANGELOG.md CHANGED
@@ -1,3 +1,13 @@
1
+ ## 0.6.0
2
+
3
+ Rename the `safe:` option on the `:date_range` ActiveModel type to `safe_parse:`. On an attribute, `safe: true` reads as a claim that the value is trusted, while it actually describes how the value is parsed. The option was introduced in 0.5.3 and `safe:` now raises an `ArgumentError`:
4
+
5
+ ```ruby
6
+ attribute :period, :date_range, safe_parse: true
7
+ ```
8
+
9
+ *wesselmoneybird*
10
+
1
11
  ## 0.5.3
2
12
 
3
13
  * Add `safe_parse`, which returns `nil` instead of raising for input that isn't a valid date range. Use it for input you don't control, like a query parameter or a form field:
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- active_date_range (0.5.3)
4
+ active_date_range (0.6.0)
5
5
  activesupport (~> 8.0)
6
6
  i18n (~> 1.6)
7
7
 
data/README.md CHANGED
@@ -134,14 +134,14 @@ class Report
134
134
  end
135
135
  ```
136
136
 
137
- The attribute raises on a value it can't parse. For an attribute fed by input you don't control, like a query parameter or a form field, pass `safe: true`. The attribute then casts to `nil` instead, so a validation can report the problem:
137
+ The attribute raises on a value it can't parse. For an attribute fed by input you don't control, like a query parameter or a form field, pass `safe_parse: true`. The attribute then casts through `safe_parse`, so it returns `nil` instead and a validation can report the problem:
138
138
 
139
139
  ```ruby
140
140
  class ReportFilter
141
141
  include ActiveModel::Attributes
142
142
  include ActiveModel::Validations
143
143
 
144
- attribute :period, :date_range, safe: true
144
+ attribute :period, :date_range, safe_parse: true
145
145
 
146
146
  validates :period, date_range: { bounded: true }
147
147
  end
@@ -2,17 +2,20 @@
2
2
 
3
3
  module ActiveDateRange
4
4
  class DateRangeType < ActiveModel::Type::String
5
- # Pass <tt>safe: true</tt> for attributes fed by input you don't control, like a query
6
- # parameter. The attribute then casts to nil instead of raising:
5
+ # Pass <tt>safe_parse: true</tt> for attributes fed by input you don't control, like a query
6
+ # parameter. The attribute then casts through .safe_parse, so it returns nil instead of
7
+ # raising:
7
8
  #
8
- # attribute :period, :date_range, safe: true
9
- def initialize(safe: false)
10
- @safe = safe
9
+ # attribute :period, :date_range, safe_parse: true
10
+ def initialize(safe_parse: false)
11
+ @safe_parse = safe_parse
11
12
  super()
12
13
  end
13
14
 
14
15
  def cast(value)
15
- @safe ? ActiveDateRange::DateRange.safe_parse(value) : ActiveDateRange::DateRange.parse(value)
16
+ return ActiveDateRange::DateRange.safe_parse(value) if @safe_parse
17
+
18
+ ActiveDateRange::DateRange.parse(value)
16
19
  end
17
20
  end
18
21
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActiveDateRange
4
- VERSION = "0.5.3"
4
+ VERSION = "0.6.0"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_date_range
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.3
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Edwin Vlieg