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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2e1eb735e2846d27610ccd41568c9022de487d62ccbf2c9d212af0019c72e1c9
4
- data.tar.gz: 0ceb88f7fe73970d8c7c47d15671ecc2fc8350a8c05e29eed55d4ce6935828bd
3
+ metadata.gz: d1738b022486bc41367e9dee76d2fc4a0792a47dccb5059ac872a479b192ab8c
4
+ data.tar.gz: 41ba0ed417967bea1af88f4c828a7bae04b586d4749e93b50ce91972ad4e55bd
5
5
  SHA512:
6
- metadata.gz: ac42f044cd02865cd63d7194b76bbe5111da98bbdf9286ebc1975ff460bad95c22a6070c29238a2c2fa6ffdca2597f8f28aad1e0dfd7a3235c6051e635d16fc1
7
- data.tar.gz: 52673c9d24958003fc168ddf02075332aac4d3275c70e73d0d3d86aca54aa6bc17ae2226cbb0c75df8d5537f0f3f208b0ce980c49b3f23160cdab75440f56ee9
6
+ metadata.gz: 9626b16ccb6c22998e885816359a0c304db95adff5657c69e59cdc83d3549717928b8425f69beee37269e69b8f1152c43330153c88267b0e701faa7b378ab84b
7
+ data.tar.gz: '089409f803c9dbae0d834795c373617088eef192a1f12bbb719fec2af28cb810884f8c4c3b90275b34fd92f88b04c0152f3c1a400094a3121d5734156033d288'
data/README.md CHANGED
@@ -1,22 +1,20 @@
1
1
  # AyeVar 🏴‍☠️
2
2
 
3
- Arrr, this gem be mighty fresh an’ experimental, me hearties! Th’ API be likely to shift with th’ tides.
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 prevents ye from usin’ undefined instance variables by transformin’ yer code as it be loaded, savvy?
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 treasure to yer gemfile, arr!
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 require an’ initialize it in yer vessel as early as possible, ye hear? If ye be usin’ Bootsnap, it should be right after Bootsnap, or I’ll make ye walk th’ plank!
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 in an array o’ globs to `include:` an’ `exclude:`, ye bilge rat!
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!
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module AyeVar
4
- VERSION = "0.1.1"
4
+ VERSION = "0.2.0"
5
5
  end
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 = nil
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 visit_def_node(node)
65
- parent = @this
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aye_var
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joel Drapper