freeze_the_lits 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +9 -0
- data/LICENSE.txt +23 -0
- data/README.md +65 -0
- data/lib/freeze_the_lits/auto.rb +3 -0
- data/lib/freeze_the_lits/iseq_mixin.rb +19 -0
- data/lib/freeze_the_lits/version.rb +5 -0
- data/lib/freeze_the_lits.rb +14 -0
- metadata +97 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: cd11e050953af220f5cf8e23060c68e4cc857641c0bab81f38bf031db29e8e86
|
4
|
+
data.tar.gz: 24a282e9a2e444ced802a5521d2005ec6ba100a08188e7d654804e9f5bbbcfe3
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2268fdb71dc02d3284db454b1a46cf6d7ef83c2b3c2c666231ff56201d4e31d756f820a96a5f7363aa1fcfd58a890697a0e6df6cb0ac88f08a563cf915d1cb68
|
7
|
+
data.tar.gz: 8b645210b6b9ef36c3f785372104679c033c8c4dea7d748ec30dd377a16cb6f9eced9a91ed760201c21ca94bf3a39934885945466aa95097bd3c3ccba8511c26
|
data/CHANGELOG.md
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
Copyright (c) 2023 Vladimir Dementyev
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
23
|
+
|
data/README.md
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
[![Gem Version](https://badge.fury.io/rb/freeze_the_lits.svg)](https://rubygems.org/gems/freeze_the_lits)
|
2
|
+
[![Build](https://github.com/ruby-next/freeze_the_lits/workflows/Build/badge.svg)](https://github.com/palkan/freeze_the_lits/actions)
|
3
|
+
|
4
|
+
# Freeze the Lits ❄️
|
5
|
+
|
6
|
+
Tired of adding `# frozen_string_literals: true` to every file in your project or running `rubocop -A` to make it do that for you? What if I told you that you can just add a single gem to your project and activate this option **for the project's files** automatically (without enabling it globally)?
|
7
|
+
|
8
|
+
FreezeTheLits is a gem that turn the `frozen_string_literal` compile option on only for the specified files. Thus, it's like running Ruby with `--enable=frozen-string-literal` but only for the files you own.
|
9
|
+
|
10
|
+
## Usage
|
11
|
+
|
12
|
+
Add the gem to your Gemfile:
|
13
|
+
|
14
|
+
```ruby
|
15
|
+
gem "freeze_the_lits"
|
16
|
+
```
|
17
|
+
|
18
|
+
And drop the following line to your application entrypoint (e.g., `config/boot.rb` for Rails):
|
19
|
+
|
20
|
+
```ruby
|
21
|
+
require "freeze_the_lits/auto"
|
22
|
+
```
|
23
|
+
|
24
|
+
By default, the gem uses `Dir.pwd` to determine the project root. If you want to use a different directory or multiple directories, configure the gem like this:
|
25
|
+
|
26
|
+
```ruby
|
27
|
+
require "freeze_the_lits"
|
28
|
+
|
29
|
+
FreezeTheLits.setup(
|
30
|
+
watch_dirs: ["/path/to/dir1", "/path/to/dir2"]
|
31
|
+
)
|
32
|
+
```
|
33
|
+
|
34
|
+
### Using with Bootsnap
|
35
|
+
|
36
|
+
FreezeTheList is compatible with Bootsnap. Just make sure you require it **after** Bootsnap:
|
37
|
+
|
38
|
+
```ruby
|
39
|
+
# config/boot.rb
|
40
|
+
|
41
|
+
require "bootsnap/setup"
|
42
|
+
require "freeze_the_lits/auto"
|
43
|
+
require "bundler/setup
|
44
|
+
```
|
45
|
+
|
46
|
+
### Using in tests
|
47
|
+
|
48
|
+
Usually, when we load tests we use different entry-points. Thus, we need to require the gem in each of them. For example, in Rails, we need to require it in `test_helper.rb` and `rails_helper.rb`:
|
49
|
+
|
50
|
+
```ruby
|
51
|
+
require "freeze_the_lits/auto"
|
52
|
+
```
|
53
|
+
|
54
|
+
### Supported Ruby versions
|
55
|
+
|
56
|
+
- Ruby (MRI) >= 2.7.0
|
57
|
+
|
58
|
+
## Contributing
|
59
|
+
|
60
|
+
Bug reports and pull requests are welcome on GitHub at [https://github.com/ruby-next/freeze_the_lits](https://github.com/ruby-next/freeze_the_lits).
|
61
|
+
|
62
|
+
|
63
|
+
## License
|
64
|
+
|
65
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module FreezeTheLits
|
2
|
+
module IseqMixin
|
3
|
+
def load_iseq(path)
|
4
|
+
was_frozen_string_literal = RubyVM::InstructionSequence.compile_option[:frozen_string_literal]
|
5
|
+
|
6
|
+
if FreezeTheLits.watch_dirs.any? { |dir| path.start_with?(dir) }
|
7
|
+
RubyVM::InstructionSequence.compile_option = {frozen_string_literal: true}
|
8
|
+
|
9
|
+
defined?(super) ? super : RubyVM::InstructionSequence.compile_file(path)
|
10
|
+
else
|
11
|
+
defined?(super) ? super : nil
|
12
|
+
end
|
13
|
+
ensure
|
14
|
+
RubyVM::InstructionSequence.compile_option = {frozen_string_literal: was_frozen_string_literal}
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
RubyVM::InstructionSequence.singleton_class.prepend(FreezeTheLits::IseqMixin)
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "freeze_the_lits/version"
|
4
|
+
|
5
|
+
module FreezeTheLits
|
6
|
+
class << self
|
7
|
+
attr_accessor :watch_dirs
|
8
|
+
|
9
|
+
def setup(watch_dirs:)
|
10
|
+
self.watch_dirs = watch_dirs.freeze
|
11
|
+
require "freeze_the_lits/iseq_mixin"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
metadata
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: freeze_the_lits
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Vladimir Dementyev
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2023-06-15 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.15'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.15'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '13.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '13.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '5.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '5.0'
|
55
|
+
description: Example description
|
56
|
+
email:
|
57
|
+
- Vladimir Dementyev
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- CHANGELOG.md
|
63
|
+
- LICENSE.txt
|
64
|
+
- README.md
|
65
|
+
- lib/freeze_the_lits.rb
|
66
|
+
- lib/freeze_the_lits/auto.rb
|
67
|
+
- lib/freeze_the_lits/iseq_mixin.rb
|
68
|
+
- lib/freeze_the_lits/version.rb
|
69
|
+
homepage: https://github.com/ruby-next/freeze_the_lits
|
70
|
+
licenses:
|
71
|
+
- MIT
|
72
|
+
metadata:
|
73
|
+
bug_tracker_uri: https://github.com/ruby-next/freeze_the_lits/issues
|
74
|
+
changelog_uri: https://github.com/ruby-next/freeze_the_lits/blob/master/CHANGELOG.md
|
75
|
+
documentation_uri: https://github.com/ruby-next/freeze_the_lits
|
76
|
+
homepage_uri: https://github.com/ruby-next/freeze_the_lits
|
77
|
+
source_code_uri: https://github.com/ruby-next/freeze_the_lits
|
78
|
+
post_install_message:
|
79
|
+
rdoc_options: []
|
80
|
+
require_paths:
|
81
|
+
- lib
|
82
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
83
|
+
requirements:
|
84
|
+
- - ">="
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: '2.7'
|
87
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - ">="
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
92
|
+
requirements: []
|
93
|
+
rubygems_version: 3.4.8
|
94
|
+
signing_key:
|
95
|
+
specification_version: 4
|
96
|
+
summary: Example description
|
97
|
+
test_files: []
|