magic_frozen_string_literal 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/add_magic_comment.rb +14 -22
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9f4a7f937c5bdae40737a09dc33c88db763840be
|
4
|
+
data.tar.gz: 722fb36293bf02e654b3fcf81114c8219c433d7b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b6e58b53690c83f77b75bd8e0f3fb44df88770e85e9cdb0f2effb59bc8a47e10a1d65d2fc427feec31f84fe9ed5ff914c53864e1de9b2c46832865d192c2c8f4
|
7
|
+
data.tar.gz: 539915a742a2ec149f110fd7126614d656840df65f1eeca3125e8d8121c4a33ce31c2d2fb275b4d461cadb2c8dedde19689cba8f964770a3f71a83e06772947a
|
data/lib/add_magic_comment.rb
CHANGED
@@ -1,45 +1,37 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# A simple library to prepend magic comments to
|
3
|
+
# A simple library to prepend magic comments to all Ruby files in a given folder
|
4
4
|
|
5
5
|
module AddMagicComment
|
6
6
|
MAGIC_COMMENT_PREFIX = "frozen_string_literal"
|
7
|
-
MAGIC_COMMENT_PATTERN =
|
7
|
+
MAGIC_COMMENT_PATTERN = /^(-|(<%))?#\s*#{MAGIC_COMMENT_PREFIX}\s*(%>)?/
|
8
8
|
MAGIC_COMMENT = "#{MAGIC_COMMENT_PREFIX}: true"
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
10
|
+
EXTENSION_COMMENTS = {
|
11
|
+
"rb" => "# #{MAGIC_COMMENT}",
|
12
|
+
"rake" => "# #{MAGIC_COMMENT}",
|
13
|
+
"haml" => "-# #{MAGIC_COMMENT}",
|
14
|
+
"erb" => "<%# #{MAGIC_COMMENT} %>"
|
14
15
|
}
|
15
16
|
|
16
|
-
|
17
|
-
|
18
|
-
# 2 : Path
|
19
|
-
# TODO : check that the encoding specified is a valid encoding
|
20
|
-
# TODO : allow use of only one option, so the encoding would be guessed (maybe using `file --mime`?)
|
21
|
-
def self.process(options)
|
22
|
-
|
23
|
-
directory = options[0] || Dir.pwd
|
24
|
-
|
25
|
-
|
26
|
-
# TODO : add options for recursivity (and application of the script to a single file)
|
17
|
+
def self.process(argv)
|
18
|
+
directory = argv.first || Dir.pwd
|
27
19
|
|
28
20
|
count = 0
|
29
|
-
|
30
|
-
|
31
|
-
Dir.glob(
|
21
|
+
EXTENSION_COMMENTS.each do |ext, comment|
|
22
|
+
filename_pattern = File.join(directory, "**", "*.#{ext}")
|
23
|
+
Dir.glob(filename_pattern).each do |filename|
|
32
24
|
next unless File.size(filename) > 0
|
33
25
|
File.open(filename, "r+") do |file|
|
34
26
|
lines = file.readlines
|
35
27
|
|
36
28
|
# remove current encoding comment(s)
|
37
|
-
while lines
|
29
|
+
while lines.first && lines.first.match(MAGIC_COMMENT_PATTERN)
|
38
30
|
lines.shift
|
39
31
|
end
|
40
32
|
|
41
33
|
# set current encoding
|
42
|
-
lines.insert(0,
|
34
|
+
lines.insert(0, comment + "\n")
|
43
35
|
count += 1
|
44
36
|
|
45
37
|
file.pos = 0
|
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: 0.0.
|
4
|
+
version: 0.0.4
|
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:
|
11
|
+
date: 2016-02-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -68,12 +68,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
68
68
|
requirements:
|
69
69
|
- - ">="
|
70
70
|
- !ruby/object:Gem::Version
|
71
|
-
version:
|
71
|
+
version: '0'
|
72
72
|
requirements: []
|
73
73
|
rubyforge_project:
|
74
74
|
rubygems_version: 2.2.2
|
75
75
|
signing_key:
|
76
76
|
specification_version: 4
|
77
|
-
summary: 'Easily add magic comments ''# frozen_string_literal: true''
|
78
|
-
|
77
|
+
summary: 'Easily add magic comments ''# frozen_string_literal: true'' to multiple
|
78
|
+
Ruby source files'
|
79
79
|
test_files: []
|