magic_frozen_string_literal 1.0.3 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +5 -5
  2. data/lib/add_magic_comment.rb +8 -3
  3. metadata +4 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 5cc218e8ed019adeb44ec55707d070d919910ff9
4
- data.tar.gz: 508018b7728a2ed542bd84e140233c889edd9dbb
2
+ SHA256:
3
+ metadata.gz: 5945cb069e07e1dc2c7571ccb24900abdeff34bdd05e7438e0afcd273f53b680
4
+ data.tar.gz: 1ff3e7a3ae7be09b82abee150629aac36eab5f6fb65fe4a39b0286b0dfb927fa
5
5
  SHA512:
6
- metadata.gz: 67cc158ee216847d3bcedc1ef1dd7fd93b5665f5c9c17fe928c27a5a189652862662cf0ce12dcf5ed1237319f3fb42fe5bf2aa9f7b27fe57ef74e0e653cd3930
7
- data.tar.gz: f033fe0afc62e06bda1fd2075b390ca1cddd78a7561ab141064f87427cf93808a12d6750fa5552f07b28e3150d973d1d821ab42956e7bbd0828dcc14493b1db1
6
+ metadata.gz: dc1f1eea9f8f6ecad0718100c37b63dc9dda12b70091e3f98aa6919fce991126b248a59b1bfb72bcf9939edbe355b55d0acf24053b2c6dce5e007683ead92706
7
+ data.tar.gz: a55071f8fd05e661a5eafe1195c77a93cced96a7fa6678c614fd3386047cd580b4c0d4a32361e71c9c5d958399b94a142327b773d09d2691892d887595b5e5dd
@@ -28,8 +28,9 @@ module AddMagicComment
28
28
  EXTENSION_COMMENTS.each do |pattern, comment|
29
29
  filename_pattern = File.join(directory, "**", "#{pattern}")
30
30
  Dir.glob(filename_pattern).each do |filename|
31
- File.open(filename, "r+") do |file|
31
+ File.open(filename, "rb+") do |file|
32
32
  lines = file.readlines
33
+ newline = detect_newline(lines.first)
33
34
  next unless lines.any?
34
35
  count += 1
35
36
 
@@ -43,7 +44,7 @@ module AddMagicComment
43
44
  end
44
45
 
45
46
  # add magic comment as the first line
46
- lines.unshift(comment)
47
+ lines.unshift(comment.gsub("\n", newline))
47
48
 
48
49
  # put shebang back
49
50
  if shebang
@@ -51,7 +52,7 @@ module AddMagicComment
51
52
  end
52
53
 
53
54
  file.pos = 0
54
- file.puts(lines.join)
55
+ file.print(*lines)
55
56
  file.truncate(file.pos)
56
57
  end
57
58
  end
@@ -59,4 +60,8 @@ module AddMagicComment
59
60
 
60
61
  puts "Magic comments added to #{count} source file(s)"
61
62
  end
63
+
64
+ def self.detect_newline(line)
65
+ (line[/\R/] if line) || $/
66
+ end
62
67
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: magic_frozen_string_literal
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Colin Kelley after Jared Roesch after Manuel Ryan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-01-18 00:00:00.000000000 Z
11
+ date: 2019-03-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -39,7 +39,7 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: '10.0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: rspec-core
42
+ name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
@@ -84,7 +84,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
84
84
  version: '0'
85
85
  requirements: []
86
86
  rubyforge_project:
87
- rubygems_version: 2.2.2
87
+ rubygems_version: 2.7.6
88
88
  signing_key:
89
89
  specification_version: 4
90
90
  summary: 'Easily add magic comments ''# frozen_string_literal: true'' followed by