sord 0.8.0 → 3.0.0.beta.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 +4 -4
- data/.github/ISSUE_TEMPLATE/bug_report.md +0 -0
- data/.github/ISSUE_TEMPLATE/feature-request.md +0 -0
- data/.gitignore +0 -0
- data/.parlour +11 -0
- data/.rspec +0 -0
- data/.travis.yml +6 -0
- data/CHANGELOG.md +99 -0
- data/CODE_OF_CONDUCT.md +0 -0
- data/Gemfile +0 -0
- data/LICENSE.txt +0 -0
- data/README.md +17 -11
- data/Rakefile +87 -12
- data/exe/sord +50 -33
- data/lib/sord.rb +2 -1
- data/lib/sord/generator.rb +592 -0
- data/lib/sord/logging.rb +21 -30
- data/lib/sord/parlour_plugin.rb +84 -0
- data/lib/sord/resolver.rb +9 -2
- data/lib/sord/type_converter.rb +88 -42
- data/lib/sord/version.rb +1 -1
- data/rbi/sord.rbi +279 -68
- data/sord.gemspec +3 -3
- metadata +23 -38
- data/lib/sord/rbi_generator.rb +0 -334
- data/sorbet/config +0 -0
- data/sorbet/rbi/gems/colorize.rbi +0 -81
- data/sorbet/rbi/gems/docile.rbi +0 -31
- data/sorbet/rbi/gems/rake.rbi +0 -643
- data/sorbet/rbi/gems/rspec-core.rbi +0 -1658
- data/sorbet/rbi/gems/rspec-expectations.rbi +0 -389
- data/sorbet/rbi/gems/rspec-mocks.rbi +0 -823
- data/sorbet/rbi/gems/rspec-support.rbi +0 -268
- data/sorbet/rbi/gems/rspec.rbi +0 -14
- data/sorbet/rbi/gems/simplecov-html.rbi +0 -30
- data/sorbet/rbi/gems/simplecov.rbi +0 -223
- data/sorbet/rbi/gems/sorbet-runtime.rbi +0 -647
- data/sorbet/rbi/gems/yard.rbi +0 -310
- data/sorbet/rbi/hidden-definitions/errors.txt +0 -9353
- data/sorbet/rbi/hidden-definitions/hidden.rbi +0 -16640
- data/sorbet/rbi/sorbet-typed/lib/bundler/all/bundler.rbi +0 -8547
- data/sorbet/rbi/sorbet-typed/lib/ruby/all/open3.rbi +0 -111
- data/sorbet/rbi/sorbet-typed/lib/ruby/all/resolv.rbi +0 -543
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6cfc03da2fe9815159c9041a5afff2a0e1e089567cb92da25bcec87137f9e747
|
4
|
+
data.tar.gz: acd6551c560c205199ec494930f4628c5357a34263b0cce05757033014ba929b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a3ef67b5162e55af55f81fd056c0a1f232293c021b145fab2054cd482951c9cd22aa2e9f8874687131c65b209f2217488ce6808f9bd88da75a04928720452a34
|
7
|
+
data.tar.gz: 719461ac9a36dc5c636c4f1b79c22923da4e1decb25032ec8e0c6eef8df60454c3eba6d275c61f91fec9d637d200631d3c3003b1aff981d6bafac3c91323e323
|
File without changes
|
File without changes
|
data/.gitignore
CHANGED
File without changes
|
data/.parlour
ADDED
data/.rspec
CHANGED
File without changes
|
data/.travis.yml
ADDED
data/CHANGELOG.md
CHANGED
@@ -3,6 +3,105 @@ All notable changes to this project will be documented in this file.
|
|
3
3
|
|
4
4
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
5
5
|
|
6
|
+
## [3.0.0.beta.1] - 2020-09-16
|
7
|
+
### Added
|
8
|
+
- Sord now uses the Parlour 5 beta's RBS generation to generate RBS files!
|
9
|
+
- Added `--rbi` and `--rbs` to select an output format to use (if neither given,
|
10
|
+
tries to infer from file extension).
|
11
|
+
|
12
|
+
### Changed
|
13
|
+
- `RbiGenerator` has been renamed to `Generator`.
|
14
|
+
- `TypeConverter#yard_to_sorbet` is now `TypeConverter#yard_to_parlour`, and
|
15
|
+
returns `Parlour::Types::Type` instances rather than strings.
|
16
|
+
|
17
|
+
### Fixed
|
18
|
+
- `#return [nil]` no longer produces a union of zero types, instead becoming
|
19
|
+
`void` for method returns or `untyped` for attributes.
|
20
|
+
|
21
|
+
## [2.0.0] - 2020-03-16
|
22
|
+
### Added
|
23
|
+
- Sord now supports generating `attr_accessor`, `attr_reader` and `attr_writer`
|
24
|
+
and will do so automatically when these are used in your code.
|
25
|
+
- Depending on what you're doing with Sord, this is **potentially breaking**,
|
26
|
+
as for example attributes which would previously generate two `foo` and `foo=`
|
27
|
+
methods in Sord will now just generate an `attr_accessor`.
|
28
|
+
- `#initialize` is now always typed as returning `void`, which is
|
29
|
+
**potentially breaking** if you directly call `#initialize` in code.
|
30
|
+
- The `--use-original-initialize-return` flag restores the old behaviour of
|
31
|
+
using whatever return type is provided, like any other method.
|
32
|
+
|
33
|
+
## [1.0.0] - 2020-02-16
|
34
|
+
### Added
|
35
|
+
- Added the `--skip-constants` flag to avoid generating RBIs for constants.
|
36
|
+
|
37
|
+
### Changed
|
38
|
+
- Parlour 2.0.0 is now being used.
|
39
|
+
|
40
|
+
### Fixed
|
41
|
+
- Fixed a bug where blank parameters were sometimes treated like non-blank
|
42
|
+
parameters.
|
43
|
+
- Fixed parameter order sometimes being incorrect.
|
44
|
+
- Fixed multiline parameter lists sometimes generating invalid RBIs.
|
45
|
+
- Multiline comments are now generated correctly.
|
46
|
+
- Fixed an incorrect README link.
|
47
|
+
|
48
|
+
## [0.10.0] - 2019-09-14
|
49
|
+
### Added
|
50
|
+
- Comments in RBIs are now converted from YARD into Markdown format, making them
|
51
|
+
look much better when viewed in an IDE. (To restore the old behaviour of copying
|
52
|
+
the YARD comments verbatim, use the `--keep-original-comments` flag.)
|
53
|
+
|
54
|
+
### Changed
|
55
|
+
- Parlour 0.8.0 is now being used.
|
56
|
+
- References to `self` as a type in YARD docs are now generated as
|
57
|
+
`T.self_type`, rather than a fixed self type determined by Sord.
|
58
|
+
|
59
|
+
## [0.9.0] - 2019-08-09
|
60
|
+
### Added
|
61
|
+
- Add the `--replace-constants-with-untyped` flag, which generates `T.untyped` instead of `SORD_ERROR` constants.
|
62
|
+
- Added an option to clean the `sord_examples` directory when seeding or reseeding.
|
63
|
+
- Added a Rake task to typecheck the `sord_examples` directory.
|
64
|
+
- Added a `.parlour` file to the project for generating Sord's RBIs.
|
65
|
+
- Added CI with Travis.
|
66
|
+
|
67
|
+
### Changed
|
68
|
+
- Code generation has been broken out into the Parlour gem, and Sord is now a Parlour plugin.
|
69
|
+
- Rainbow is now used for coloured output instead of colorize.
|
70
|
+
- Duplicate type signatures are no longer generated for inherited methods.
|
71
|
+
- The Resolver can now resolve more objects.
|
72
|
+
- If a parameter has `nil` as its default, it now has a nilable type.
|
73
|
+
- Generation of constants has been improved.
|
74
|
+
- Superclass names are now generated as fully-qualified identifiers.
|
75
|
+
|
76
|
+
### Fixed
|
77
|
+
- Fixed `T::Hash` and `T::Array` syntax being generated incorrectly.
|
78
|
+
- Fix a bug where the `--no-comments` or `--no-generate` flags were ignored.
|
79
|
+
- Collections of `T.untyped` now have signatures generated correctly.
|
80
|
+
- Fix generation of hashes when they are given too few parameters.
|
81
|
+
- YARD no longer prints irrelevant error messages when running rake.
|
82
|
+
|
83
|
+
## [0.8.0] - 2019-07-07
|
84
|
+
### Added
|
85
|
+
- Block types can now be generated using `@yieldparam` and `@yieldreturn`.
|
86
|
+
- Long lists of parameters (at least 4) are now broken onto multiple lines. The threshold can be altered with the `--break-params` option.
|
87
|
+
- If a constant used is not found, Sord will now attempt to locate it and fully-qualify its name.
|
88
|
+
- Add the `--replace-errors-with-untyped` flag; when present, `T.untyped` is used instead of `SORD_ERROR_` constants.
|
89
|
+
- Add the `--include/exclude-messages` flags, which can be used to suppress certain log message kinds.
|
90
|
+
- Add support for the `Class<...>` generic becoming `T.class_of(...)`. (#44)
|
91
|
+
- Add YARD array (`<...>`) and hash (`{... => ...}`) shorthands. (#43)
|
92
|
+
- Sord now has an `examples` set of Rake tasks to test Sord on a large number of repos.
|
93
|
+
- Sord now bundles an RBI for itself.
|
94
|
+
|
95
|
+
### Changed
|
96
|
+
- Methods without any YARD documentation are now typed as `T.untyped` rather than `void`.
|
97
|
+
|
98
|
+
### Fixed
|
99
|
+
- Duck types in the form of setters (`#foo=`) are now interpreted properly.
|
100
|
+
- Fix some cases where indentation was incorrect. (#30, #46)
|
101
|
+
- Fix `include` and `extend` calls being swapped, and give them proper blank lines.
|
102
|
+
- Fix incorrect blank lines inside empty namespaces.
|
103
|
+
- Fix a crash when a `@param` has no name given.
|
104
|
+
|
6
105
|
## [0.7.1] - 2019-06-24
|
7
106
|
### Fixed
|
8
107
|
- Fix bug where `--no-regenerate` flag was ignored.
|
data/CODE_OF_CONDUCT.md
CHANGED
File without changes
|
data/Gemfile
CHANGED
File without changes
|
data/LICENSE.txt
CHANGED
File without changes
|
data/README.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
## Overview
|
4
4
|
|
5
|
-
Sord is a [**So**rbet](https://sorbet.org) and [YA**RD**](https://
|
5
|
+
Sord is a [**So**rbet](https://sorbet.org) and [YA**RD**](https://yardoc.org/)
|
6
6
|
crossover. It can automatically generate Sorbet type signatures files by
|
7
7
|
looking at the types specified in YARD documentation comments.
|
8
8
|
|
@@ -52,14 +52,16 @@ where the maintainer is unwilling to ship type signatures with the gem itself.
|
|
52
52
|
|
53
53
|
Sord also takes some flags to alter the generated `.rbi` file:
|
54
54
|
|
55
|
-
- `--no-comments`: Generates the `.rbi` file without any comments
|
56
|
-
warnings/inferences/errors.
|
55
|
+
- `--no-sord-comments`: Generates the `.rbi` file without any Sord comments
|
56
|
+
about warnings/inferences/errors. (The original file's comments will still
|
57
|
+
be included.)
|
57
58
|
- `--no-regenerate`: By default, Sord will regenerate a repository's YARD
|
58
59
|
docs for you. This option skips regenerating the YARD docs.
|
59
60
|
- `--break-params`: Determines how many parameters are necessary before
|
60
61
|
the signature is changed from a single-line to a multi-line block.
|
61
62
|
(Default: 4)
|
62
63
|
- `--replace-errors-with-untyped`: Uses `T.untyped` instead of `SORD_ERROR_*` constants.
|
64
|
+
- `--replace-unresolved-with-untyped`: Uses `T.untyped` when Sord is unable to resolve a constant.
|
63
65
|
- `--include-messages` and `--exclude-messages`: Used to filter the logging
|
64
66
|
messages given by Sord. `--include-messages` acts as a whitelist, printing
|
65
67
|
only messages of the specified logging kinds, whereas `--exclude-messages`
|
@@ -75,22 +77,22 @@ Say we have this file, called `test.rb`:
|
|
75
77
|
```ruby
|
76
78
|
module Example
|
77
79
|
class Person
|
78
|
-
# @param [String] name
|
79
|
-
# @param [Integer] age
|
80
|
+
# @param name [String] The name of the Person to create.
|
81
|
+
# @param age [Integer] The age of the Person to create.
|
80
82
|
# @return [Example::Person]
|
81
83
|
def initialize(name, age)
|
82
84
|
@name = name
|
83
85
|
@age = age
|
84
86
|
end
|
85
87
|
|
86
|
-
# @return [String]
|
88
|
+
# @return name [String]
|
87
89
|
attr_accessor :name
|
88
90
|
|
89
|
-
# @return [Integer]
|
91
|
+
# @return age [Integer]
|
90
92
|
attr_accessor :age
|
91
93
|
|
92
|
-
# @param [Array<String>]
|
93
|
-
# @param [Array<Integer>]
|
94
|
+
# @param possible_names [Array<String>] An array of potential names to choose from.
|
95
|
+
# @param possible_ages [Array<Integer>] An array of potential ages to choose from.
|
94
96
|
# @return [Example::Person]
|
95
97
|
def self.construct_randomly(possible_names, possible_ages)
|
96
98
|
Person.new(possible_names.sample, possible_ages.sample)
|
@@ -115,23 +117,27 @@ The `test.rbi` file then contains a complete RBI file for `test.rb`:
|
|
115
117
|
# typed: strong
|
116
118
|
module Example
|
117
119
|
class Person
|
120
|
+
# @param `name` — The name of the Person to create.
|
121
|
+
# @param `age` — The age of the Person to create.
|
118
122
|
sig { params(name: String, age: Integer).returns(Example::Person) }
|
119
123
|
def initialize(name, age); end
|
120
124
|
|
121
125
|
sig { returns(String) }
|
122
|
-
def name
|
126
|
+
def name; end
|
123
127
|
|
124
128
|
# sord infer - inferred type of parameter "value" as String using getter's return type
|
125
129
|
sig { params(value: String).returns(String) }
|
126
130
|
def name=(value); end
|
127
131
|
|
128
132
|
sig { returns(Integer) }
|
129
|
-
def age
|
133
|
+
def age; end
|
130
134
|
|
131
135
|
# sord infer - inferred type of parameter "value" as Integer using getter's return type
|
132
136
|
sig { params(value: Integer).returns(Integer) }
|
133
137
|
def age=(value); end
|
134
138
|
|
139
|
+
# @param `possible_names` — An array of potential names to choose from.
|
140
|
+
# @param `possible_ages` — An array of potential ages to choose from.
|
135
141
|
sig { params(possible_names: T::Array[String], possible_ages: T::Array[Integer]).returns(Example::Person) }
|
136
142
|
def self.construct_randomly(possible_names, possible_ages); end
|
137
143
|
end
|
data/Rakefile
CHANGED
@@ -10,6 +10,7 @@ REPOS = {
|
|
10
10
|
bundler: 'https://github.com/bundler/bundler',
|
11
11
|
discordrb: 'https://github.com/meew0/discordrb',
|
12
12
|
gitlab: 'https://github.com/NARKOZ/gitlab',
|
13
|
+
'graphql-ruby': 'https://github.com/rmosolgo/graphql-ruby',
|
13
14
|
haml: 'https://github.com/haml/haml',
|
14
15
|
oga: 'https://gitlab.com/yorickpeterse/oga',
|
15
16
|
rouge: 'https://github.com/rouge-ruby/rouge',
|
@@ -20,12 +21,21 @@ REPOS = {
|
|
20
21
|
|
21
22
|
namespace :examples do
|
22
23
|
require 'fileutils'
|
23
|
-
require '
|
24
|
+
require 'rainbow'
|
24
25
|
|
25
26
|
desc "Clone git repositories and run Sord on them as examples"
|
26
|
-
task :seed do
|
27
|
+
task :seed, [:mode, :clean] do |t, args|
|
27
28
|
if File.directory?('sord_examples')
|
28
|
-
puts 'sord_examples directory already exists, please delete the directory or run a reseed!'.red
|
29
|
+
puts Rainbow('sord_examples directory already exists, please delete the directory or run a reseed!').red
|
30
|
+
exit
|
31
|
+
end
|
32
|
+
|
33
|
+
if args[:mode] == 'rbi'
|
34
|
+
mode_arg = '--rbi'
|
35
|
+
elsif args[:mode] == 'rbs'
|
36
|
+
mode_arg = '--rbs'
|
37
|
+
else
|
38
|
+
puts Rainbow('please specify \'rbi\' or \'rbs\'!').red
|
29
39
|
exit
|
30
40
|
end
|
31
41
|
|
@@ -44,35 +54,100 @@ namespace :examples do
|
|
44
54
|
system('bundle install')
|
45
55
|
# Generate sri
|
46
56
|
puts "Generating rbi for #{name}..."
|
47
|
-
|
48
|
-
|
57
|
+
if args[:clean]
|
58
|
+
system("bundle exec sord ../#{name}.#{args[:mode]} #{mode_arg} --no-sord-comments --replace-errors-with-untyped --replace-unresolved-with-untyped")
|
59
|
+
else
|
60
|
+
system("bundle exec sord ../#{name}.#{args[:mode]} #{mode_arg}")
|
61
|
+
end
|
62
|
+
puts "#{name}.#{args[:mode]} generated!"
|
49
63
|
FileUtils.cd '..'
|
50
64
|
end
|
51
65
|
end
|
52
66
|
|
53
|
-
puts "Seeding complete!".green
|
67
|
+
puts Rainbow("Seeding complete!").green
|
54
68
|
end
|
55
69
|
|
56
70
|
desc 'Regenerate the rbi files in sord_examples.'
|
57
|
-
task :reseed do
|
58
|
-
|
71
|
+
task :reseed, [:mode, :clean] do |t, args|
|
72
|
+
if Dir.exist?('sord_examples')
|
73
|
+
FileUtils.cd 'sord_examples'
|
74
|
+
else
|
75
|
+
raise Rainbow("The sord_examples directory does not exist. Have you run the seed task?").red.bold
|
76
|
+
end
|
77
|
+
|
78
|
+
if args[:mode] == 'rbi'
|
79
|
+
mode_arg = '--rbi'
|
80
|
+
elsif args[:mode] == 'rbs'
|
81
|
+
mode_arg = '--rbs'
|
82
|
+
else
|
83
|
+
puts Rainbow('please specify \'rbi\' or \'rbs\'!').red
|
84
|
+
exit
|
85
|
+
end
|
59
86
|
|
60
87
|
REPOS.keys.each do |name|
|
61
88
|
FileUtils.cd name.to_s
|
62
89
|
puts "Regenerating rbi file for #{name}..."
|
63
90
|
Bundler.with_clean_env do
|
64
|
-
|
91
|
+
if args[:clean]
|
92
|
+
system("bundle exec sord ../#{name}.#{args[:mode]} #{mode_arg} --no-regenerate --no-sord-comments --replace-errors-with-untyped --replace-unresolved-with-untyped")
|
93
|
+
else
|
94
|
+
system("bundle exec sord ../#{name}.#{args[:mode]} #{mode_arg} --no-regenerate")
|
95
|
+
end
|
65
96
|
end
|
66
97
|
FileUtils.cd '..'
|
67
98
|
end
|
68
99
|
|
69
|
-
puts "Re-seeding complete!".green
|
100
|
+
puts Rainbow("Re-seeding complete!").green
|
70
101
|
end
|
71
102
|
|
72
103
|
desc 'Delete the sord_examples directory to allow the seeder to run again.'
|
73
104
|
task :reset do
|
74
105
|
FileUtils.rm_rf 'sord_examples' if File.directory?('sord_examples')
|
75
|
-
puts 'Reset complete.'.green
|
106
|
+
puts Rainbow('Reset complete.').green
|
76
107
|
end
|
77
|
-
end
|
78
108
|
|
109
|
+
desc 'Typecheck each of the sord_examples rbi files.'
|
110
|
+
task :typecheck, [:verbose] do |t, args|
|
111
|
+
results_hash = {}
|
112
|
+
REPOS.each do |name, url|
|
113
|
+
Bundler.with_clean_env do
|
114
|
+
puts "srb tc sord_examples/#{name}.rbi --ignore sord.rbi 2>&1"
|
115
|
+
if args[:verbose]
|
116
|
+
output = system("srb tc sord_examples/#{name}.rbi --ignore sord.rbi 2>&1")
|
117
|
+
else
|
118
|
+
output = `srb tc sord_examples/#{name}.rbi --ignore sord.rbi 2>&1`.split("\n").last
|
119
|
+
results_hash[:"#{name}"] = output
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
unless args[:verbose]
|
125
|
+
puts Rainbow("Errors").bold
|
126
|
+
longest_name = results_hash.keys.map { |name| name.length }.max
|
127
|
+
|
128
|
+
# Replace all values in results_hash with integer by parsing it.
|
129
|
+
results_hash.each do |name, result|
|
130
|
+
result.scan(/Errors\: (\d+)/) { |match| result = match.first.to_i }
|
131
|
+
results_hash[name] = (result == "No errors! Great job.") ? 0 : result
|
132
|
+
end
|
133
|
+
|
134
|
+
# Print the right-aligned name and the number of errors, with different colors depending on the number of errors.
|
135
|
+
results_hash.each do |name, result|
|
136
|
+
spaces_needed = longest_name - name.length
|
137
|
+
output = "#{' ' * spaces_needed}#{name}: #{result}"
|
138
|
+
case result
|
139
|
+
when 0..5
|
140
|
+
puts Rainbow(output).green.bright
|
141
|
+
when 6..25
|
142
|
+
puts Rainbow(output).green
|
143
|
+
when 26..50
|
144
|
+
puts Rainbow(output).red
|
145
|
+
else
|
146
|
+
puts Rainbow(output).red.bright
|
147
|
+
end
|
148
|
+
end
|
149
|
+
# Report the Total.
|
150
|
+
puts Rainbow("#{' ' * (longest_name - 'Total'.length)}Total: #{results_hash.values.inject(0, :+)}").bold
|
151
|
+
end
|
152
|
+
end
|
153
|
+
end
|
data/exe/sord
CHANGED
@@ -10,64 +10,81 @@ program :description, 'Generate Sorbet RBIs from YARD documentation'
|
|
10
10
|
default_command :gen
|
11
11
|
command :gen do |c|
|
12
12
|
c.syntax = 'sord gen <output-file> [options]'
|
13
|
-
c.description = 'Generates
|
14
|
-
c.option '--
|
13
|
+
c.description = 'Generates a type signature file from this directory\'s YARD docs'
|
14
|
+
c.option '--rbi', 'Use Sorbet\'s RBI format'
|
15
|
+
c.option '--rbs', 'Use Steep/Ruby 3\'s RBS format'
|
16
|
+
c.option '--[no-]sord-comments', 'Controls informational/warning comments in the file'
|
15
17
|
c.option '--[no-]regenerate', 'Controls whether YARD is executed before Sord runs'
|
16
18
|
c.option '--break-params INTEGER', Integer, 'Break params onto their own lines if there are this many'
|
17
19
|
c.option '--replace-errors-with-untyped', 'Uses T.untyped rather than SORD_ERROR_ constants'
|
20
|
+
c.option '--replace-unresolved-with-untyped', 'Uses T.untyped when Sord is unable to resolve a constant'
|
18
21
|
c.option '--exclude-messages STRING', String, 'Blacklists a comma-separated string of log message types'
|
19
22
|
c.option '--include-messages STRING', String, 'Whitelists a comma-separated string of log message types'
|
23
|
+
c.option '--keep-original-comments', 'Retains original YARD comments rather than converting them to Markdown'
|
24
|
+
c.option '--skip-constants', 'Excludes constants from generated file'
|
25
|
+
c.option '--use-original-initialize-return', 'Uses the specified return type for #initialize rather than void'
|
20
26
|
|
21
27
|
c.action do |args, options|
|
22
28
|
options.default(
|
23
|
-
|
29
|
+
rbi: false,
|
30
|
+
rbs: false,
|
31
|
+
sord_comments: true,
|
24
32
|
regenerate: true,
|
25
33
|
break_params: 4,
|
26
34
|
replace_errors_with_untyped: false,
|
35
|
+
replace_unresolved_with_untyped: false,
|
27
36
|
exclude_messages: nil,
|
28
37
|
include_messages: nil,
|
38
|
+
keep_original_comments: false,
|
39
|
+
skip_constants: false,
|
40
|
+
use_original_initialize_return: false,
|
29
41
|
)
|
30
42
|
|
31
43
|
if args.length != 1
|
32
44
|
Sord::Logging.error('Must specify filename')
|
33
45
|
exit 1
|
34
46
|
end
|
47
|
+
|
48
|
+
plugin_options = options.__hash__
|
49
|
+
plugin_options[:exclude_options] = plugin_options[:exclude_options]&.split(',')
|
50
|
+
plugin_options[:include_options] = plugin_options[:include_options]&.split(',')
|
35
51
|
|
36
|
-
if
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
Sord::Logging.error('Not all types on your --include-messages list are valid.')
|
51
|
-
Sord::Logging.error("Valid options are: #{Sord::Logging::AVAILABLE_TYPES.map(&:to_s).join(', ')}")
|
52
|
+
if !(plugin_options[:rbi] || plugin_options[:rbs])
|
53
|
+
if args.first
|
54
|
+
if args.first.end_with?('.rbi')
|
55
|
+
Sord::Logging.infer('Assuming from filename you wish to generate in RBI format')
|
56
|
+
plugin_options[:rbi] = true
|
57
|
+
elsif args.first.end_with?('.rbs')
|
58
|
+
Sord::Logging.infer('Assuming from filename you wish to generate in RBS format')
|
59
|
+
plugin_options[:rbs] = true
|
60
|
+
else
|
61
|
+
Sord::Logging.error('An output format could not be inferred from your filename; please specify --rbi or --rbs')
|
62
|
+
exit 1
|
63
|
+
end
|
64
|
+
else
|
65
|
+
Sord::Logging.error('No output format given; please specify --rbi or --rbs')
|
52
66
|
exit 1
|
53
67
|
end
|
54
|
-
Sord::Logging.enabled_types = Sord::Logging::AVAILABLE_TYPES - blacklist
|
55
68
|
end
|
56
69
|
|
57
|
-
if
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
70
|
+
if (plugin_options[:rbi] && plugin_options[:rbs])
|
71
|
+
Sord::Logging.error('You cannot specify both --rbi and --rbs; please use only one')
|
72
|
+
exit 1
|
73
|
+
end
|
74
|
+
|
75
|
+
plugin = Sord::ParlourPlugin.new(plugin_options)
|
76
|
+
|
77
|
+
if plugin_options[:rbi]
|
78
|
+
klass = Parlour::RbiGenerator
|
79
|
+
generator_method = :rbi
|
80
|
+
elsif plugin_options[:rbs]
|
81
|
+
klass = Parlour::RbsGenerator
|
82
|
+
generator_method = :rbs
|
69
83
|
end
|
70
84
|
|
71
|
-
|
85
|
+
plugin.parlour = klass.new(break_params: plugin_options[:break_params])
|
86
|
+
plugin.generate(plugin.parlour.root)
|
87
|
+
|
88
|
+
File.write(args.first, plugin.parlour.send(generator_method))
|
72
89
|
end
|
73
90
|
end
|