aye_var 0.1.1 → 0.2.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 +4 -4
- data/README.md +5 -7
- data/lib/aye_var/version.rb +1 -1
- data/lib/aye_var.rb +11 -40
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d1738b022486bc41367e9dee76d2fc4a0792a47dccb5059ac872a479b192ab8c
|
4
|
+
data.tar.gz: 41ba0ed417967bea1af88f4c828a7bae04b586d4749e93b50ce91972ad4e55bd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9626b16ccb6c22998e885816359a0c304db95adff5657c69e59cdc83d3549717928b8425f69beee37269e69b8f1152c43330153c88267b0e701faa7b378ab84b
|
7
|
+
data.tar.gz: '089409f803c9dbae0d834795c373617088eef192a1f12bbb719fec2af28cb810884f8c4c3b90275b34fd92f88b04c0152f3c1a400094a3121d5734156033d288'
|
data/README.md
CHANGED
@@ -1,22 +1,20 @@
|
|
1
1
|
# AyeVar 🏴☠️
|
2
2
|
|
3
|
-
|
3
|
+
Avast ye, this gem be fresh off th’ plunderin’ an’ experimental as a new recruit, me hearties! Th’ API be shiftin’ like th’ treacherous seas beneath yer barnacled hull.
|
4
4
|
|
5
5
|
## What does it do?
|
6
6
|
|
7
|
-
It
|
8
|
-
|
9
|
-
Instance variables must be declared in yer object’s initializer (even if they be initially set to `nil`). Only then can ye access ’em in th’ rest o’ yer code, ye scurvy dog!
|
7
|
+
It keelhauls them scurvy undefined instance variables by transformin’ yer code as it loads into th’ hold, savvy? Davy Jones ’imself would approve!
|
10
8
|
|
11
9
|
## Setup
|
12
10
|
|
13
|
-
Add this
|
11
|
+
Add this precious booty to yer gemfile, shiver me timbers!
|
14
12
|
|
15
13
|
```ruby
|
16
14
|
gem "aye_var", require: false
|
17
15
|
```
|
18
16
|
|
19
|
-
Then
|
17
|
+
Then be requirin’ an’ initializin’ it in yer galleon as early as ye can hoist sail, ye scallywag! If ye be usin’ Bootsnap, place it right after, or by the powers, ye’ll be swimmin’ with th’ fishes!
|
20
18
|
|
21
19
|
```ruby
|
22
20
|
require "aye_var"
|
@@ -24,4 +22,4 @@ require "aye_var"
|
|
24
22
|
AyeVar.init(include: ["#{Dir.pwd}/**/*"])
|
25
23
|
```
|
26
24
|
|
27
|
-
Ye can pass
|
25
|
+
Ye can pass an array o’ globs to `include:` an’ `exclude:`, or I’ll feed ye to th’ kraken, ye mangy bilge-suckin’ swab!
|
data/lib/aye_var/version.rb
CHANGED
data/lib/aye_var.rb
CHANGED
@@ -4,8 +4,6 @@ require "require-hooks/setup"
|
|
4
4
|
require "prism"
|
5
5
|
|
6
6
|
module AyeVar
|
7
|
-
METHODS_PERMITTED_FOR_DEFINITION = Set[:initialize, :setup].freeze
|
8
|
-
|
9
7
|
NameError = Class.new(::NameError)
|
10
8
|
|
11
9
|
def self.init(include: [], exclude: [])
|
@@ -25,7 +23,7 @@ module AyeVar
|
|
25
23
|
visitor.annotations.sort_by(&:first).reverse_each do |offset, action, name|
|
26
24
|
case action
|
27
25
|
when :start
|
28
|
-
buffer.insert(offset, "((raise ::AyeVar::NameError.new('Undefined instance variable #{name}') unless defined?(#{name}));")
|
26
|
+
buffer.insert(offset, "((raise ::AyeVar::NameError.new('Undefined instance variable #{name}') unless defined?(#{name})); ")
|
29
27
|
when :end
|
30
28
|
buffer.insert(offset, ")")
|
31
29
|
else
|
@@ -37,9 +35,8 @@ module AyeVar
|
|
37
35
|
end
|
38
36
|
|
39
37
|
def initialize
|
40
|
-
@definition_context = true
|
41
38
|
@this = nil
|
42
|
-
@context =
|
39
|
+
@context = Set[]
|
43
40
|
@annotations = []
|
44
41
|
end
|
45
42
|
|
@@ -61,16 +58,16 @@ module AyeVar
|
|
61
58
|
new_context(node) { super }
|
62
59
|
end
|
63
60
|
|
64
|
-
def
|
65
|
-
|
66
|
-
|
67
|
-
new_context(node) do
|
68
|
-
if METHODS_PERMITTED_FOR_DEFINITION.include?(node.name) || Prism::SelfNode === node.receiver || !(Prism::ClassNode === parent)
|
69
|
-
super
|
70
|
-
else
|
71
|
-
prevent_definitions { super }
|
72
|
-
end
|
61
|
+
def visit_defined_node(node)
|
62
|
+
if Prism::InstanceVariableReadNode === node.value
|
63
|
+
context << node.value.name
|
73
64
|
end
|
65
|
+
|
66
|
+
super
|
67
|
+
end
|
68
|
+
|
69
|
+
def visit_def_node(node)
|
70
|
+
new_context(node) { super }
|
74
71
|
end
|
75
72
|
|
76
73
|
def visit_if_node(node)
|
@@ -105,21 +102,6 @@ module AyeVar
|
|
105
102
|
super
|
106
103
|
end
|
107
104
|
|
108
|
-
def visit_instance_variable_write_node(node)
|
109
|
-
name = node.name
|
110
|
-
|
111
|
-
unless @definition_context || context.include?(name)
|
112
|
-
location = node.location
|
113
|
-
|
114
|
-
context << name
|
115
|
-
|
116
|
-
@annotations << [location.start_character_offset, :start, name]
|
117
|
-
@annotations << [location.end_character_offset, :end, name]
|
118
|
-
end
|
119
|
-
|
120
|
-
super
|
121
|
-
end
|
122
|
-
|
123
105
|
private def new_context(this)
|
124
106
|
original_this = @this
|
125
107
|
original_context = @context
|
@@ -150,16 +132,5 @@ module AyeVar
|
|
150
132
|
private def context
|
151
133
|
@context
|
152
134
|
end
|
153
|
-
|
154
|
-
private def prevent_definitions
|
155
|
-
original_definition_context = @definition_context
|
156
|
-
|
157
|
-
begin
|
158
|
-
@definition_context = false
|
159
|
-
yield
|
160
|
-
ensure
|
161
|
-
@definition_context = original_definition_context
|
162
|
-
end
|
163
|
-
end
|
164
135
|
end
|
165
136
|
end
|