Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
53 additions
and
6 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
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 |
---|---|---|
@@ -1,19 +1,31 @@ | ||
require "date" | ||
|
||
require "todo_or_die/version" | ||
require "todo_or_die/overdue_error" | ||
|
||
# The namespace | ||
module TodoOrDie | ||
DEFAULT_CONFIG = { | ||
die: ->(message, due_at) { | ||
raise TodoOrDie::OverdueTodo.new <<~MSG | ||
TODO: "#{message}" came due on #{due_at.strftime("%Y-%m-%d")}. Do it! | ||
MSG | ||
}, | ||
}.freeze | ||
|
||
def self.config(options = {}) | ||
@config ||= reset | ||
@config.merge!(options) | ||
end | ||
|
||
def self.reset | ||
@config = DEFAULT_CONFIG.dup | ||
end | ||
end | ||
|
||
# The main event | ||
def TodoOrDie(message, by:) # rubocop:disable Naming/MethodName | ||
due_at = by.to_time | ||
|
||
if Time.now >= due_at | ||
raise TodoOrDie::OverdueTodo.new <<~MSG | ||
TODO: "#{message}" came due on #{due_at.strftime("%Y-%m-%d")}. Do it! | ||
MSG | ||
TodoOrDie.config[:die].call(message, due_at) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,5 +6,6 @@ | |
class UnitTest < Minitest::Test | ||
def teardown | ||
Timecop.return | ||
TodoOrDie.reset | ||
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