todo_or_die 0.0.2 → 0.1.0

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: '0491e8c47bb1f59f0b38966bb65a8dbd6d31a18aa9044ca9445cce8962c55e62'
4
+ data.tar.gz: c82c1ce0e56afbfb197ff4d7a66d7187003ef085b58d7096c510696faca4dbc9
5
5
  SHA512:
6
- metadata.gz: fe91f1b1b86bb5a7077a8fa5f35bb25d25f598e4f6c40a319c0a771d755d79905191aa9a2b06982cf33cfc5bdcfa1af0553cd798d53d80580d6c5e27be70ae3e
7
- data.tar.gz: 75480ce8dbf70cf14db4ba6e9592530ef40ef15fa173f841dc7cba0e1a1be3f1965031472ec7cd6def55b9a00d737994d984c4f41dc916436b267ec004b1349c
6
+ metadata.gz: 18751ea8ecfeb4e50ddbdc42229b721957a86bd5d6535655264dec37a46f99f68596fd98be14eb2d585395956cf0b1c01712610750664fae8c8bfa910ac4e0b2
7
+ data.tar.gz: 6fdf682b441ce3edf280f1322cc4a88bf6af9c84057334eef449e894fcd41ff20a3a2164ccd80a13bbe0214787101c0ff38e24cff1f73ae2353853eaf1563c4c
data/.circleci/config.yml CHANGED
@@ -6,7 +6,9 @@ version: 2
6
6
  jobs:
7
7
  build:
8
8
  docker:
9
- - image: circleci/ruby:2.4.1-node-browsers
9
+ - image: circleci/ruby:2.7-node-browsers
10
+ environment:
11
+ RUBYOPT: "-W:no-deprecated -W:no-experimental"
10
12
 
11
13
  working_directory: ~/repo
12
14
 
@@ -16,6 +18,7 @@ jobs:
16
18
  - run:
17
19
  name: install dependencies
18
20
  command: |
21
+ bundle update --bundler
19
22
  bundle install --retry=3
20
23
 
21
24
  - run:
data/CHANGELOG.md ADDED
@@ -0,0 +1,31 @@
1
+ # Changelog
2
+ All notable changes to this project will be documented in this file.
3
+
4
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
5
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
+
7
+ ## [0.1.0] - 2022-06-27
8
+
9
+ - Add `warn_by` option [#14](https://github.com/searls/todo_or_die/pull/14)
10
+
11
+ ## [0.0.3] - 2019-11-26
12
+ ### Added
13
+ - Boolean-returning conditionals or callables (Proc, Block, Lambda) can be passed to the
14
+ new `if` argument. `if` can be used instead of or in conjunction with the `by` argument
15
+ to die on a specific date OR when a specific condition becomes true.
16
+
17
+ ### Changed
18
+ - Date strings can now be parsed parsed internally without calling `Time` or `Date`
19
+ classes explicitely.
20
+
21
+ ## [0.0.2] - 2019-02-15
22
+ ### Changed
23
+ - Exclude this gem's backtrace location from exceptions thrown to make it easier to find
24
+ TODOs.
25
+
26
+ ## [0.0.1] - 2019-01-01
27
+
28
+ [Unreleased]: https://github.com/olivierlacan/keep-a-changelog/compare/v0.0.3...HEAD
29
+ [0.0.3]: https://github.com/olivierlacan/keep-a-changelog/compare/v0.0.2...v0.0.3
30
+ [0.0.2]: https://github.com/olivierlacan/keep-a-changelog/compare/v0.0.1...v0.0.2
31
+ [0.0.1]: https://github.com/olivierlacan/keep-a-changelog/releases/tag/v0.0.1
data/Gemfile CHANGED
@@ -1,6 +1,6 @@
1
1
  source "https://rubygems.org"
2
2
 
3
- git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
3
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
4
4
 
5
5
  # Specify your gem's dependencies in todo_or_die.gemspec
6
6
  gemspec
data/Gemfile.lock CHANGED
@@ -1,33 +1,36 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- todo_or_die (0.0.2)
4
+ todo_or_die (0.1.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
9
  ast (2.4.0)
10
- jaro_winkler (1.5.1)
10
+ jaro_winkler (1.5.4)
11
11
  minitest (5.11.3)
12
- parallel (1.12.1)
13
- parser (2.5.3.0)
12
+ parallel (1.19.1)
13
+ parser (2.7.1.2)
14
14
  ast (~> 2.4.0)
15
- powerpack (0.1.2)
16
15
  rainbow (3.0.0)
17
- rake (12.3.2)
18
- rubocop (0.61.1)
16
+ rake (13.0.1)
17
+ rexml (3.2.4)
18
+ rubocop (0.82.0)
19
19
  jaro_winkler (~> 1.5.1)
20
20
  parallel (~> 1.10)
21
- parser (>= 2.5, != 2.5.1.1)
22
- powerpack (~> 0.1)
21
+ parser (>= 2.7.0.1)
23
22
  rainbow (>= 2.2.2, < 4.0)
23
+ rexml
24
24
  ruby-progressbar (~> 1.7)
25
- unicode-display_width (~> 1.4.0)
26
- ruby-progressbar (1.10.0)
27
- standard (0.0.23)
28
- rubocop (>= 0.60)
25
+ unicode-display_width (>= 1.4.0, < 2.0)
26
+ rubocop-performance (1.5.2)
27
+ rubocop (>= 0.71.0)
28
+ ruby-progressbar (1.10.1)
29
+ standard (0.4.1)
30
+ rubocop (~> 0.82.0)
31
+ rubocop-performance (~> 1.5.2)
29
32
  timecop (0.9.1)
30
- unicode-display_width (1.4.1)
33
+ unicode-display_width (1.7.0)
31
34
 
32
35
  PLATFORMS
33
36
  ruby
@@ -41,4 +44,4 @@ DEPENDENCIES
41
44
  todo_or_die!
42
45
 
43
46
  BUNDLED WITH
44
- 1.17.3
47
+ 2.1.4
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,22 @@ 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 a callable (e.g. proc/lambda/method) or
64
+ a boolean test:
65
+
66
+ ``` ruby
67
+ class User < ApplicationRecord
68
+ TodoOrDie("delete after someone wins", if: User.count > 1000000)
69
+ def is_one_millionth_user?
70
+ id == 1000000
71
+ end
72
+ end
73
+ ```
74
+
75
+ You can also pass both `by` and `if` (where both must be met for an error to be
76
+ raised) or, I guess, neither (where an error will be raised as soon as
77
+ `TodoOrDie` is invoked).
78
+
63
79
  ### What kind of error?
64
80
 
65
81
  It depends on whether you're using [Rails](https://rubyonrails.org) or not.
@@ -1,3 +1,3 @@
1
1
  module TodoOrDie
2
- VERSION = "0.0.2"
2
+ VERSION = "0.1.0"
3
3
  end
data/lib/todo_or_die.rb CHANGED
@@ -1,13 +1,18 @@
1
+ require "time"
1
2
  require "todo_or_die/version"
2
3
  require "todo_or_die/overdue_error"
3
4
 
4
5
  # The namespace
5
6
  module TodoOrDie
6
7
  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
8
+ die: ->(message, due_at, condition) {
9
+ error_message = [
10
+ "TODO: \"#{message}\"",
11
+ (" came due on #{due_at.strftime("%Y-%m-%d")}" if due_at),
12
+ (" and" if due_at && condition),
13
+ (" has met the conditions to be acted upon" if condition),
14
+ ". Do it!"
15
+ ].compact.join("")
11
16
 
12
17
  if defined?(Rails) && Rails.env.production?
13
18
  Rails.logger.warn(error_message)
@@ -15,6 +20,20 @@ module TodoOrDie
15
20
  raise TodoOrDie::OverdueTodo, error_message, TodoOrDie.__clean_backtrace(caller)
16
21
  end
17
22
  },
23
+
24
+ warn: lambda { |message, due_at, warn_at, condition|
25
+ error_message = [
26
+ "TODO: \"#{message}\"",
27
+ (" is due on #{due_at.strftime("%Y-%m-%d")}" if due_at),
28
+ (" and" if warn_at && condition),
29
+ (" has met the conditions to be acted upon" if condition),
30
+ ". Don't forget!"
31
+ ].compact.join("")
32
+
33
+ puts error_message
34
+
35
+ Rails.logger.warn(error_message) if defined?(Rails)
36
+ }
18
37
  }.freeze
19
38
 
20
39
  def self.config(options = {})
@@ -28,15 +47,26 @@ module TodoOrDie
28
47
 
29
48
  FILE_PATH_REGEX = Regexp.new(Regexp.quote(__dir__)).freeze
30
49
  def self.__clean_backtrace(stack)
31
- stack.delete_if {|line| line =~ FILE_PATH_REGEX }
50
+ stack.delete_if { |line| line =~ FILE_PATH_REGEX }
32
51
  end
33
52
  end
34
53
 
35
54
  # The main event
36
- def TodoOrDie(message, by:) # rubocop:disable Naming/MethodName
37
- due_at = by.to_time
55
+ def TodoOrDie(message, by: by_omitted = true, if: if_omitted = true, warn_by: warn_by_omitted = true) # rubocop:disable Naming/MethodName
56
+ due_at = Time.parse(by.to_s) unless by_omitted
57
+ warn_at = Time.parse(warn_by.to_s) unless warn_by_omitted
58
+ condition = binding.local_variable_get(:if) unless if_omitted
59
+
60
+ should_warn = !warn_by_omitted && Time.now > warn_at
61
+ is_due = by_omitted || Time.now > due_at
62
+ die_condition_met = if_omitted || (condition.respond_to?(:call) ? condition.call : condition)
63
+ should_die = is_due && die_condition_met
38
64
 
39
- if Time.now >= due_at
40
- TodoOrDie.config[:die].call(message, due_at)
65
+ if should_die
66
+ die = TodoOrDie.config[:die]
67
+ die.call(*[message, due_at, condition].take(die.arity.abs))
68
+ elsif should_warn
69
+ warn = TodoOrDie.config[:warn]
70
+ warn.call(*[message, due_at, warn_at, condition].take(warn.arity.abs))
41
71
  end
42
72
  end
data/todo_or_die.gemspec CHANGED
@@ -3,15 +3,15 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
3
  require "todo_or_die"
4
4
 
5
5
  Gem::Specification.new do |spec|
6
- spec.name = "todo_or_die"
7
- spec.version = TodoOrDie::VERSION
8
- spec.authors = ["Justin Searls"]
9
- spec.email = ["searls@gmail.com"]
6
+ spec.name = "todo_or_die"
7
+ spec.version = TodoOrDie::VERSION
8
+ spec.authors = ["Justin Searls"]
9
+ spec.email = ["searls@gmail.com"]
10
10
 
11
- spec.summary = "Write TO​DOs in code that ensure you actually do them"
12
- spec.homepage = "https://github.com/searls/todo_or_die"
11
+ spec.summary = "Write TO​DOs in code that ensure you actually do them"
12
+ spec.homepage = "https://github.com/searls/todo_or_die"
13
13
 
14
- spec.files = Dir.chdir(File.expand_path("..", __FILE__)) do
14
+ spec.files = Dir.chdir(File.expand_path("..", __FILE__)) do
15
15
  `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
16
16
  end
17
17
  spec.require_paths = ["lib"]
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.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Searls
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-02-15 00:00:00.000000000 Z
11
+ date: 2022-06-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -80,7 +80,7 @@ dependencies:
80
80
  - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
- description:
83
+ description:
84
84
  email:
85
85
  - searls@gmail.com
86
86
  executables: []
@@ -89,6 +89,7 @@ extra_rdoc_files: []
89
89
  files:
90
90
  - ".circleci/config.yml"
91
91
  - ".gitignore"
92
+ - CHANGELOG.md
92
93
  - Gemfile
93
94
  - Gemfile.lock
94
95
  - LICENSE.txt
@@ -103,7 +104,7 @@ files:
103
104
  homepage: https://github.com/searls/todo_or_die
104
105
  licenses: []
105
106
  metadata: {}
106
- post_install_message:
107
+ post_install_message:
107
108
  rdoc_options: []
108
109
  require_paths:
109
110
  - lib
@@ -118,8 +119,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
118
119
  - !ruby/object:Gem::Version
119
120
  version: '0'
120
121
  requirements: []
121
- rubygems_version: 3.0.1
122
- signing_key:
122
+ rubygems_version: 3.3.7
123
+ signing_key:
123
124
  specification_version: 4
124
125
  summary: Write TO​DOs in code that ensure you actually do them
125
126
  test_files: []