This repository has been archived by the owner on Jan 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DRY up the data sync start/end times
These values are beginning to leak into multiple places. It is good maintenance practice to try to keep them in one place. There is probably a cleaner way of doing this with YML config, but given that some places need the start/end times and others need specifically the start/end hour and minute, a function seems a reasonable thing to create to encapsulate all that knowledge. In any case, it is an improvement on trying to duplicate the values throughout the repository.
- Loading branch information
1 parent
1dcf035
commit f6daa94
Showing
4 changed files
with
49 additions
and
18 deletions.
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
modules/govuk/lib/puppet/parser/functions/data_sync_times.rb
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,38 @@ | ||
module Puppet::Parser::Functions | ||
newfunction(:format_data_sync_time, :type => :rvalue, :doc => <<-EOS | ||
Return information about the data sync times, depending on the argument passed | ||
EOS | ||
) do |args| | ||
start_hour = 22 | ||
start_minute = 0 | ||
finish_hour = 8 | ||
finish_minute = 0 | ||
|
||
if args.size != 1 | ||
raise ArgumentError, "format_data_sync_time: Wrong number of arguments " + | ||
"(given #{args.size})" | ||
end | ||
|
||
type = args[0] | ||
|
||
case type | ||
when 'time_range' | ||
"#{start_hour}:#{start_minute}-#{finish_hour}:#{finish_minute}" | ||
when 'start_time' | ||
"#{start_hour}:#{start_minute}" | ||
when 'start_hour' | ||
start_hour | ||
when 'start_minute' | ||
start_minute | ||
when 'finish_time' | ||
"#{finish_hour}:#{finish_minute}" | ||
when 'finish_hour' | ||
finish_hour | ||
when 'finish_minute' | ||
finish_minute | ||
else | ||
raise ArgumentError, "format_data_sync_time: Unknown argument #{type}" | ||
end | ||
end | ||
end | ||
|
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