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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b194253e28740bfc137b7ef030efcf8387fe3acf0b91983eb69b961691a1c4eb
4
- data.tar.gz: 8566f5e5b156ff958ee22aaca60f663d372cd0bea69ffacc5218c86441ce2a1c
3
+ metadata.gz: 96c320c1ac97e6cffb75fb2a62e882c2f7380aab8e38a562a584ab8c167b05b0
4
+ data.tar.gz: ac069f4dac6b8282328c521b9f9dc28ea4121d4ddd071ebc838db81a11e946b3
5
5
  SHA512:
6
- metadata.gz: fe91f1b1b86bb5a7077a8fa5f35bb25d25f598e4f6c40a319c0a771d755d79905191aa9a2b06982cf33cfc5bdcfa1af0553cd798d53d80580d6c5e27be70ae3e
7
- data.tar.gz: 75480ce8dbf70cf14db4ba6e9592530ef40ef15fa173f841dc7cba0e1a1be3f1965031472ec7cd6def55b9a00d737994d984c4f41dc916436b267ec004b1349c
6
+ metadata.gz: 4b2336159eb6e740866bbbf452979c3f55970a0dd77017880e3c40213511f47acd139d0be43cca0cae5d2c3fbff2b3671ae4929f43843e3c2cbd84f72717ba70
7
+ data.tar.gz: 4aed5f65010ef315704714d9acd608c9bb356ed0b07bb187c89a57c692f1efcbc6f14c9761edff0391ac538cf1ca2ded76f81295718ce75581c5baf6901df492
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- todo_or_die (0.0.2)
4
+ todo_or_die (0.0.3)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
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: Time.parse("2019-02-04"))
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.
@@ -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 = <<~MSG
9
- TODO: "#{message}" came due on #{due_at.strftime("%Y-%m-%d")}. Do it!
10
- MSG
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.to_time
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 Time.now >= due_at
40
- TodoOrDie.config[:die].call(message, due_at)
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
@@ -1,3 +1,3 @@
1
1
  module TodoOrDie
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
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.2
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-02-15 00:00:00.000000000 Z
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.1
121
+ rubygems_version: 3.0.3
122
122
  signing_key:
123
123
  specification_version: 4
124
124
  summary: Write TO​DOs in code that ensure you actually do them