fixme 1.1.2 → 1.1.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
  SHA1:
3
- metadata.gz: 5918a9a8d6c7ed2b50dffce574ddd35938855694
4
- data.tar.gz: 174d74e39c33019eeb487ad97cf58c827a0618dd
3
+ metadata.gz: c67ae50e3df9d60ec0fade7d7a0f5c1e36977e9f
4
+ data.tar.gz: dc1a8c384a67c488afd83c16bba99f497a7d9513
5
5
  SHA512:
6
- metadata.gz: 42f862c20eb8fd60cbc2bd6fcefbaaee13ed635d0f4ebefe84167b13f9c8a3df23eeac57c5ae60c40ec1394f2b4ff029d5fee13d9f0a90138312da6e9977fa4a
7
- data.tar.gz: 3bec830317f532f8e923ce858921f3ad12dc1a65ddeb753c8d4771ef0f38950ca672ee36788a368d44c7d65b515b8f92ddbe9eb1aa8ac0313a25124a6a36a010
6
+ metadata.gz: 2ab32146fc4177eab5ca1777116ef256e1574bcd512d45c3c548edc3ee7ec81d2bdcedb7bdd8e046a81e22265875a74ad0ff1754b95b834a104ef9c7498fea13
7
+ data.tar.gz: 6816245408219c824abdfcafc2b90310c31bc567ddb4c76ce3b1df192c56dd6d7cf2ca5d4c9333f0ff5e72da351b1d4ff6ed4d633e5c66b658b21c43f1a29ddb
data/README.md CHANGED
@@ -22,6 +22,8 @@ If `Rails.environment` (Ruby on Rails) or `ENV["RACK_ENV"]` (e.g. Sinatra) is pr
22
22
 
23
23
  If you don't want your CI server to raise, make it set the environment variable `DO_NOT_RAISE_FIXMES`. I like having CI raise them, though.
24
24
 
25
+ For simplicity, the date comparison uses machine-local time (not e.g. the Rails configured time zone).
26
+
25
27
  Protip: make sure it's clear from the exception or from a separate comment just what should be done – sometimes not even the person who wrote the quickfix will remember what you're meant to change.
26
28
 
27
29
  This library is an extraction of a helper (originally called `wip_raise`) we tried and liked at [Barsoom](http://barsoom.se).
data/lib/fixme.rb CHANGED
@@ -6,26 +6,50 @@ module Fixme
6
6
 
7
7
  module Mixin
8
8
  def FIXME(date_and_message)
9
- return if ENV["DO_NOT_RAISE_FIXMES"]
9
+ # In a separate class to avoid mixing in privates.
10
+ # http://thepugautomatic.com/2014/02/private-api/
11
+ Runner.new(date_and_message).run
12
+ end
13
+ end
14
+
15
+ class Runner
16
+ RUN_ONLY_IN_FRAMEWORK_ENVS = [ "", "test", "development" ]
10
17
 
11
- env = defined?(Rails) ? Rails.env : ENV["RACK_ENV"]
12
- return unless [ "", "test", "development" ].include?(env.to_s)
18
+ def initialize(date_and_message)
19
+ @date_and_message = date_and_message
20
+ end
21
+
22
+ def run
23
+ return if ENV["DO_NOT_RAISE_FIXMES"]
24
+ return unless RUN_ONLY_IN_FRAMEWORK_ENVS.include?(framework_env.to_s)
13
25
 
14
- raw_date, message = date_and_message.split(": ", 2)
15
- due_date = Date.parse(raw_date)
26
+ due_date, message = parse
16
27
 
17
- raise_if_due = -> {
28
+ disallow_timecop do
18
29
  if Date.today >= due_date
19
30
  raise UnfixedError, "Fix by #{due_date}: #{message}"
20
31
  end
21
- }
32
+ end
33
+ end
22
34
 
35
+ private
36
+
37
+ def framework_env
38
+ defined?(Rails) ? Rails.env : ENV["RACK_ENV"]
39
+ end
40
+
41
+ def disallow_timecop(&block)
23
42
  if defined?(Timecop)
24
- Timecop.return(&raise_if_due)
43
+ Timecop.return(&block)
25
44
  else
26
- raise_if_due.call
45
+ block.call
27
46
  end
28
47
  end
48
+
49
+ def parse
50
+ raw_date, message = @date_and_message.split(": ", 2)
51
+ [ Date.parse(raw_date), message ]
52
+ end
29
53
  end
30
54
  end
31
55
 
data/lib/fixme/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Fixme
2
- VERSION = "1.1.2"
2
+ VERSION = "1.1.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fixme
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.2
4
+ version: 1.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Henrik Nyh