timebomb 0.9.0 → 0.9.1

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: 1833e77693bf971f43b78c5bef33fcf679e510d8a530bb079ff5157616218ce6
4
- data.tar.gz: c96e02c9065acde6d35cabc4097d588d2c4ef1f8c996a395ff659bbf6fb70eba
3
+ metadata.gz: 0ad54e44e510d89d2e9ccc3963f6c93447fbe16b41046ad3c7002a70f3a724b6
4
+ data.tar.gz: 0ff295e086002545559385e7292d12725ebeb2cdb145fcdd6d54ab96c5cfec2b
5
5
  SHA512:
6
- metadata.gz: 47f7c64923d5a917b2096f4c7b755a3fba4d3384a21b70213dbd16432ffb9d52208d3dab8dac6725650e1d8460cb19c324104850e8ba96da047318a0f7806b3f
7
- data.tar.gz: 8b78dec64771c5f342da9cb63c72e1895e1906bb4ded1dedf3e157a5c9507a005d5396a6c32f2145f313bfa056f0339b377a39f6a5223e0544d50308c8c2c4df
6
+ metadata.gz: 22fedf11da4cae21951fdac61b582ca8dc8e1f950f4789af40a540551c7e1e6cdbc104971bd79dc6b73d12d8c56764abdfad3ec13445626cf050a5bd7d370315
7
+ data.tar.gz: c0093955e02f040fb1d4d72f6d51f46d2173122de59ff01bc688507146b837b69f5c18c6366001cf4fd64b9def4dc0e42082f740ad10446e898e6de768203275
data/.gitignore CHANGED
@@ -6,6 +6,7 @@
6
6
  /pkg/
7
7
  /spec/reports/
8
8
  /tmp/
9
+ /timebomb/
9
10
 
10
11
  # rspec failure tracking
11
12
  .rspec_status
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- timebomb (0.1.0)
4
+ timebomb (0.9.0)
5
5
  chronic
6
6
  thor
7
7
 
data/README.md CHANGED
@@ -30,6 +30,17 @@ Then create your first timebomb test:
30
30
 
31
31
  $ timebomb create --title "Remove the old feature" --date "2 months from now"
32
32
 
33
+ This creates a file at `./timebombs/remove_the_old_feature.tb` which you can edit to add more context:
34
+
35
+ ```
36
+ ---
37
+ title: Remove the old feature
38
+ date: 2018-06-16 00:00:00.000000000 -07:00
39
+ ---
40
+
41
+ We're running an experiment on this feature. The metrics team said if we don't get 1,000 users in 2 months we should just pull it.
42
+ ```
43
+
33
44
  To check to see if any of the timebombs went off, run:
34
45
 
35
46
  $ timebomb report
@@ -66,27 +66,36 @@ module Timebomb
66
66
  Would create the file #{DEFAULT_PATH.join("remove_the_feature.tb")}
67
67
  LONGDESC
68
68
  option :title, required: true, aliases: :t
69
- option :date, aliases: :d
69
+ option :date, aliases: :d, default: DEFAULT_DATE_FROM_NOW
70
70
  option :description, aliases: :m
71
71
  def create
72
- title = options[:title]
73
- date = Chronic.parse(options.fetch(:date, DEFAULT_DATE_FROM_NOW))
74
- description = options[:description]
75
-
76
-
77
- path = DEFAULT_PATH.join tb_file(title)
78
- data = { "title" => title, "date" => date }
79
-
80
- File.open(path, 'w') do |file|
81
- file.puts data.to_yaml
82
- file.puts "---"
83
- file.puts
84
- file.puts description
72
+ path = DEFAULT_PATH.join tb_file(options[:title])
73
+ file = BombFile.new(path)
74
+ file.bomb.tap do |b|
75
+ b.title = options[:title]
76
+ b.description = options[:description]
77
+ b.date = options[:date]
85
78
  end
86
-
79
+ file.write
87
80
  puts "Timebomb created at #{path}"
88
81
  end
89
82
 
83
+ desc "bump", "bumps all exploded timebombs to specified date"
84
+ option :date, aliases: :d, default: DEFAULT_DATE_FROM_NOW
85
+ def bump(path = DEFAULT_PATTERN)
86
+ date = options[:date]
87
+ suite = Suite.new
88
+ suite.load_files Dir.glob(path)
89
+ suite.timebomb_files.each do |file|
90
+ file.read
91
+ if file.bomb.has_exploded?
92
+ file.bomb.date = date
93
+ file.write
94
+ puts "Bumped #{file.path} to #{date}"
95
+ end
96
+ end
97
+ end
98
+
90
99
  private
91
100
  def underscore(title)
92
101
  title.downcase.split(/\W/).reject{ |word| word == "" || word.nil? }.join("_")
@@ -99,6 +108,8 @@ module Timebomb
99
108
 
100
109
  class CLIReport
101
110
  RED_COLOR_CODE = 31
111
+ EXPLODED_CHARACTER = "💥"
112
+ UNEXPLODED_CHARACTER = "💣"
102
113
 
103
114
  attr_reader :suite
104
115
 
@@ -109,7 +120,7 @@ module Timebomb
109
120
  def print(out)
110
121
  out.puts "Detected #{suite.timebombs.count} timebombs"
111
122
  suite.timebombs.each do |tb|
112
- out.puts timebomb_line(tb)
123
+ out.puts row " #{explosion_symbol(tb)} ", format_date(tb.date), days_until(tb), tb.title
113
124
  end
114
125
  if suite.has_exploded?
115
126
  out.puts "#{suite.exploded_timebombs.count} timebombs have exploded!"
@@ -117,12 +128,25 @@ module Timebomb
117
128
  end
118
129
 
119
130
  private
120
- def timebomb_line(tb)
121
- [result(tb), tb.date, tb.title].join("\t")
131
+ def row(*columns)
132
+ columns.join("\t")
122
133
  end
123
134
 
124
- def result(tb)
125
- tb.has_exploded? ? " 💣 " : " 💥 "
135
+ def days_until(tb)
136
+ days = tb.days_difference
137
+ if days < 0
138
+ "Exploded #{-days.to_i} days ago"
139
+ else
140
+ "Explodes in #{days.to_i} days"
141
+ end
142
+ end
143
+
144
+ def explosion_symbol(tb)
145
+ tb.has_exploded? ? EXPLODED_CHARACTER : UNEXPLODED_CHARACTER
146
+ end
147
+
148
+ def format_date(date)
149
+ date.strftime "%b %e, %Y"
126
150
  end
127
151
  end
128
152
 
@@ -142,36 +166,61 @@ module Timebomb
142
166
  end
143
167
  end
144
168
 
145
- class Timebomb
146
- attr_accessor :title, :date, :description
169
+ # Handles reading and writing to a Timebomb file `*.tb`.
170
+ class BombFile
171
+ EXTENSION = ".tb".freeze
147
172
 
173
+ attr_reader :path, :bomb
148
174
 
149
- def parse_data(data)
150
- frontmatter = Frontmatter.new(data)
151
- self.title = frontmatter.data.fetch("title")
152
- self.date = frontmatter.data.fetch("date")
153
- self.description = frontmatter.body
175
+ def initialize(path)
176
+ @path = Pathname.new(path)
177
+ @bomb = Bomb.new
178
+ end
154
179
 
155
- self
180
+ def read
181
+ File.open(path, 'r') do |file|
182
+ data = file.read
183
+ frontmatter = Frontmatter.new(data)
184
+ bomb.title = frontmatter.data.fetch("title")
185
+ bomb.date = frontmatter.data.fetch("date")
186
+ bomb.description = frontmatter.body
187
+ end
156
188
  end
157
189
 
158
- def parse_file(path)
159
- parse_data File.read(path)
190
+ def write
191
+ data = { "title" => bomb.title, "date" => bomb.date }
192
+
193
+ File.open(path, 'w') do |file|
194
+ file.puts data.to_yaml
195
+ file.puts "---"
196
+ file.puts
197
+ file.puts bomb.description
198
+ end
160
199
  end
200
+ end
201
+
202
+ class Bomb
203
+ SECONDS_IN_DAY = 86400
204
+
205
+ attr_accessor :title, :date, :description
161
206
 
162
207
  def date=(date)
163
208
  @date = date.is_a?(String) ? Chronic.parse(date) : date
164
209
  end
165
210
 
166
211
  def has_exploded?
167
- self.date > ::Timebomb.current_time
212
+ date < Timebomb.current_time
213
+ end
214
+
215
+ def days_difference
216
+ (date - Timebomb.current_time) / SECONDS_IN_DAY
168
217
  end
169
218
  end
170
219
 
171
220
  class Suite
172
221
  def load_files(paths)
173
222
  paths.each do |path|
174
- self.timebombs << Timebomb.new.parse_file(path)
223
+ self.timebomb_files << BombFile.new(path)
175
224
  end
176
225
  end
177
226
 
@@ -188,7 +237,14 @@ module Timebomb
188
237
  end
189
238
 
190
239
  def timebombs
191
- @timebombs ||= []
240
+ timebomb_files.map do |file|
241
+ file.read
242
+ file.bomb
243
+ end
244
+ end
245
+
246
+ def timebomb_files
247
+ @timebomb_files ||= []
192
248
  end
193
249
  end
194
250
 
@@ -1,3 +1,3 @@
1
1
  module Timebomb
2
- VERSION = "0.9.0"
2
+ VERSION = "0.9.1"
3
3
  end
@@ -9,7 +9,7 @@ Gem::Specification.new do |spec|
9
9
  spec.authors = ["Brad Gessler"]
10
10
  spec.email = ["bradgessler@gmail.com"]
11
11
 
12
- spec.summary = %q{Blow up a CI server when a date is exceeded for a feature}
12
+ spec.summary = %q{Blow up a CI server when its time to deprecate something or remove a feature.}
13
13
  spec.homepage = "https://github.com/bradgessler/timebomb"
14
14
  spec.license = "MIT"
15
15
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: timebomb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0
4
+ version: 0.9.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brad Gessler
@@ -127,5 +127,5 @@ rubyforge_project:
127
127
  rubygems_version: 2.7.3
128
128
  signing_key:
129
129
  specification_version: 4
130
- summary: Blow up a CI server when a date is exceeded for a feature
130
+ summary: Blow up a CI server when its time to deprecate something or remove a feature.
131
131
  test_files: []