-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #196 from 18F/stages/rc-2021
Deploy RC 14 to Prod
- Loading branch information
Showing
23 changed files
with
604 additions
and
222 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,3 +8,7 @@ plugins: | |
channel: rubocop-0-78 | ||
config: | ||
file: .rubocop.yml | ||
|
||
checks: | ||
method-complexity: | ||
enabled: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# Parses duration strings ("1d", 2w", "3m", "4y" into ActiveSupport::Durations) | ||
class DurationParser | ||
attr_reader :value | ||
|
||
# @param value [String, nil] | ||
def initialize(value) | ||
@value = value | ||
end | ||
|
||
# @return [ActiveSupport::Duration, nil] | ||
def parse | ||
return if value.blank? | ||
|
||
match = value.match(/^(?<number>\d+)(?<duration>\D)$/) | ||
return nil unless match | ||
|
||
parse_duration(Integer(match[:number], 10), match[:duration]) | ||
rescue ArgumentError | ||
nil | ||
end | ||
|
||
def valid? | ||
value.blank? || !parse.nil? | ||
end | ||
|
||
# @api private | ||
def parse_duration(number, duration) | ||
case duration | ||
when 'd' # days | ||
number.days | ||
when 'w' # weeks | ||
(7 * number).days | ||
when 'm' # months | ||
(30 * number).days | ||
when 'y' # years | ||
(365 * number).days | ||
end | ||
end | ||
end |
Oops, something went wrong.