decode 0.24.0 → 0.24.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: 8caef896e4f0541d426216be2ee041cd78ef81642b677a420d9f89f77a719ae0
4
- data.tar.gz: 26c7090e233385633a99ec80f906f6cc7f429dd3eb02fe0d24a87ab9019b2931
3
+ metadata.gz: 16fcc036ea4c0db950c8dccf9b8f7a8a8b646e4375d5aa51dae09aa119269916
4
+ data.tar.gz: 209ee8f76ba71de8f80df11d838f734d36867bc7bde266188731e07e16cfadd2
5
5
  SHA512:
6
- metadata.gz: 9b3ef91c4974a9d9cad7b5918dd885d55838c4a0d1f0eb06e2584bcde500e6bc657ef2bb11c50b6963171336153ae76a8b8d2365ed5444895906b35272e4795f
7
- data.tar.gz: 4c60126b5604f42b9c8f9e1f10d47ba264d52042a0365881df2957bf77ad0faf6a2f8a9fc7e05c77c430a8376a873b606d9e5112bddee194944323247108e139
6
+ metadata.gz: 841791e39cb636b47ed5a2bd9f5974ab8fc77bccf1fb7ab932300aa0c32046afe47a42ebc562c3580bfc53363b89bc5afcb9e1af151f3c414dc367b4a940d02e
7
+ data.tar.gz: 173fa08e9dcac6fa0afdc73ccb9452afb95c4dccf00333e0209692628bb0336e80cd1eea65061458e301980726e94701d08e3e02fccaa30482b1faf97b49331d
checksums.yaml.gz.sig CHANGED
Binary file
@@ -56,7 +56,7 @@ module Decode
56
56
  else
57
57
  # Ignore unknown directive.
58
58
  end
59
-
59
+
60
60
  # Or it's just text:
61
61
  else
62
62
  yield Text.new(line)
data/lib/decode/index.rb CHANGED
@@ -57,10 +57,10 @@ module Decode
57
57
  def inspect
58
58
  "#<#{self.class} #{@definitions.size} definition(s)>"
59
59
  end
60
-
60
+
61
61
  # Generate a string representation of the index.
62
62
  alias to_s inspect
63
-
63
+
64
64
  # All supported languages for this index.
65
65
  # @attribute [Languages] The languages this index can parse.
66
66
  attr :languages
@@ -56,7 +56,7 @@ module Decode
56
56
  def nested_name
57
57
  "class"
58
58
  end
59
-
59
+
60
60
  # A singleton class is a container for other definitions.
61
61
  # @returns [Boolean]
62
62
  def container?
@@ -8,13 +8,18 @@ require_relative "wrapper"
8
8
  require_relative "method"
9
9
  module Decode
10
10
  module RBS
11
+ # Represents a Ruby class definition wrapper for RBS generation.
11
12
  class Class < Wrapper
12
13
 
14
+ # Initialize a new class wrapper.
15
+ # @parameter definition [Decode::Definition] The class definition to wrap.
13
16
  def initialize(definition)
14
17
  super
15
18
  @generics = nil
16
19
  end
17
20
 
21
+ # Extract generic type parameters from the class definition.
22
+ # @returns [Array] The generic type parameters for this class.
18
23
  def generics
19
24
  @generics ||= extract_generics
20
25
  end
@@ -10,7 +10,10 @@ require_relative "module"
10
10
 
11
11
  module Decode
12
12
  module RBS
13
+ # Represents a generator for RBS type declarations.
13
14
  class Generator
15
+ # Initialize a new RBS generator.
16
+ # Sets up the RBS environment for type resolution.
14
17
  def initialize
15
18
  # Set up RBS environment for type resolution
16
19
  @loader = ::RBS::EnvironmentLoader.new()
@@ -23,6 +26,7 @@ module Decode
23
26
  def generate(index, output: $stdout)
24
27
  # Build nested RBS AST structure using a hash for proper ||= behavior
25
28
  declarations = {}
29
+ roots = []
26
30
 
27
31
  # Efficiently traverse the trie to find containers and their methods
28
32
  index.trie.traverse do |lexical_path, node, descend|
@@ -32,7 +36,9 @@ module Decode
32
36
  containers.each do |definition|
33
37
  case definition
34
38
  when Decode::Language::Ruby::Class, Decode::Language::Ruby::Module
35
- build_nested_declaration(definition, declarations, index)
39
+ if declaration = build_nested_declaration(definition, declarations, index)
40
+ roots << declaration
41
+ end
36
42
  end
37
43
  end
38
44
  end
@@ -44,18 +50,20 @@ module Decode
44
50
  # Write the RBS output
45
51
  writer = ::RBS::Writer.new(out: output)
46
52
 
47
- unless declarations.empty?
48
- writer.write(declarations.values)
53
+ unless roots.empty?
54
+ writer.write(roots)
49
55
  end
50
56
  end
51
57
 
52
58
  private
53
59
 
54
- # Build nested RBS declarations preserving the parent hierarchy
60
+ # Build nested RBS declarations preserving the parent hierarchy.
61
+ # @returns [::RBS::AST::Declarations::Class | ::RBS::AST::Declarations::Module] If the definition has no parent, returns the declaration.
62
+ # @returns [Nil] If the definition has a parent, adds to parent's members.
55
63
  def build_nested_declaration(definition, declarations, index)
56
64
  # Create the declaration for this definition using ||= to avoid duplicates
57
65
  qualified_name = definition.qualified_name
58
- declarations[qualified_name] ||= definition_to_rbs(definition, index)
66
+ declaration = (declarations[qualified_name] ||= definition_to_rbs(definition, index))
59
67
 
60
68
  # Add this declaration to its parent's members if it has a parent
61
69
  if definition.parent
@@ -63,11 +71,13 @@ module Decode
63
71
  parent_container = declarations[parent_qualified_name]
64
72
 
65
73
  # Only add if not already present
66
- unless parent_container.members.any? {|member|
67
- member.respond_to?(:name) && member.name.name == definition.name.to_sym
68
- }
74
+ unless parent_container.members.any?{|member| member.respond_to?(:name) && member.name.name == definition.name.to_sym}
69
75
  parent_container.members << declarations[qualified_name]
70
76
  end
77
+
78
+ return nil
79
+ else
80
+ return declaration
71
81
  end
72
82
  end
73
83
 
@@ -10,13 +10,18 @@ require_relative "wrapper"
10
10
 
11
11
  module Decode
12
12
  module RBS
13
+ # Represents a Ruby method definition wrapper for RBS generation.
13
14
  class Method < Wrapper
14
15
 
16
+ # Initialize a new method wrapper.
17
+ # @parameter definition [Decode::Definition] The method definition to wrap.
15
18
  def initialize(definition)
16
19
  super
17
20
  @signatures = nil
18
21
  end
19
22
 
23
+ # Extract method signatures from the method definition.
24
+ # @returns [Array] The extracted signatures for this method.
20
25
  def signatures
21
26
  @signatures ||= extract_signatures
22
27
  end
@@ -8,8 +8,11 @@ require_relative "wrapper"
8
8
 
9
9
  module Decode
10
10
  module RBS
11
+ # Represents a Ruby module definition wrapper for RBS generation.
11
12
  class Module < Wrapper
12
13
 
14
+ # Initialize a new module wrapper.
15
+ # @parameter definition [Decode::Definition] The module definition to wrap.
13
16
  def initialize(definition)
14
17
  super
15
18
  end
data/lib/decode/rbs.rb CHANGED
@@ -9,3 +9,9 @@ require_relative "rbs/class"
9
9
  require_relative "rbs/method"
10
10
  require_relative "rbs/module"
11
11
  require_relative "rbs/generator"
12
+
13
+ module Decode
14
+ # RBS generation functionality for Ruby type signatures.
15
+ module RBS
16
+ end
17
+ end
data/lib/decode/trie.rb CHANGED
@@ -21,10 +21,10 @@ module Decode
21
21
  def inspect
22
22
  "#<#{self.class} #{@children.size} children>"
23
23
  end
24
-
24
+
25
25
  # Generate a string representation of the node.
26
26
  alias to_s inspect
27
-
27
+
28
28
  # A mutable array of all values that terminate at this node.
29
29
  # @attribute [Array | Nil] The values stored at this node, or nil if no values.
30
30
  attr_accessor :values
@@ -4,5 +4,5 @@
4
4
  # Copyright, 2020-2025, by Samuel Williams.
5
5
 
6
6
  module Decode
7
- VERSION = "0.24.0"
7
+ VERSION = "0.24.1"
8
8
  end
data/readme.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  A Ruby code analysis tool and documentation generator.
4
4
 
5
- [![Development Status](https://github.com/ioquatix/decode/workflows/Test/badge.svg)](https://github.com/ioquatix/decode/actions?workflow=Test)
5
+ [![Development Status](https://github.com/socketry/decode/workflows/Test/badge.svg)](https://github.com/socketry/decode/actions?workflow=Test)
6
6
 
7
7
  ## Motivation
8
8
 
@@ -10,21 +10,21 @@ As part of my effort to build [better project documentation](https://github.com/
10
10
 
11
11
  ## Usage
12
12
 
13
- Please see the [project documentation](https://ioquatix.github.io/decode/) for more details.
13
+ Please see the [project documentation](https://socketry.github.io/decode/) for more details.
14
14
 
15
- - [Getting Started](https://ioquatix.github.io/decode/guides/getting-started/index) - This guide explains how to use `decode` for source code analysis.
15
+ - [Getting Started](https://socketry.github.io/decode/guides/getting-started/index) - This guide explains how to use `decode` for source code analysis.
16
16
 
17
- - [Code Coverage](https://ioquatix.github.io/decode/guides/code-coverage/index) - This guide explains how to compute documentation code coverage.
17
+ - [Code Coverage](https://socketry.github.io/decode/guides/code-coverage/index) - This guide explains how to compute documentation code coverage.
18
18
 
19
- - [Extract Symbols](https://ioquatix.github.io/decode/guides/extract-symbols/index) - This example demonstrates how to extract symbols using the index. An instance of <code class="language-ruby">Decode::Index</code> is used for loading symbols from source code files. These symbols are available as a flat list and as a trie structure. You can look up specific symbols using a reference using <code class="language-ruby">Decode::Index\#lookup</code>.
19
+ - [Extract Symbols](https://socketry.github.io/decode/guides/extract-symbols/index) - This example demonstrates how to extract symbols using the index. An instance of <code class="language-ruby">Decode::Index</code> is used for loading symbols from source code files. These symbols are available as a flat list and as a trie structure. You can look up specific symbols using a reference using <code class="language-ruby">Decode::Index\#lookup</code>.
20
20
 
21
21
  ## Releases
22
22
 
23
- Please see the [project releases](https://ioquatix.github.io/decode/releases/index) for all releases.
23
+ Please see the [project releases](https://socketry.github.io/decode/releases/index) for all releases.
24
24
 
25
25
  ### v0.24.0
26
26
 
27
- - [Introduce support for RBS signature generation.](https://ioquatix.github.io/decode/releases/index#introduce-support-for-rbs-signature-generation.)
27
+ - [Introduce support for RBS signature generation](https://socketry.github.io/decode/releases/index#introduce-support-for-rbs-signature-generation)
28
28
 
29
29
  ### v0.23.5
30
30
 
data/releases.md CHANGED
@@ -2,25 +2,25 @@
2
2
 
3
3
  ## v0.24.0
4
4
 
5
- ### Introduce support for RBS signature generation.
5
+ ### Introduce support for RBS signature generation
6
6
 
7
7
  Decode now supports generating RBS type signatures from Ruby source code, making it easier to add type annotations to existing Ruby projects. The RBS generator analyzes your Ruby code and documentation to produce type signatures that can be used with tools like Steep, TypeProf, and other RBS-compatible type checkers.
8
8
 
9
9
  To generate RBS signatures for your Ruby code, use the provided bake task:
10
10
 
11
11
  ``` bash
12
- # Generate RBS signatures for the current directory
13
- bundle exec bake decode:rbs:generate .
12
+ -- Generate RBS signatures for the current directory
13
+ $ bundle exec bake decode:rbs:generate .
14
14
 
15
- # Generate RBS signatures for a specific directory
16
- bundle exec bake decode:rbs:generate lib/
15
+ -- Generate RBS signatures for a specific directory
16
+ $ bundle exec bake decode:rbs:generate lib/
17
17
  ```
18
18
 
19
19
  The generator will output RBS declarations to stdout, which you can redirect to a file:
20
20
 
21
21
  ``` bash
22
- # Save RBS signatures to a file
23
- bundle exec bake decode:rbs:generate lib/ > sig/generated.rbs
22
+ -- Save RBS signatures to a file
23
+ $ bundle exec bake decode:rbs:generate lib/ > sig/generated.rbs
24
24
  ```
25
25
 
26
26
  The RBS generator produces type signatures for:
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: decode
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.24.0
4
+ version: 0.24.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
@@ -145,13 +145,13 @@ files:
145
145
  - license.md
146
146
  - readme.md
147
147
  - releases.md
148
- homepage: https://github.com/ioquatix/decode
148
+ homepage: https://github.com/socketry/decode
149
149
  licenses:
150
150
  - MIT
151
151
  metadata:
152
- documentation_uri: https://ioquatix.github.io/decode/
153
- funding_uri: https://github.com/sponsors/ioquatix/
154
- source_code_uri: https://github.com/ioquatix/decode.git
152
+ documentation_uri: https://socketry.github.io/decode/
153
+ funding_uri: https://github.com/sponsors/socketry/
154
+ source_code_uri: https://github.com/socketry/decode.git
155
155
  rdoc_options: []
156
156
  require_paths:
157
157
  - lib
metadata.gz.sig CHANGED
Binary file