tag_ripper 0.2.0 → 0.2.1

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: 375a528cbf8942e0dd48c51ffe10c005a6b3672b414e82b5d768011f3355e350
4
- data.tar.gz: f3e74892414a1587e5dfabeba4cda6839f2dd500f800bda6303fa2ea97f18042
3
+ metadata.gz: 2e80933d8c317438627b041b30bd905ae33ed8d993db4ef149e69f3f71fd30d7
4
+ data.tar.gz: 7eeb22fc466b8b50da7f6d3e887dfc02c04d0de462abf870f36bf0beda6b3a68
5
5
  SHA512:
6
- metadata.gz: 49ababa76c465f7fa6a691f968290a6668762d884e0be15ca3790e6b6b884853aa1ff1bbbe78c9afdeef293b85ab4f3470357d635c9dda531257f26e81d4700b
7
- data.tar.gz: 07311f3a4768f8643c0fafcab84f3b6318392a5c1726bcfccf2fcfd1291db35e4039d4493adeb4e0241765b086e56bd2fbb3feee4e9065452c4880df3a9d88f9
6
+ metadata.gz: 131915acf06d838e8d5aa62ee92b62eab06743071298aa57fb887975cd9414b825d9929a40349bd6e4607ee5b7475eb41dc205939dc8a86d8c51856880317692
7
+ data.tar.gz: e7e86cc4d7984e3f05d1743d42892ee235152467a16f64edbc64cfe79d9683a5130aa013ce193084adb3348d509cc06938d78bbf5d2823efcb7a33ef61fbcf89
data/.rubocop.yml CHANGED
@@ -11,6 +11,7 @@ AllCops:
11
11
  Exclude:
12
12
  - bin/*
13
13
  - test/fixtures/**/* # These files have particular styles that should be preserved
14
+ - samples/**/* # These files have particular styles that should be preserved
14
15
  Metrics/AbcSize:
15
16
  Exclude:
16
17
  - test/**/*
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 3.4.2
1
+ 3.4.3
data/Guardfile ADDED
@@ -0,0 +1,12 @@
1
+ guard :minitest, cli: "--verbose" do
2
+ watch(%r{^test/(.+)_test\.rb$})
3
+ watch(%r{^lib/(.+)\.rb$}) { |m| "test/#{m[1]}_test.rb" }
4
+ watch("test/test_helper.rb") { "test" }
5
+ end
6
+
7
+ guard :rubocop, all_on_start: false do
8
+ watch(/^.+\.rb$/)
9
+ watch(%r{^(config|test)/.+\.rb$})
10
+ watch("Gemfile")
11
+ watch(".rubocop.yml")
12
+ end
data/README.md CHANGED
@@ -5,7 +5,24 @@
5
5
 
6
6
  Lets you annotate Ruby code with tags that can be parsed and collected in code.
7
7
 
8
- Example:
8
+
9
+ ## Installation
10
+
11
+
12
+ Install the gem and add to the application's Gemfile by executing:
13
+
14
+ ```bash
15
+ bundle add tag_ripper
16
+ ```
17
+
18
+ If bundler is not being used to manage dependencies, install the gem by executing:
19
+
20
+ ```bash
21
+ gem install tag_ripper
22
+ ```
23
+
24
+ ## Usage
25
+
9
26
 
10
27
  ```ruby
11
28
  # @domain: Auth
@@ -35,25 +52,6 @@ TagRipper.new(File.read('user.rb')).taggables
35
52
  # parent: nil
36
53
  ```
37
54
 
38
- ## Installation
39
-
40
-
41
- Install the gem and add to the application's Gemfile by executing:
42
-
43
- ```bash
44
- bundle add tag_ripper
45
- ```
46
-
47
- If bundler is not being used to manage dependencies, install the gem by executing:
48
-
49
- ```bash
50
- gem install tag_ripper
51
- ```
52
-
53
- ## Usage
54
-
55
- TODO: Write usage instructions here
56
-
57
55
  ## Development
58
56
 
59
57
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -62,7 +60,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
62
60
 
63
61
  ## Contributing
64
62
 
65
- Bug reports and pull requests are welcome on GitHub at https://github.com/bodacious/tag-ripper. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/bodacious/tag-ripper/blob/master/CODE_OF_CONDUCT.md).
63
+ Bug reports and pull requests are welcome on GitHub at https://github.com/bodacious/tag_ripper. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/bodacious/tag_ripper/blob/master/CODE_OF_CONDUCT.md).
66
64
 
67
65
  ## License
68
66
 
@@ -70,4 +68,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
70
68
 
71
69
  ## Code of Conduct
72
70
 
73
- Everyone interacting in the Tag::Ripper project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/bodacious/tag-ripper/blob/master/CODE_OF_CONDUCT.md).
71
+ Everyone interacting in the Tag::Ripper project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/bodacious/tag_ripper/blob/master/CODE_OF_CONDUCT.md).
@@ -3,8 +3,22 @@ module TagRipper
3
3
  require "forwardable"
4
4
  extend Forwardable
5
5
 
6
- TAG_REGEX = /#\s@(?<tag_name>[\w_-]+):\s(?<tag_value>.+)/
7
- END_TOKEN = "end".freeze
6
+ TAG_REGEX = /#\s@(?<tag_name>[\w-]+):\s(?<tag_value>.+)/
7
+
8
+ ##
9
+ # = Operators =
10
+
11
+ DOUBLE_COLON = "::".freeze
12
+ SINGLETON_CLASS = "<<".freeze
13
+
14
+ ##
15
+ # = Keywords =
16
+
17
+ KEYWORD_CONST = "const".freeze
18
+ KEYWORD_CLASS = "class".freeze
19
+ KEYWORD_DEF = "def".freeze
20
+ KEYWORD_END = "end".freeze
21
+ KEYWORD_MODULE = "module".freeze
8
22
 
9
23
  class Location
10
24
  attr_reader :col
@@ -50,7 +64,11 @@ module TagRipper
50
64
  end
51
65
 
52
66
  def double_colon?
53
- token == "::"
67
+ token == DOUBLE_COLON
68
+ end
69
+
70
+ def singleton_class?
71
+ token == SINGLETON_CLASS
54
72
  end
55
73
 
56
74
  def keyword?
@@ -58,7 +76,7 @@ module TagRipper
58
76
  end
59
77
 
60
78
  def end?
61
- keyword? && token == END_TOKEN
79
+ keyword? && token == KEYWORD_END
62
80
  end
63
81
 
64
82
  def tag_name
@@ -76,13 +94,10 @@ module TagRipper
76
94
  def on_kw_type
77
95
  return nil unless keyword?
78
96
 
79
- case token
80
- when "const" then :class
81
- when "module" then :module
82
- when "def" then :instance_method
83
- else
84
- :unknown
85
- end
97
+ const_lookup = "KEYWORD_#{token.upcase}"
98
+ return :unknown unless self.class.const_defined?(const_lookup)
99
+
100
+ self.class.const_get(const_lookup).to_sym
86
101
  end
87
102
  end
88
103
  end
@@ -34,17 +34,18 @@ module TagRipper
34
34
  # @return [Array<Symbol>]
35
35
  OPENED_STATUSES = %i[tagged awaiting_name named].freeze
36
36
 
37
- def initialize(name: nil, parent: nil)
37
+ def initialize(name: nil, parent: nil, type: nil)
38
38
  @name = name
39
39
  @tags = Hash.new { |hash, key| hash[key] = Set.new }
40
40
  @parent = parent
41
- @type = nil
41
+ @type = type
42
42
  self.status = :pending
43
43
  end
44
44
 
45
45
  alias id object_id
46
46
 
47
47
  def send_event(event_name, lex)
48
+ debug_event(event_name, lex) if ENV["DEBUG_TAG_RIPPER"]
48
49
  if respond_to?(event_name, true)
49
50
  send(event_name, lex)
50
51
  else
@@ -52,6 +53,13 @@ module TagRipper
52
53
  end
53
54
  end
54
55
 
56
+ def debug_event(event_name, lex)
57
+ puts <<~OUTPUT.chomp
58
+ Sending #{event_name} to #{self} with #{lex.token.inspect}
59
+ #{inspect}"
60
+ OUTPUT
61
+ end
62
+
55
63
  def module?
56
64
  (type == :module) | (type == :class)
57
65
  end
@@ -63,7 +71,7 @@ module TagRipper
63
71
  # The fully-qualified name of this entity (e.g. +"Foo::Bar::MyClass"+)
64
72
  # @return [String]
65
73
  def fqn
66
- return nil unless named?
74
+ return nil unless name?
67
75
  return name if fqn_names.size == 1
68
76
 
69
77
  if type == :instance_method
@@ -100,6 +108,10 @@ module TagRipper
100
108
  self.status = :awaiting_name
101
109
  end
102
110
 
111
+ def name?
112
+ !!@name
113
+ end
114
+
103
115
  def name=(name)
104
116
  unless may_name?
105
117
  raise IllegalStateTransitionError.new(from: @status, to: :named)
@@ -137,10 +149,20 @@ module TagRipper
137
149
  named?
138
150
  end
139
151
 
152
+ def parent_id
153
+ parent&.id
154
+ end
155
+
140
156
  def inspect
141
- "<id=#{id},@name=#{@name},tags=#{@tags},parent=#{@parent}>"
157
+ exposed_properties = %i[object_id name fqn type parent_id status tags]
158
+ inner_string = exposed_properties.map do |property|
159
+ "#{property}=#{public_send(property)}"
160
+ end.join(", ")
161
+ "<#{inner_string}>"
142
162
  end
143
163
 
164
+ alias to_s inspect
165
+
144
166
  def tags
145
167
  @tags.dup
146
168
  end
@@ -153,6 +175,10 @@ module TagRipper
153
175
  @parent
154
176
  end
155
177
 
178
+ def status
179
+ @status
180
+ end
181
+
156
182
  protected
157
183
 
158
184
  def append_name!(string)
@@ -182,10 +208,6 @@ module TagRipper
182
208
  @tags[name].add(value)
183
209
  end
184
210
 
185
- def named?
186
- !!@name
187
- end
188
-
189
211
  def build_child
190
212
  self.class.new(parent: self)
191
213
  end
@@ -216,7 +238,7 @@ module TagRipper
216
238
  returnable_entity = named? ? build_child : self
217
239
 
218
240
  returnable_entity.await_name!
219
- self.type = lex.on_kw_type
241
+ returnable_entity.type = lex.on_kw_type
220
242
 
221
243
  returnable_entity
222
244
  end
@@ -233,10 +255,10 @@ module TagRipper
233
255
  return self if IGNORED_IDENT_KEYWORDS.include?(lex.token)
234
256
  # TODO: Simplify this logic
235
257
  return self if named? && !@name.end_with?("::")
236
- return self unless may_name? || @name.end_with?("::")
258
+ return self unless may_name? || (name? && @name.end_with?("::"))
237
259
 
238
260
  # self.status = :awaiting_name # TODO: Fix this with a proper state
239
- if named? && @name.end_with?("::")
261
+ if named? && @name.to_s.end_with?("::")
240
262
  append_name!(lex.token)
241
263
  else
242
264
  self.name = "#{name}#{lex.token}"
@@ -257,6 +279,24 @@ module TagRipper
257
279
  if lex.double_colon?
258
280
  append_name!(lex.token)
259
281
  end
282
+
283
+ # return name_from_op(lex) if lex.singleton_class?
284
+ self
285
+ end
286
+
287
+ def on_kw_self(lex)
288
+ if module? && awaiting_name?
289
+ self.name = lex.token
290
+ return self
291
+ end
292
+
293
+ self
294
+ end
295
+
296
+ ##
297
+ # Name the current entity 'self' based on an operator (e.g. +class << self+)
298
+ def name_from_kw(lex)
299
+ self.name = lex.token
260
300
  self
261
301
  end
262
302
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module TagRipper
4
- VERSION = "0.2.0"
4
+ VERSION = "0.2.1"
5
5
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tag_ripper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gavin Morrice
8
8
  bindir: exe
9
9
  cert_chain: []
10
- date: 2025-06-19 00:00:00.000000000 Z
10
+ date: 2025-07-02 00:00:00.000000000 Z
11
11
  dependencies: []
12
12
  description: Add tags to your Ruby code comments and then Rip the as lexical tokens
13
13
  email:
@@ -21,6 +21,7 @@ files:
21
21
  - ".ruby-version"
22
22
  - CHANGELOG.md
23
23
  - CODE_OF_CONDUCT.md
24
+ - Guardfile
24
25
  - LICENSE.txt
25
26
  - README.md
26
27
  - Rakefile