frag 0.0.1 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/CHANGELOG CHANGED
@@ -1,3 +1,7 @@
1
+ == 0.1.0 2012-08-05
2
+
3
+ * Use 'frag:'...'frag end' for delimiters.
4
+
1
5
  == 0.0.1 2012-08-05
2
6
 
3
7
  * Hi.
data/README.markdown CHANGED
@@ -16,14 +16,14 @@ you might want to generate your `~/.ssh/config` from a list of hosts managed by
16
16
  Hostname 123.123.123.2
17
17
  User me
18
18
 
19
- # GEN: knife sshgen
20
- # ENDGEN
19
+ # frag: knife sshgen
20
+ # frag end
21
21
 
22
22
  Now `frag` that file:
23
23
 
24
24
  frag ~/.ssh/config
25
25
 
26
- and the region delimited by the `GEN`..`ENDGEN` lines will be filled in with the
26
+ and the region delimited by the `GEN`..`frag end` lines will be filled in with the
27
27
  output from [knife sshgen][knife-sshgen]. The delimiter lines remain, so you can
28
28
  re-`frag` anytime to bring it up to date.
29
29
 
@@ -35,15 +35,15 @@ database:
35
35
  ::1 localhost
36
36
  fe80::1%lo0 localhost
37
37
 
38
- # GEN: mysql myapp -Bre 'select subdomain from sites | sed -e 's/.*/127.0.0.1 &.myapp.local/'
39
- # ENDGEN
38
+ # frag: mysql myapp -Bre 'select subdomain from sites | sed -e 's/.*/127.0.0.1 &.myapp.local/'
39
+ # frag end
40
40
 
41
41
  Pipelines work - woo!
42
42
 
43
43
  Or maybe you're authoring this README and want to show all the options `frag`
44
44
  takes:
45
45
 
46
- <!-- GEN: echo; ruby -Ilib bin/frag --help | sed -e 's/^/ /'; echo -->
46
+ <!-- frag: echo; ruby -Ilib bin/frag --help | sed -e 's/^/ /'; echo -->
47
47
 
48
48
  USAGE: bin/frag [options] file ...
49
49
  -b, --begin DELIMITER
@@ -53,7 +53,7 @@ takes:
53
53
  -p, --backup-prefix PREFIX
54
54
  -s, --backup-suffix SUFFIX
55
55
 
56
- <!-- ENDGEN -->
56
+ <!-- frag end -->
57
57
 
58
58
  (Check the source... ;-)
59
59
 
data/lib/frag/app.rb CHANGED
@@ -8,8 +8,8 @@ module Frag
8
8
  @input, @output, @error = input, output, error
9
9
  @status = 0
10
10
 
11
- beginning = 'GEN:'
12
- ending = 'ENDGEN'
11
+ beginning = 'frag:'
12
+ ending = 'frag end'
13
13
  leader = '#'
14
14
  trailer = ''
15
15
  @backup_prefix = @backup_suffix = nil
data/lib/frag/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module Frag
2
- VERSION = [0, 0, 1]
2
+ VERSION = [0, 1, 0]
3
3
 
4
4
  class << VERSION
5
5
  include Comparable
@@ -12,15 +12,15 @@ describe Frag do
12
12
  describe "when a file is frag'd successfully" do
13
13
  it "updates the file, and exits with zero status" do
14
14
  write_file 'input', <<-EOS.demargin
15
- |# GEN: echo new
15
+ |# frag: echo new
16
16
  |old
17
- |# ENDGEN
17
+ |# frag end
18
18
  EOS
19
19
  frag('input').must_equal 0
20
20
  File.read('input').must_equal <<-EOS.demargin
21
- |# GEN: echo new
21
+ |# frag: echo new
22
22
  |new
23
- |# ENDGEN
23
+ |# frag end
24
24
  EOS
25
25
  end
26
26
  end
@@ -28,21 +28,21 @@ describe Frag do
28
28
  describe "when options are used succesfully" do
29
29
  it "updates the file, and exits with zero status" do
30
30
  write_file 'input', <<-EOS.demargin
31
- |# GEN: echo new
31
+ |# frag: echo new
32
32
  |old
33
- |# ENDGEN
34
- |// GEN: echo new
33
+ |# frag end
34
+ |// frag: echo new
35
35
  |old
36
- |// ENDGEN
36
+ |// frag end
37
37
  EOS
38
38
  frag('-l', '//', 'input').must_equal 0
39
39
  File.read('input').must_equal <<-EOS.demargin
40
- |# GEN: echo new
40
+ |# frag: echo new
41
41
  |old
42
- |# ENDGEN
43
- |// GEN: echo new
42
+ |# frag end
43
+ |// frag: echo new
44
44
  |new
45
- |// ENDGEN
45
+ |// frag end
46
46
  EOS
47
47
  end
48
48
  end
@@ -14,92 +14,92 @@ describe Frag::App do
14
14
  describe "when no options are used" do
15
15
  it "populates the delimited region if it's empty" do
16
16
  write_file 'input', <<-EOS.demargin
17
- |# GEN: echo hi
18
- |# ENDGEN
17
+ |# frag: echo hi
18
+ |# frag end
19
19
  EOS
20
20
  frag('input').must_equal 0
21
21
  (output.string + error.string).must_equal ''
22
22
  File.read('input').must_equal <<-EOS.demargin
23
- |# GEN: echo hi
23
+ |# frag: echo hi
24
24
  |hi
25
- |# ENDGEN
25
+ |# frag end
26
26
  EOS
27
27
  end
28
28
 
29
29
  it "replaces the delimited region if there's already something there" do
30
30
  write_file 'input', <<-EOS.demargin
31
- |# GEN: echo new
31
+ |# frag: echo new
32
32
  |old
33
- |# ENDGEN
33
+ |# frag end
34
34
  EOS
35
35
  frag('input').must_equal 0
36
36
  (output.string + error.string).must_equal ''
37
37
  File.read('input').must_equal <<-EOS.demargin
38
- |# GEN: echo new
38
+ |# frag: echo new
39
39
  |new
40
- |# ENDGEN
40
+ |# frag end
41
41
  EOS
42
42
  end
43
43
 
44
44
  it "appends a newline if the command output doesn't end in one" do
45
45
  write_file 'input', <<-EOS.demargin
46
- |# GEN: echo -n hi
47
- |# ENDGEN
46
+ |# frag: echo -n hi
47
+ |# frag end
48
48
  EOS
49
49
  frag('input').must_equal 0
50
50
  (output.string + error.string).must_equal ''
51
51
  File.read('input').must_equal <<-EOS.demargin
52
- |# GEN: echo -n hi
52
+ |# frag: echo -n hi
53
53
  |hi
54
- |# ENDGEN
54
+ |# frag end
55
55
  EOS
56
56
  end
57
57
 
58
58
  it "processes multiple regions, and leave surrounding content alone" do
59
59
  write_file 'input', <<-EOS.demargin
60
60
  |before
61
- |# GEN: echo one
62
- |# ENDGEN
61
+ |# frag: echo one
62
+ |# frag end
63
63
  |middle
64
- |# GEN: echo two
65
- |# ENDGEN
64
+ |# frag: echo two
65
+ |# frag end
66
66
  |after
67
67
  EOS
68
68
  frag('input').must_equal 0
69
69
  (output.string + error.string).must_equal ''
70
70
  File.read('input').must_equal <<-EOS.demargin
71
71
  |before
72
- |# GEN: echo one
72
+ |# frag: echo one
73
73
  |one
74
- |# ENDGEN
74
+ |# frag end
75
75
  |middle
76
- |# GEN: echo two
76
+ |# frag: echo two
77
77
  |two
78
- |# ENDGEN
78
+ |# frag end
79
79
  |after
80
80
  EOS
81
81
  end
82
82
 
83
83
  it "can process multiple files" do
84
84
  write_file 'one', <<-EOS.demargin
85
- |# GEN: echo one
86
- |# ENDGEN
85
+ |# frag: echo one
86
+ |# frag end
87
87
  EOS
88
88
  write_file 'two', <<-EOS.demargin
89
- |# GEN: echo two
90
- |# ENDGEN
89
+ |# frag: echo two
90
+ |# frag end
91
91
  EOS
92
92
  frag('one', 'two').must_equal 0
93
93
  (output.string + error.string).must_equal ''
94
94
  File.read('one').must_equal <<-EOS.demargin
95
- |# GEN: echo one
95
+ |# frag: echo one
96
96
  |one
97
- |# ENDGEN
97
+ |# frag end
98
98
  EOS
99
99
  File.read('two').must_equal <<-EOS.demargin
100
- |# GEN: echo two
100
+ |# frag: echo two
101
101
  |two
102
- |# ENDGEN
102
+ |# frag end
103
103
  EOS
104
104
  end
105
105
  end
@@ -109,14 +109,14 @@ describe Frag::App do
109
109
  it "uses the beginning delimiter given by #{option}" do
110
110
  write_file 'input', <<-EOS.demargin
111
111
  |# BEGIN echo one
112
- |# ENDGEN
112
+ |# frag end
113
113
  EOS
114
114
  frag(option, 'BEGIN', 'input').must_equal 0
115
115
  (output.string + error.string).must_equal ''
116
116
  File.read('input').must_equal <<-EOS.demargin
117
117
  |# BEGIN echo one
118
118
  |one
119
- |# ENDGEN
119
+ |# frag end
120
120
  EOS
121
121
  end
122
122
  end
@@ -124,13 +124,13 @@ describe Frag::App do
124
124
  ['-e', '--end'].each do |option|
125
125
  it "uses the ending delimiter given by #{option}" do
126
126
  write_file 'input', <<-EOS.demargin
127
- |# GEN: echo one
127
+ |# frag: echo one
128
128
  |# END
129
129
  EOS
130
130
  frag(option, 'END', 'input').must_equal 0
131
131
  (output.string + error.string).must_equal ''
132
132
  File.read('input').must_equal <<-EOS.demargin
133
- |# GEN: echo one
133
+ |# frag: echo one
134
134
  |one
135
135
  |# END
136
136
  EOS
@@ -140,15 +140,15 @@ describe Frag::App do
140
140
  ['-l', '--leader'].each do |option|
141
141
  it "uses the delimiter leader given by #{option}" do
142
142
  write_file 'input', <<-EOS.demargin
143
- |// GEN: echo one
144
- |// ENDGEN
143
+ |// frag: echo one
144
+ |// frag end
145
145
  EOS
146
146
  frag(option, '//', 'input').must_equal 0
147
147
  (output.string + error.string).must_equal ''
148
148
  File.read('input').must_equal <<-EOS.demargin
149
- |// GEN: echo one
149
+ |// frag: echo one
150
150
  |one
151
- |// ENDGEN
151
+ |// frag end
152
152
  EOS
153
153
  end
154
154
  end
@@ -156,15 +156,15 @@ describe Frag::App do
156
156
  ['-t', '--trailer'].each do |option|
157
157
  it "uses the delimiter trailer given by #{option}" do
158
158
  write_file 'input', <<-EOS.demargin
159
- |# GEN: echo one !!
160
- |# ENDGEN !!
159
+ |# frag: echo one !!
160
+ |# frag end !!
161
161
  EOS
162
162
  frag(option, '!!', 'input').must_equal 0
163
163
  (output.string + error.string).must_equal ''
164
164
  File.read('input').must_equal <<-EOS.demargin
165
- |# GEN: echo one !!
165
+ |# frag: echo one !!
166
166
  |one
167
- |# ENDGEN !!
167
+ |# frag end !!
168
168
  EOS
169
169
  end
170
170
  end
@@ -188,21 +188,21 @@ describe Frag::App do
188
188
  ['-p', '--backup-prefix'].each do |option|
189
189
  it "backs up the input file with the prefix given by #{option}" do
190
190
  write_file 'input', <<-EOS.demargin
191
- |# GEN: echo new
191
+ |# frag: echo new
192
192
  |old
193
- |# ENDGEN
193
+ |# frag end
194
194
  EOS
195
195
  frag(option, 'path/to/backups', 'input').must_equal 0
196
196
  (output.string + error.string).must_equal ''
197
197
  File.read('input').must_equal <<-EOS.demargin
198
- |# GEN: echo new
198
+ |# frag: echo new
199
199
  |new
200
- |# ENDGEN
200
+ |# frag end
201
201
  EOS
202
202
  File.read("path/to/backups/#{File.expand_path('input')}").must_equal <<-EOS.demargin
203
- |# GEN: echo new
203
+ |# frag: echo new
204
204
  |old
205
- |# ENDGEN
205
+ |# frag end
206
206
  EOS
207
207
  end
208
208
  end
@@ -210,57 +210,57 @@ describe Frag::App do
210
210
  ['-s', '--backup-suffix'].each do |option|
211
211
  it "backs up the input file with the suffix given by #{option}" do
212
212
  write_file 'input', <<-EOS.demargin
213
- |# GEN: echo new
213
+ |# frag: echo new
214
214
  |old
215
- |# ENDGEN
215
+ |# frag end
216
216
  EOS
217
217
  frag(option, '.backup', 'input').must_equal 0
218
218
  (output.string + error.string).must_equal ''
219
219
  File.read('input').must_equal <<-EOS.demargin
220
- |# GEN: echo new
220
+ |# frag: echo new
221
221
  |new
222
- |# ENDGEN
222
+ |# frag end
223
223
  EOS
224
224
  File.read('input.backup').must_equal <<-EOS.demargin
225
- |# GEN: echo new
225
+ |# frag: echo new
226
226
  |old
227
- |# ENDGEN
227
+ |# frag end
228
228
  EOS
229
229
  end
230
230
  end
231
231
 
232
232
  it "supports using --backup-prefix and --backup-suffix together" do
233
233
  write_file 'input', <<-EOS.demargin
234
- |# GEN: echo new
234
+ |# frag: echo new
235
235
  |old
236
- |# ENDGEN
236
+ |# frag end
237
237
  EOS
238
238
  frag('-p', 'path/to/backups', '-s', '.backup', 'input').must_equal 0
239
239
  (output.string + error.string).must_equal ''
240
240
  File.read('input').must_equal <<-EOS.demargin
241
- |# GEN: echo new
241
+ |# frag: echo new
242
242
  |new
243
- |# ENDGEN
243
+ |# frag end
244
244
  EOS
245
245
  File.read("path/to/backups/#{File.expand_path('input')}.backup").must_equal <<-EOS.demargin
246
- |# GEN: echo new
246
+ |# frag: echo new
247
247
  |old
248
- |# ENDGEN
248
+ |# frag end
249
249
  EOS
250
250
  end
251
251
 
252
252
  it "does not back up files which produces errors" do
253
253
  write_file 'a', <<-EOS.demargin
254
- |# GEN: true
255
- |# ENDGEN
254
+ |# frag: true
255
+ |# frag end
256
256
  EOS
257
257
  write_file 'b', <<-EOS.demargin
258
- |# GEN: false
259
- |# ENDGEN
258
+ |# frag: false
259
+ |# frag end
260
260
  EOS
261
261
  write_file 'c', <<-EOS.demargin
262
- |# GEN: true
263
- |# ENDGEN
262
+ |# frag: true
263
+ |# frag end
264
264
  EOS
265
265
  frag('-s', '.backup', 'a', 'b', 'c').must_equal 1
266
266
  File.exist?('a.backup').must_equal true
@@ -271,27 +271,27 @@ describe Frag::App do
271
271
 
272
272
  it "prints an error and leaves the input file unchanged if a command fails" do
273
273
  write_file 'input', <<-EOS.demargin
274
- |# GEN: echo new
274
+ |# frag: echo new
275
275
  |old
276
- |# ENDGEN
277
- |# GEN: false
278
- |# ENDGEN
276
+ |# frag end
277
+ |# frag: false
278
+ |# frag end
279
279
  EOS
280
280
  frag('input').must_equal 1
281
281
  output.string.must_equal ''
282
282
  error.string.must_match(/\b4:.*failed/)
283
283
  File.read('input').must_equal <<-EOS.demargin
284
- |# GEN: echo new
284
+ |# frag: echo new
285
285
  |old
286
- |# ENDGEN
287
- |# GEN: false
288
- |# ENDGEN
286
+ |# frag end
287
+ |# frag: false
288
+ |# frag end
289
289
  EOS
290
290
  end
291
291
 
292
292
  it "prints an error if there's an unmatched beginning line" do
293
293
  write_file 'input', <<-EOS.demargin
294
- |# GEN: echo one
294
+ |# frag: echo one
295
295
  EOS
296
296
  frag('input').must_equal 1
297
297
  output.string.must_equal ''
@@ -300,7 +300,7 @@ describe Frag::App do
300
300
 
301
301
  it "prints an error if there's an unmatched ending line" do
302
302
  write_file 'input', <<-EOS.demargin
303
- |# ENDGEN
303
+ |# frag end
304
304
  EOS
305
305
  frag('input').must_equal 1
306
306
  output.string.must_equal ''
@@ -309,36 +309,36 @@ describe Frag::App do
309
309
 
310
310
  it "continues processing other files if one of them produces an error" do
311
311
  write_file 'a', <<-EOS.demargin
312
- |# GEN: echo new
312
+ |# frag: echo new
313
313
  |old
314
- |# ENDGEN
314
+ |# frag end
315
315
  EOS
316
316
  write_file 'b', <<-EOS.demargin
317
- |# GEN: false
317
+ |# frag: false
318
318
  |old
319
- |# ENDGEN
319
+ |# frag end
320
320
  EOS
321
321
  write_file 'c', <<-EOS.demargin
322
- |# GEN: echo new
322
+ |# frag: echo new
323
323
  |old
324
- |# ENDGEN
324
+ |# frag end
325
325
  EOS
326
326
  frag('a', 'b', 'c').must_equal 1
327
327
  output.string.must_equal ''
328
328
  File.read('a').must_equal <<-EOS.demargin
329
- |# GEN: echo new
329
+ |# frag: echo new
330
330
  |new
331
- |# ENDGEN
331
+ |# frag end
332
332
  EOS
333
333
  File.read('b').must_equal <<-EOS.demargin
334
- |# GEN: false
334
+ |# frag: false
335
335
  |old
336
- |# ENDGEN
336
+ |# frag end
337
337
  EOS
338
338
  File.read('c').must_equal <<-EOS.demargin
339
- |# GEN: echo new
339
+ |# frag: echo new
340
340
  |new
341
- |# ENDGEN
341
+ |# frag end
342
342
  EOS
343
343
  end
344
344
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: frag
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -64,7 +64,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
64
64
  version: '0'
65
65
  segments:
66
66
  - 0
67
- hash: 863246519076329498
67
+ hash: -4503615734379659812
68
68
  required_rubygems_version: !ruby/object:Gem::Requirement
69
69
  none: false
70
70
  requirements:
@@ -73,7 +73,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
73
73
  version: '0'
74
74
  segments:
75
75
  - 0
76
- hash: 863246519076329498
76
+ hash: -4503615734379659812
77
77
  requirements: []
78
78
  rubyforge_project:
79
79
  rubygems_version: 1.8.24