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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7260804a0ee8714a348bba3207f9ed391591c74d
4
- data.tar.gz: 8597342b0aca99fa0c1b2dde2593d5a06642fa6d
3
+ metadata.gz: f9e4cc8192139393c7fbf2247b1ee9b4a696aed7
4
+ data.tar.gz: ba2e0a11b25db29bf1a5f3004eb09609cbe96b30
5
5
  SHA512:
6
- metadata.gz: 99262c5f8b66aa88d89790a594ba42ac3a14f6c42216ab0ccbb578d3c4af60664e076ea00701fd95aae645310f2eeb41cd1a575c17692e1d48685be75b40c4f2
7
- data.tar.gz: f9530d1daa881c2bc7646691368a0fd6336ffe9f5292724e161312fd075b4a919274b4bdaec47c67a7d30d63d21af076f851d29901f39e3edfd0f3d8072574f4
6
+ metadata.gz: 749667b89bed4a12cdec07c64d832dbbd28170a5cec0f7bf7d3a6ad344c4389a235e4c1cde7cded2a7bd8e737676a84b951bcc71c61fdc70beb2558eafbe7597
7
+ data.tar.gz: 556de823f9e8b1e7ede7f50f7508ce8d408d96e3abce625d2233b15444cc35846f8d037017f7f2ed4a9ed5c1706a9c060de9e5abe4652ee0ac9e68b1e7e2857d
@@ -15,9 +15,12 @@ module Stamper
15
15
  def self.stamp(opts)
16
16
  opts = DEFAULTS.merge(opts)
17
17
 
18
- stamp, files = opts[:stamp], Dir.glob(opts[:files])
19
- includes, excludes = opts[:includes], opts[:excludes]
20
- respect_first_marks, dryrun = opts[:respect_first_marks], opts[:dryrun]
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| Regexp.new(include).match(file) }
33
- next if excludes.any? { |exclude| Regexp.new(exclude).match(file) }
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| Regexp.new(mark).match(contents.first) }
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
@@ -1,3 +1,3 @@
1
1
  module Stamper
2
- VERSION = '0.1.0'
2
+ VERSION = '0.1.1'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stamper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Renier Morales