stamper 0.1.0 → 0.1.1
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.
- checksums.yaml +4 -4
- data/lib/stamper.rb +12 -6
- data/lib/stamper/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f9e4cc8192139393c7fbf2247b1ee9b4a696aed7
|
4
|
+
data.tar.gz: ba2e0a11b25db29bf1a5f3004eb09609cbe96b30
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 749667b89bed4a12cdec07c64d832dbbd28170a5cec0f7bf7d3a6ad344c4389a235e4c1cde7cded2a7bd8e737676a84b951bcc71c61fdc70beb2558eafbe7597
|
7
|
+
data.tar.gz: 556de823f9e8b1e7ede7f50f7508ce8d408d96e3abce625d2233b15444cc35846f8d037017f7f2ed4a9ed5c1706a9c060de9e5abe4652ee0ac9e68b1e7e2857d
|
data/lib/stamper.rb
CHANGED
@@ -15,9 +15,12 @@ module Stamper
|
|
15
15
|
def self.stamp(opts)
|
16
16
|
opts = DEFAULTS.merge(opts)
|
17
17
|
|
18
|
-
stamp
|
19
|
-
|
20
|
-
|
18
|
+
stamp = opts[:stamp]
|
19
|
+
files = opts[:files].is_a?(Array) ? opts[:files] : Dir.glob(opts[:files])
|
20
|
+
includes = opts[:includes].map { |i| Regexp.new(i) }
|
21
|
+
excludes = opts[:excludes].map { |e| Regexp.new(e) }
|
22
|
+
respect_first_marks = opts[:respect_first_marks].map { |m| Regexp.new(m) }
|
23
|
+
dryrun = opts[:dryrun]
|
21
24
|
quiet = opts[:quiet]
|
22
25
|
|
23
26
|
if dryrun
|
@@ -29,8 +32,8 @@ module Stamper
|
|
29
32
|
stamped = 0
|
30
33
|
# For each file that matches pattern(s)
|
31
34
|
files.each do |file|
|
32
|
-
next unless includes.any? { |include|
|
33
|
-
next if excludes.any? { |exclude|
|
35
|
+
next unless includes.any? { |include| include.match(file) }
|
36
|
+
next if excludes.any? { |exclude| exclude.match(file) }
|
34
37
|
|
35
38
|
# Check the header of the file. Match on first lines or shifted by one line.
|
36
39
|
# If match, do nothing, else stamp file (or report only -- use colorize).
|
@@ -46,13 +49,16 @@ module Stamper
|
|
46
49
|
next
|
47
50
|
end
|
48
51
|
|
49
|
-
if respect_first_marks.any? { |mark|
|
52
|
+
if respect_first_marks.any? { |mark| mark.match(contents.first) }
|
50
53
|
shifted = contents.shift
|
51
54
|
contents = shifted + "\n" + stamp + contents.join("\n")
|
52
55
|
else
|
53
56
|
contents = stamp + contents.join("\n")
|
54
57
|
end
|
55
58
|
|
59
|
+
# Make sure files have a new line at the end of the file
|
60
|
+
contents += "\n" if contents[-1] != "\n"
|
61
|
+
|
56
62
|
IO.write(file, contents)
|
57
63
|
stamped += 1
|
58
64
|
puts file unless quiet
|
data/lib/stamper/version.rb
CHANGED