magic_frozen_string_literal 0.0.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f3d4cf03b86472104ca49183f5166a4f2f990539
4
+ data.tar.gz: 52df99a2ea7dc7a14db1dcfbb73600715a44560e
5
+ SHA512:
6
+ metadata.gz: 59fc7a3c9f698ed9e01fe06d1069869f63c4535fd9215e19af0efdce9021381bda32e0b4cae8ef70416c264abd3eac1f6852abe6bdaaca68efa8dc0df149df85
7
+ data.tar.gz: 381a8847c20c6c1a95c5c8ef9e3298e75baa098429bb7032d3b87c5b68cf91393cfed8f79397074dafa81852a6f2bb46551d5ffacba5d8e4c4541fecb6ef7953
data/CHANGELOG ADDED
@@ -0,0 +1,8 @@
1
+ ## 0.0.1 (August 3, 2010)
2
+
3
+ Initial Version
4
+
5
+ ## 0.0.2 (August 3, 2010)
6
+
7
+ Existing magic comments are now erased before the file is prepended with the desired magic comment
8
+ Bugfixes
data/LICENCE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 Manuel Ryan
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,25 @@
1
+ = Magic_frozen_string_literal
2
+
3
+ Magic_frozen_string_literal is a little tool that allows you to quickly
4
+ add the magic comment that indicates that the file
5
+ can safely have its string literals frozen, as will be {the default in Ruby 3.0}[https://bugs.ruby-lang.org/issues/8976].
6
+
7
+ Cloned from https://github.com/m-ryan/magic_encoding
8
+
9
+ == Installation
10
+
11
+ gem install magic_frozen_string_literal
12
+
13
+ == Usage
14
+
15
+ you can call the tool from the console with default parameters like so
16
+
17
+ magic_frozen_string_literal
18
+
19
+ this will prepend every ".rb" file in the working directory (recursively) with the following line:
20
+
21
+ # frozen_string_literal: true
22
+
23
+ Notes:
24
+ - existing frozen_string_literal magic comments are replaced
25
+ - the rest of the file remains unchanged
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # A simple tool to prepend magic '# frozen_string_literal: true' comments to multiple ".rb" files
4
+
5
+ require 'add_magic_comment'
6
+
7
+ AddMagicComment.process(ARGV)
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ # A simple library to prepend magic comments to multiple ".rb" files
4
+
5
+ module AddMagicComment
6
+ MAGIC_COMMENT_PREFIX = "frozen_string_literal"
7
+ MAGIC_COMMENT_PATTERN = /^-?# *#{MAGIC_COMMENT_PREFIX}/
8
+ MAGIC_COMMENT = "#{MAGIC_COMMENT_PREFIX}: true"
9
+
10
+ EXTENSIONS = {
11
+ 'rb' => '# {text}',
12
+ 'rake' => '# {text}',
13
+ 'haml' => '-# {text}',
14
+ }
15
+
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)
27
+
28
+ count = 0
29
+ EXTENSIONS.each do |ext, comment_style|
30
+ rbfiles = File.join(directory, "**", "*.#{ext}")
31
+ Dir.glob(rbfiles).each do |filename|
32
+ File.open(filename, "r+") do |file|
33
+ lines = file.readlines
34
+
35
+ # remove current encoding comment(s)
36
+ while lines[0].match(MAGIC_COMMENT_PATTERN)
37
+ lines.shift
38
+ end
39
+
40
+ # set current encoding
41
+ lines.insert(0, comment_style.sub('{text}', MAGIC_COMMENT + "\n"))
42
+ count += 1
43
+
44
+ file.pos = 0
45
+ file.puts(lines.join)
46
+ end
47
+ end
48
+ end
49
+
50
+ puts "Magic comments added to #{count} source file(s)"
51
+ end
52
+ end
metadata ADDED
@@ -0,0 +1,79 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: magic_frozen_string_literal
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Colin Kelley after Jared Roesch after Manuel Ryan
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-08-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description:
42
+ email:
43
+ - colin@invoca.com
44
+ executables:
45
+ - magic_frozen_string_literal
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - CHANGELOG
50
+ - LICENCE
51
+ - README.rdoc
52
+ - bin/magic_frozen_string_literal
53
+ - lib/add_magic_comment.rb
54
+ homepage: https://github.com/Invoca/magic_frozen_string_literal
55
+ licenses:
56
+ - MIT
57
+ metadata: {}
58
+ post_install_message:
59
+ rdoc_options: []
60
+ require_paths:
61
+ - lib
62
+ required_ruby_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ required_rubygems_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: 1.3.6
72
+ requirements: []
73
+ rubyforge_project:
74
+ rubygems_version: 2.2.2
75
+ signing_key:
76
+ specification_version: 4
77
+ summary: 'Easily add magic comments ''# frozen_string_literal: true'' on multiple
78
+ ruby source files'
79
+ test_files: []