auto_freeze 0.1.0
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 +7 -0
- data/README.md +60 -0
- data/lib/auto_freeze/version.rb +5 -0
- data/lib/auto_freeze.rb +37 -0
- metadata +73 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 627d69c77fff17254fa24464b518fa8ec96208cf5e330766aa3025c15ec0fcfe
|
|
4
|
+
data.tar.gz: 729dba1b2e421a9ff38fffe62e3e5e2099aa327a8a27ac54fd0102e6a9dbc5ad
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 5c5a8111c77a08e754dd5a06f7bac526bfe6ae3deeda2e00f4b4cf83e7a60463af03a7945ebac9030549486edb51fe8417af67c1276782a52c4a3b0ea0d1a70e
|
|
7
|
+
data.tar.gz: cc0acbff2058d2b184e64ec3b7dd8bea8286a9d2d48c9252519463645bdcd2d861b4866357deecee1d5b72711a9fc1a884501ace6026336343e570b82b64ddc1
|
data/README.md
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# AutoFreeze
|
|
2
|
+
|
|
3
|
+
Sets the `frozen_string_literal` compile option for your gems.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
1. In your Gemfile, add this:
|
|
8
|
+
|
|
9
|
+
```
|
|
10
|
+
gem 'auto_freeze'
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
2. Run `bundle install` as normal.
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
Before the `Bundler.require` in your application, configure the gems to be
|
|
18
|
+
required with the `frozen_string_literal` compile option set to true.
|
|
19
|
+
By default, all gems are required with frozen strings.
|
|
20
|
+
|
|
21
|
+
```ruby
|
|
22
|
+
AutoFreeze.setup!
|
|
23
|
+
Bundler.require(*Rails.groups)
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
You can exclude certain gems:
|
|
27
|
+
|
|
28
|
+
```ruby
|
|
29
|
+
exclude_gems = %w[
|
|
30
|
+
arr-pm-0.0.12
|
|
31
|
+
email_reply_trimmer-0.1.6
|
|
32
|
+
method_source-1.0.0
|
|
33
|
+
seed-fu-2.3.9
|
|
34
|
+
unicode_utils-1.4.0
|
|
35
|
+
].freeze
|
|
36
|
+
AutoFreeze.setup!(excluded_gems: exclude_gems)
|
|
37
|
+
Bundler.require(*Rails.groups)
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
To only freeze gems you specify, pass an array into `auto_freeze` option:
|
|
41
|
+
|
|
42
|
+
```ruby
|
|
43
|
+
AutoFreeze.setup!(auto_freeze: %w[httpclient-2.9.0])
|
|
44
|
+
Bundler.require(*Rails.groups)
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
AutoFreeze will automatically set `frozen_string_literal` compile option to be
|
|
48
|
+
`true` when that gem is required by Bundler.
|
|
49
|
+
|
|
50
|
+
## Development
|
|
51
|
+
|
|
52
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
|
53
|
+
|
|
54
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
|
55
|
+
|
|
56
|
+
## Thanks
|
|
57
|
+
|
|
58
|
+
Thanks to
|
|
59
|
+
<https://evilmartians.com/chronicles/freezolite-the-magic-gem-for-keeping-ruby-literals-safely-frozen>
|
|
60
|
+
for the research showing that it was possible to dynamically enable the `frozen_string_literal` option.
|
data/lib/auto_freeze.rb
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "auto_freeze/version"
|
|
4
|
+
require 'freezolite'
|
|
5
|
+
|
|
6
|
+
# Set frozen_string_literals: true when requiring gems.
|
|
7
|
+
module AutoFreeze
|
|
8
|
+
class << self
|
|
9
|
+
def setup!(auto_freeze: true, excluded_gems: [])
|
|
10
|
+
# Freezolite uses File.fnmatch for its patterns.
|
|
11
|
+
# It also uses load_iseq(<absolute_path>) callback for its around hook.
|
|
12
|
+
# So to freeze gem, we need to find the absolute path using `Gem.path`.
|
|
13
|
+
include_patterns = if auto_freeze.is_a?(Array)
|
|
14
|
+
auto_freeze.flat_map do |gem|
|
|
15
|
+
Gem::Specification.find_by_full_name(gem).full_require_paths.map do |require_path|
|
|
16
|
+
File.join(require_path, "*.rb")
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
else
|
|
20
|
+
Gem.path.map { |path| File.join(path, "*.rb") }
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
exclude_patterns = excluded_gems.map { |gem_name| File.join("**", gem_name, "**") }
|
|
24
|
+
|
|
25
|
+
freezolite_setup(
|
|
26
|
+
patterns: include_patterns,
|
|
27
|
+
exclude_patterns: exclude_patterns
|
|
28
|
+
)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
private
|
|
32
|
+
|
|
33
|
+
def freezolite_setup(**kwargs)
|
|
34
|
+
Freezolite.setup(**kwargs)
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: auto_freeze
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Thong Kuah
|
|
8
|
+
bindir: bin
|
|
9
|
+
cert_chain: []
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
|
+
dependencies:
|
|
12
|
+
- !ruby/object:Gem::Dependency
|
|
13
|
+
name: freezolite
|
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
|
15
|
+
requirements:
|
|
16
|
+
- - "~>"
|
|
17
|
+
- !ruby/object:Gem::Version
|
|
18
|
+
version: '0.6'
|
|
19
|
+
type: :runtime
|
|
20
|
+
prerelease: false
|
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
22
|
+
requirements:
|
|
23
|
+
- - "~>"
|
|
24
|
+
- !ruby/object:Gem::Version
|
|
25
|
+
version: '0.6'
|
|
26
|
+
- !ruby/object:Gem::Dependency
|
|
27
|
+
name: gitlab-styles
|
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
|
29
|
+
requirements:
|
|
30
|
+
- - "~>"
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: '14.0'
|
|
33
|
+
type: :development
|
|
34
|
+
prerelease: false
|
|
35
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
36
|
+
requirements:
|
|
37
|
+
- - "~>"
|
|
38
|
+
- !ruby/object:Gem::Version
|
|
39
|
+
version: '14.0'
|
|
40
|
+
description: Allows you to select specific gems to be required with `frozen_string_literal`
|
|
41
|
+
set to true.
|
|
42
|
+
email:
|
|
43
|
+
- tkuah@gitlab.com
|
|
44
|
+
executables: []
|
|
45
|
+
extensions: []
|
|
46
|
+
extra_rdoc_files: []
|
|
47
|
+
files:
|
|
48
|
+
- README.md
|
|
49
|
+
- lib/auto_freeze.rb
|
|
50
|
+
- lib/auto_freeze/version.rb
|
|
51
|
+
homepage: https://gitlab.com/gitlab-org/gitlab/-/tree/master/gems/auto_freeze
|
|
52
|
+
licenses:
|
|
53
|
+
- MIT
|
|
54
|
+
metadata:
|
|
55
|
+
rubygems_mfa_required: 'true'
|
|
56
|
+
rdoc_options: []
|
|
57
|
+
require_paths:
|
|
58
|
+
- lib
|
|
59
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
60
|
+
requirements:
|
|
61
|
+
- - ">="
|
|
62
|
+
- !ruby/object:Gem::Version
|
|
63
|
+
version: '3.0'
|
|
64
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - ">="
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: '0'
|
|
69
|
+
requirements: []
|
|
70
|
+
rubygems_version: 4.0.10
|
|
71
|
+
specification_version: 4
|
|
72
|
+
summary: Sets the `frozen_string_literal` compile option for your gems.
|
|
73
|
+
test_files: []
|