magic_frozen_string_literal 0.0.3 → 0.0.4

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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/add_magic_comment.rb +14 -22
  3. metadata +5 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5271e012fd545661378c77a655a973dcf5784742
4
- data.tar.gz: 37ed692a99df681f6d044b9d5042ece055552105
3
+ metadata.gz: 9f4a7f937c5bdae40737a09dc33c88db763840be
4
+ data.tar.gz: 722fb36293bf02e654b3fcf81114c8219c433d7b
5
5
  SHA512:
6
- metadata.gz: 7381678e8e283f22e3648c4a9a80fc6828b703c5d04cd0bbb5578cbc651e288a1f88d5c4497eaed6c0b96a8f2d861bc3d43cc23f64f1591fd29ec72d66d35015
7
- data.tar.gz: b50bac58839c7995482ede8a117666f627212506d25a459572c06d47855285a56e0678c56187354f6b5728cb4fe6359c8d6f164e1b9404c9a78545797901dbf2
6
+ metadata.gz: b6e58b53690c83f77b75bd8e0f3fb44df88770e85e9cdb0f2effb59bc8a47e10a1d65d2fc427feec31f84fe9ed5ff914c53864e1de9b2c46832865d192c2c8f4
7
+ data.tar.gz: 539915a742a2ec149f110fd7126614d656840df65f1eeca3125e8d8121c4a33ce31c2d2fb275b4d461cadb2c8dedde19689cba8f964770a3f71a83e06772947a
@@ -1,45 +1,37 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # A simple library to prepend magic comments to multiple ".rb" files
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 = /^-?# *#{MAGIC_COMMENT_PREFIX}/
7
+ MAGIC_COMMENT_PATTERN = /^(-|(<%))?#\s*#{MAGIC_COMMENT_PREFIX}\s*(%>)?/
8
8
  MAGIC_COMMENT = "#{MAGIC_COMMENT_PREFIX}: true"
9
9
 
10
- EXTENSIONS = {
11
- 'rb' => '# {text}',
12
- 'rake' => '# {text}',
13
- 'haml' => '-# {text}',
10
+ EXTENSION_COMMENTS = {
11
+ "rb" => "# #{MAGIC_COMMENT}",
12
+ "rake" => "# #{MAGIC_COMMENT}",
13
+ "haml" => "-# #{MAGIC_COMMENT}",
14
+ "erb" => "<%# #{MAGIC_COMMENT} %>"
14
15
  }
15
16
 
16
- # Options :
17
- # 1 : Encoding
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
- EXTENSIONS.each do |ext, comment_style|
30
- rbfiles = File.join(directory, "**", "*.#{ext}")
31
- Dir.glob(rbfiles).each do |filename|
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[0].match(MAGIC_COMMENT_PATTERN)
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, comment_style.sub('{text}', MAGIC_COMMENT + "\n"))
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.3
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: 2015-08-21 00:00:00.000000000 Z
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: 1.3.6
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'' on multiple
78
- ruby source files'
77
+ summary: 'Easily add magic comments ''# frozen_string_literal: true'' to multiple
78
+ Ruby source files'
79
79
  test_files: []