aye_var 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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 13bedf4da163ee9b20c83ed235f78825ced3e3a6547abc98af2de5e08d06401c
4
+ data.tar.gz: 4cbc787d135c70ea6c1b725ad01af3c2be374959fb1a52667f9db6271e458b32
5
+ SHA512:
6
+ metadata.gz: eb4d35e722d2f31d4953a03687421c18b1aea499e69e77ef614285622e41e8ab23c0422b6649dfad1e54066d77362ccad1a5851c3f2a9a1a7dafe6bf44fc877f
7
+ data.tar.gz: bd303daa537463d610e8b37b356e3bc44e8bd46e4e4734acc58b24ca3a262748ae39e2169cbe328b3daddf4bd84767d94514fd6ed7ebdd54aa1ad980da4a8a4a
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2025 Joel Drapper
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,19 @@
1
+ ## AyeVar
2
+
3
+ Note, this gem is very new and experimental. The API will probably change.
4
+
5
+ Add this gem to your gemfile.
6
+
7
+ ```ruby
8
+ gem "aye_var", require: false
9
+ ```
10
+
11
+ Then require and initialize it in your app as early as possible. If you’re using Bootsnap, it should be right after Bootsnap.
12
+
13
+ ```ruby
14
+ require "aye_var"
15
+
16
+ AyeVar.init(include: ["#{Dir.pwd}/**/*"])
17
+ ```
18
+
19
+ You can pass in an array of globs to `include:` and `exclude:`.
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AyeVar
4
+ VERSION = "0.1.0"
5
+ end
data/lib/aye_var.rb ADDED
@@ -0,0 +1,77 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "require-hooks/setup"
4
+
5
+ module AyeVar
6
+ class Processor < Prism::Visitor
7
+ def self.call(source)
8
+ object = new(source)
9
+ object.visit(Prism.parse(source).value)
10
+
11
+ buffer = source.dup
12
+
13
+ object.ivars.sort_by(&:first).reverse_each do |offset, action, name|
14
+ case action
15
+ when :start
16
+ buffer.insert(offset, "((raise ::AyeVar::NameError.new('Undefined instance variable #{name}') unless defined?(#{name}));")
17
+ when :end
18
+ buffer.insert(offset, ")")
19
+ end
20
+ end
21
+
22
+ buffer
23
+ end
24
+
25
+ def initialize(source)
26
+ @initializer = false
27
+ @ivars = []
28
+ end
29
+
30
+ attr_reader :ivars
31
+
32
+ def visit_def_node(node)
33
+ if node.name == :initialize
34
+ begin
35
+ @initializer = true
36
+ super
37
+ ensure
38
+ @initializer = false
39
+ end
40
+ else
41
+ super
42
+ end
43
+ end
44
+
45
+ def visit_instance_variable_read_node(node)
46
+ location = node.location
47
+ name = node.name
48
+
49
+ @ivars << [location.start_character_offset, :start, name]
50
+ @ivars << [location.end_character_offset, :end, name]
51
+ super
52
+ end
53
+
54
+ def visit_instance_variable_write_node(node)
55
+ unless @initializer
56
+ location = node.location
57
+ name = node.name
58
+
59
+ @ivars << [location.start_character_offset, :start, name]
60
+ @ivars << [location.end_character_offset, :end, name]
61
+ end
62
+
63
+ super
64
+ end
65
+ end
66
+
67
+ private_constant :Processor
68
+
69
+ NameError = Class.new(::NameError)
70
+
71
+ def self.init(include: [], exclude: [])
72
+ RequireHooks.source_transform(patterns: include, exclude_patterns: exclude) do |path, source|
73
+ source ||= File.read(path)
74
+ Processor.call(source)
75
+ end
76
+ end
77
+ end
metadata ADDED
@@ -0,0 +1,62 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: aye_var
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Joel Drapper
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: require-hooks
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - ">="
17
+ - !ruby/object:Gem::Version
18
+ version: '0'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - ">="
24
+ - !ruby/object:Gem::Version
25
+ version: '0'
26
+ description: Raise an exception when using undefined instance variables.
27
+ email:
28
+ - joel@drapper.me
29
+ executables: []
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - LICENSE.txt
34
+ - README.md
35
+ - lib/aye_var.rb
36
+ - lib/aye_var/version.rb
37
+ homepage: https://github.com/joeldrapper/aye_var
38
+ licenses:
39
+ - MIT
40
+ metadata:
41
+ homepage_uri: https://github.com/joeldrapper/aye_var
42
+ source_code_uri: https://github.com/joeldrapper/aye_var
43
+ funding_uri: https://github.com/sponsors/joeldrapper
44
+ rubygems_mfa_required: 'true'
45
+ rdoc_options: []
46
+ require_paths:
47
+ - lib
48
+ required_ruby_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: '3.1'
53
+ required_rubygems_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
58
+ requirements: []
59
+ rubygems_version: 3.6.7
60
+ specification_version: 4
61
+ summary: Raise an exception when using undefined instance variables.
62
+ test_files: []