todo_or_die 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +15 -1
- data/lib/todo_or_die.rb +17 -9
- data/lib/todo_or_die/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 96c320c1ac97e6cffb75fb2a62e882c2f7380aab8e38a562a584ab8c167b05b0
|
4
|
+
data.tar.gz: ac069f4dac6b8282328c521b9f9dc28ea4121d4ddd071ebc838db81a11e946b3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4b2336159eb6e740866bbbf452979c3f55970a0dd77017880e3c40213511f47acd139d0be43cca0cae5d2c3fbff2b3671ae4929f43843e3c2cbd84f72717ba70
|
7
|
+
data.tar.gz: 4aed5f65010ef315704714d9acd608c9bb356ed0b07bb187c89a57c692f1efcbc6f14c9761edff0391ac538cf1ca2ded76f81295718ce75581c5baf6901df492
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -50,7 +50,7 @@ To use it, try replacing one of your TODO comments with something like this:
|
|
50
50
|
|
51
51
|
``` ruby
|
52
52
|
class UsersController < ApiController
|
53
|
-
TodoOrDie("delete after JS app has propagated", by:
|
53
|
+
TodoOrDie("delete after JS app has propagated", by: "2019-02-04")
|
54
54
|
def show
|
55
55
|
redirect_to root_path
|
56
56
|
end
|
@@ -60,6 +60,20 @@ end
|
|
60
60
|
Nothing will happen at all until February 4th, at which point the gem will
|
61
61
|
raise an error whenever this class is loaded until someone deals with it.
|
62
62
|
|
63
|
+
You may also pass a condition, either as boolean or in proc/lambda form:
|
64
|
+
|
65
|
+
``` ruby
|
66
|
+
class User < ApplicationRecord
|
67
|
+
TodoOrDie(
|
68
|
+
"delete after 1 million users",
|
69
|
+
if: User.size > 1000000,
|
70
|
+
)
|
71
|
+
def is_one_millionth_user?
|
72
|
+
id == 1000000
|
73
|
+
end
|
74
|
+
end
|
75
|
+
```
|
76
|
+
|
63
77
|
### What kind of error?
|
64
78
|
|
65
79
|
It depends on whether you're using [Rails](https://rubyonrails.org) or not.
|
data/lib/todo_or_die.rb
CHANGED
@@ -4,10 +4,14 @@ require "todo_or_die/overdue_error"
|
|
4
4
|
# The namespace
|
5
5
|
module TodoOrDie
|
6
6
|
DEFAULT_CONFIG = {
|
7
|
-
die: ->(message, due_at) {
|
8
|
-
error_message =
|
9
|
-
TODO: "#{message}"
|
10
|
-
|
7
|
+
die: ->(message, due_at, condition) {
|
8
|
+
error_message = [
|
9
|
+
"TODO: \"#{message}\"",
|
10
|
+
(" came due on #{due_at.strftime("%Y-%m-%d")}" if due_at),
|
11
|
+
(" and" if due_at && condition),
|
12
|
+
(" has met the conditions to be acted upon" if condition),
|
13
|
+
". Do it!",
|
14
|
+
].compact.join("")
|
11
15
|
|
12
16
|
if defined?(Rails) && Rails.env.production?
|
13
17
|
Rails.logger.warn(error_message)
|
@@ -28,15 +32,19 @@ module TodoOrDie
|
|
28
32
|
|
29
33
|
FILE_PATH_REGEX = Regexp.new(Regexp.quote(__dir__)).freeze
|
30
34
|
def self.__clean_backtrace(stack)
|
31
|
-
stack.delete_if {|line| line =~ FILE_PATH_REGEX }
|
35
|
+
stack.delete_if { |line| line =~ FILE_PATH_REGEX }
|
32
36
|
end
|
33
37
|
end
|
34
38
|
|
35
39
|
# The main event
|
36
|
-
def TodoOrDie(message, by:) # rubocop:disable Naming/MethodName
|
37
|
-
due_at = by.
|
40
|
+
def TodoOrDie(message, by: by_omitted = true, if: if_omitted = true) # rubocop:disable Naming/MethodName
|
41
|
+
due_at = Time.parse(by.to_s) unless by_omitted
|
42
|
+
is_due = by_omitted || Time.now > due_at
|
43
|
+
condition = binding.local_variable_get(:if) unless if_omitted
|
44
|
+
condition_met = if_omitted || (condition.respond_to?(:call) ? condition.call : condition)
|
38
45
|
|
39
|
-
if
|
40
|
-
TodoOrDie.config[:die]
|
46
|
+
if is_due && condition_met
|
47
|
+
die = TodoOrDie.config[:die]
|
48
|
+
die.call(*[message, due_at, condition].take(die.arity.abs))
|
41
49
|
end
|
42
50
|
end
|
data/lib/todo_or_die/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: todo_or_die
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Justin Searls
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-11-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -118,7 +118,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
118
118
|
- !ruby/object:Gem::Version
|
119
119
|
version: '0'
|
120
120
|
requirements: []
|
121
|
-
rubygems_version: 3.0.
|
121
|
+
rubygems_version: 3.0.3
|
122
122
|
signing_key:
|
123
123
|
specification_version: 4
|
124
124
|
summary: Write TODOs in code that ensure you actually do them
|