parlour 3.0.0 → 5.0.0.beta.3
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 +1 -1
- data/.parlour +5 -0
- data/.rspec +0 -0
- data/.travis.yml +0 -0
- data/CHANGELOG.md +57 -0
- data/CODE_OF_CONDUCT.md +0 -0
- data/Gemfile +0 -0
- data/LICENSE.txt +0 -0
- data/README.md +233 -19
- data/Rakefile +0 -0
- data/exe/parlour +109 -4
- data/lib/parlour.rb +27 -1
- data/lib/parlour/conflict_resolver.rb +31 -9
- data/lib/parlour/conversion/converter.rb +34 -0
- data/lib/parlour/conversion/rbi_to_rbs.rb +223 -0
- data/lib/parlour/debugging.rb +0 -0
- data/lib/parlour/detached_rbi_generator.rb +1 -6
- data/lib/parlour/detached_rbs_generator.rb +25 -0
- data/lib/parlour/generator.rb +34 -0
- data/lib/parlour/kernel_hack.rb +0 -0
- data/lib/parlour/options.rb +71 -0
- data/lib/parlour/parse_error.rb +0 -0
- data/lib/parlour/plugin.rb +1 -1
- data/lib/parlour/rbi_generator.rb +24 -37
- data/lib/parlour/rbi_generator/arbitrary.rb +5 -2
- data/lib/parlour/rbi_generator/attribute.rb +14 -5
- data/lib/parlour/rbi_generator/class_namespace.rb +8 -3
- data/lib/parlour/rbi_generator/constant.rb +28 -8
- data/lib/parlour/rbi_generator/enum_class_namespace.rb +8 -3
- data/lib/parlour/rbi_generator/extend.rb +5 -2
- data/lib/parlour/rbi_generator/include.rb +5 -2
- data/lib/parlour/rbi_generator/method.rb +15 -10
- data/lib/parlour/rbi_generator/module_namespace.rb +7 -2
- data/lib/parlour/rbi_generator/namespace.rb +68 -18
- data/lib/parlour/rbi_generator/parameter.rb +13 -7
- data/lib/parlour/rbi_generator/rbi_object.rb +19 -78
- data/lib/parlour/rbi_generator/struct_class_namespace.rb +9 -2
- data/lib/parlour/rbi_generator/struct_prop.rb +12 -9
- data/lib/parlour/rbi_generator/type_alias.rb +101 -0
- data/lib/parlour/rbs_generator.rb +24 -0
- data/lib/parlour/rbs_generator/arbitrary.rb +92 -0
- data/lib/parlour/rbs_generator/attribute.rb +82 -0
- data/lib/parlour/rbs_generator/block.rb +49 -0
- data/lib/parlour/rbs_generator/class_namespace.rb +106 -0
- data/lib/parlour/rbs_generator/constant.rb +95 -0
- data/lib/parlour/rbs_generator/extend.rb +92 -0
- data/lib/parlour/rbs_generator/include.rb +92 -0
- data/lib/parlour/rbs_generator/interface_namespace.rb +34 -0
- data/lib/parlour/rbs_generator/method.rb +146 -0
- data/lib/parlour/rbs_generator/method_signature.rb +104 -0
- data/lib/parlour/rbs_generator/module_namespace.rb +35 -0
- data/lib/parlour/rbs_generator/namespace.rb +627 -0
- data/lib/parlour/rbs_generator/parameter.rb +146 -0
- data/lib/parlour/rbs_generator/rbs_object.rb +78 -0
- data/lib/parlour/rbs_generator/type_alias.rb +96 -0
- data/lib/parlour/type_loader.rb +25 -12
- data/lib/parlour/type_parser.rb +174 -17
- data/lib/parlour/typed_object.rb +87 -0
- data/lib/parlour/types.rb +539 -0
- data/lib/parlour/version.rb +1 -1
- data/parlour.gemspec +1 -1
- data/plugin_examples/foobar_plugin.rb +0 -0
- data/rbi/parlour.rbi +1856 -0
- metadata +35 -10
- data/lib/parlour/rbi_generator/options.rb +0 -74
@@ -1,11 +1,11 @@
|
|
1
1
|
# typed: true
|
2
2
|
module Parlour
|
3
|
-
class RbiGenerator
|
3
|
+
class RbiGenerator < Generator
|
4
4
|
# Represents an +include+ call.
|
5
5
|
class Include < RbiObject
|
6
6
|
sig do
|
7
7
|
params(
|
8
|
-
generator:
|
8
|
+
generator: Generator,
|
9
9
|
name: String,
|
10
10
|
block: T.nilable(T.proc.params(x: Include).void)
|
11
11
|
).void
|
@@ -82,6 +82,9 @@ module Parlour
|
|
82
82
|
def describe
|
83
83
|
"Include (#{name})"
|
84
84
|
end
|
85
|
+
|
86
|
+
sig { override.void }
|
87
|
+
def generalize_from_rbi!; end # Nothing to do
|
85
88
|
end
|
86
89
|
end
|
87
90
|
end
|
@@ -1,16 +1,16 @@
|
|
1
1
|
# typed: true
|
2
2
|
module Parlour
|
3
|
-
class RbiGenerator
|
3
|
+
class RbiGenerator < Generator
|
4
4
|
# Represents a method definition.
|
5
5
|
class Method < RbiObject
|
6
6
|
extend T::Sig
|
7
7
|
|
8
8
|
sig do
|
9
9
|
params(
|
10
|
-
generator:
|
10
|
+
generator: Generator,
|
11
11
|
name: String,
|
12
12
|
parameters: T::Array[Parameter],
|
13
|
-
return_type: T.nilable(
|
13
|
+
return_type: T.nilable(Types::TypeLike),
|
14
14
|
abstract: T::Boolean,
|
15
15
|
implementation: T::Boolean,
|
16
16
|
override: T::Boolean,
|
@@ -29,8 +29,7 @@ module Parlour
|
|
29
29
|
# this - use the +class_method+ parameter instead.
|
30
30
|
# @param parameters [Array<Parameter>] An array of {Parameter} instances representing this
|
31
31
|
# method's parameters.
|
32
|
-
# @param return_type [
|
33
|
-
# +"String"+ or +"T.untyped"+. Passing nil denotes a void return.
|
32
|
+
# @param return_type [Types::TypeLike, nil] What this method returns. Passing nil denotes a void return.
|
34
33
|
# @param abstract [Boolean] Whether this method is abstract.
|
35
34
|
# @param implementation [Boolean] DEPRECATED: Whether this method is an
|
36
35
|
# implementation of a parent abstract method.
|
@@ -82,10 +81,9 @@ module Parlour
|
|
82
81
|
# @return [Array<Parameter>]
|
83
82
|
attr_reader :parameters
|
84
83
|
|
85
|
-
sig { returns(T.nilable(
|
86
|
-
#
|
87
|
-
#
|
88
|
-
# @return [String, nil]
|
84
|
+
sig { returns(T.nilable(Types::TypeLike)) }
|
85
|
+
# What this method returns. Passing nil denotes a void return.
|
86
|
+
# @return [Types::TypeLike, nil]
|
89
87
|
attr_reader :return_type
|
90
88
|
|
91
89
|
sig { returns(T::Boolean) }
|
@@ -140,7 +138,7 @@ module Parlour
|
|
140
138
|
# @param options [Options] The formatting options to use.
|
141
139
|
# @return [Array<String>] The RBI lines, formatted as specified.
|
142
140
|
def generate_rbi(indent_level, options)
|
143
|
-
return_call = return_type ? "returns(#{return_type})" : 'void'
|
141
|
+
return_call = @return_type ? "returns(#{String === @return_type ? @return_type : @return_type.generate_rbi})" : 'void'
|
144
142
|
sig_args = final ? '(:final)' : ''
|
145
143
|
|
146
144
|
sig_params = parameters.map(&:to_sig_param)
|
@@ -218,6 +216,13 @@ module Parlour
|
|
218
216
|
" returns #{return_type}"
|
219
217
|
end
|
220
218
|
|
219
|
+
sig { override.void }
|
220
|
+
def generalize_from_rbi!
|
221
|
+
@return_type = TypeParser.parse_single_type(@return_type) if String === @return_type
|
222
|
+
|
223
|
+
parameters.each(&:generalize_from_rbi!)
|
224
|
+
end
|
225
|
+
|
221
226
|
private
|
222
227
|
|
223
228
|
sig do
|
@@ -1,13 +1,13 @@
|
|
1
1
|
# typed: true
|
2
2
|
module Parlour
|
3
|
-
class RbiGenerator
|
3
|
+
class RbiGenerator < Generator
|
4
4
|
# Represents a module definition.
|
5
5
|
class ModuleNamespace < Namespace
|
6
6
|
extend T::Sig
|
7
7
|
|
8
8
|
sig do
|
9
9
|
params(
|
10
|
-
generator:
|
10
|
+
generator: Generator,
|
11
11
|
name: String,
|
12
12
|
final: T::Boolean,
|
13
13
|
interface: T::Boolean,
|
@@ -96,6 +96,11 @@ module Parlour
|
|
96
96
|
"Module #{name} - #{"interface, " if interface}#{children.length} " +
|
97
97
|
"children, #{includes.length} includes, #{extends.length} extends"
|
98
98
|
end
|
99
|
+
|
100
|
+
sig { override.void }
|
101
|
+
def generalize_from_rbi!
|
102
|
+
super
|
103
|
+
end
|
99
104
|
end
|
100
105
|
end
|
101
106
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# typed: true
|
2
2
|
module Parlour
|
3
|
-
class RbiGenerator
|
3
|
+
class RbiGenerator < Generator
|
4
4
|
# A generic namespace. This shouldn't be used, except as the type of
|
5
5
|
# {RbiGenerator#root}.
|
6
6
|
class Namespace < RbiObject
|
@@ -24,7 +24,7 @@ module Parlour
|
|
24
24
|
|
25
25
|
sig do
|
26
26
|
params(
|
27
|
-
generator:
|
27
|
+
generator: Generator,
|
28
28
|
name: T.nilable(String),
|
29
29
|
final: T::Boolean,
|
30
30
|
block: T.nilable(T.proc.params(x: Namespace).void)
|
@@ -77,6 +77,17 @@ module Parlour
|
|
77
77
|
)
|
78
78
|
end
|
79
79
|
|
80
|
+
sig { returns(T::Array[RbiGenerator::TypeAlias]) }
|
81
|
+
# The {RbiGenerator::TypeAlias} objects from {children}.
|
82
|
+
# @return [Array<RbiGenerator::TypeAlias>]
|
83
|
+
def aliases
|
84
|
+
T.cast(
|
85
|
+
children.select { |c| c.is_a?(RbiGenerator::TypeAlias) },
|
86
|
+
T::Array[RbiGenerator::TypeAlias]
|
87
|
+
)
|
88
|
+
end
|
89
|
+
alias type_aliases aliases
|
90
|
+
|
80
91
|
sig { returns(T::Array[RbiGenerator::Constant]) }
|
81
92
|
# The {RbiGenerator::Constant} objects from {children}.
|
82
93
|
# @return [Array<RbiGenerator::Constant>]
|
@@ -260,8 +271,8 @@ module Parlour
|
|
260
271
|
params(
|
261
272
|
name: String,
|
262
273
|
parameters: T.nilable(T::Array[Parameter]),
|
263
|
-
return_type: T.nilable(
|
264
|
-
returns: T.nilable(
|
274
|
+
return_type: T.nilable(Types::TypeLike),
|
275
|
+
returns: T.nilable(Types::TypeLike),
|
265
276
|
abstract: T::Boolean,
|
266
277
|
implementation: T::Boolean,
|
267
278
|
override: T::Boolean,
|
@@ -320,7 +331,7 @@ module Parlour
|
|
320
331
|
params(
|
321
332
|
name: String,
|
322
333
|
kind: Symbol,
|
323
|
-
type:
|
334
|
+
type: Types::TypeLike,
|
324
335
|
class_attribute: T::Boolean,
|
325
336
|
block: T.nilable(T.proc.params(x: Attribute).void)
|
326
337
|
).returns(Attribute)
|
@@ -376,7 +387,7 @@ module Parlour
|
|
376
387
|
sig do
|
377
388
|
params(
|
378
389
|
name: String,
|
379
|
-
type:
|
390
|
+
type: Types::TypeLike,
|
380
391
|
class_attribute: T::Boolean,
|
381
392
|
block: T.nilable(T.proc.params(x: Attribute).void)
|
382
393
|
).returns(Attribute)
|
@@ -397,7 +408,7 @@ module Parlour
|
|
397
408
|
sig do
|
398
409
|
params(
|
399
410
|
name: String,
|
400
|
-
type:
|
411
|
+
type: Types::TypeLike,
|
401
412
|
class_attribute: T::Boolean,
|
402
413
|
block: T.nilable(T.proc.params(x: Attribute).void)
|
403
414
|
).returns(Attribute)
|
@@ -418,7 +429,7 @@ module Parlour
|
|
418
429
|
sig do
|
419
430
|
params(
|
420
431
|
name: String,
|
421
|
-
type:
|
432
|
+
type: Types::TypeLike,
|
422
433
|
class_attribute: T::Boolean,
|
423
434
|
block: T.nilable(T.proc.params(x: Attribute).void)
|
424
435
|
).returns(Attribute)
|
@@ -527,7 +538,7 @@ module Parlour
|
|
527
538
|
returned_includables
|
528
539
|
end
|
529
540
|
|
530
|
-
sig { params(name: String, value: String, block: T.nilable(T.proc.params(x: Constant).void)).returns(Constant) }
|
541
|
+
sig { params(name: String, value: String, eigen_constant: T::Boolean, block: T.nilable(T.proc.params(x: Constant).void)).returns(Constant) }
|
531
542
|
# Adds a new constant definition to this namespace.
|
532
543
|
#
|
533
544
|
# @example Add an +Elem+ constant to the class.
|
@@ -535,13 +546,16 @@ module Parlour
|
|
535
546
|
#
|
536
547
|
# @param name [String] The name of the constant.
|
537
548
|
# @param value [String] The value of the constant, as a Ruby code string.
|
549
|
+
# @param eigen_constant [Boolean] Whether this constant is defined on the
|
550
|
+
# eigenclass of the current namespace.
|
538
551
|
# @param block A block which the new instance yields itself to.
|
539
552
|
# @return [RbiGenerator::Constant]
|
540
|
-
def create_constant(name, value:, &block)
|
553
|
+
def create_constant(name, value:, eigen_constant: false, &block)
|
541
554
|
new_constant = RbiGenerator::Constant.new(
|
542
555
|
generator,
|
543
556
|
name: name,
|
544
557
|
value: value,
|
558
|
+
eigen_constant: eigen_constant,
|
545
559
|
&block
|
546
560
|
)
|
547
561
|
move_next_comments(new_constant)
|
@@ -549,7 +563,7 @@ module Parlour
|
|
549
563
|
new_constant
|
550
564
|
end
|
551
565
|
|
552
|
-
sig { params(name: String, type:
|
566
|
+
sig { params(name: String, type: Types::TypeLike, block: T.nilable(T.proc.params(x: TypeAlias).void)).returns(TypeAlias) }
|
553
567
|
# Adds a new type alias, in the form of a constant, to this namespace.
|
554
568
|
#
|
555
569
|
# @example Add a +MyType+ type alias, to +Integer+, to the class.
|
@@ -560,7 +574,15 @@ module Parlour
|
|
560
574
|
# @param block A block which the new instance yields itself to.
|
561
575
|
# @return [RbiGenerator::Constant]
|
562
576
|
def create_type_alias(name, type:, &block)
|
563
|
-
|
577
|
+
new_type_alias = RbiGenerator::TypeAlias.new(
|
578
|
+
generator,
|
579
|
+
name: name,
|
580
|
+
type: type,
|
581
|
+
&block
|
582
|
+
)
|
583
|
+
move_next_comments(new_type_alias)
|
584
|
+
children << new_type_alias
|
585
|
+
new_type_alias
|
564
586
|
end
|
565
587
|
|
566
588
|
sig do
|
@@ -612,12 +634,17 @@ module Parlour
|
|
612
634
|
"includes, #{extends.length} extends, #{constants.length} constants"
|
613
635
|
end
|
614
636
|
|
637
|
+
sig { override.void }
|
638
|
+
def generalize_from_rbi!
|
639
|
+
children.each(&:generalize_from_rbi!)
|
640
|
+
end
|
641
|
+
|
615
642
|
private
|
616
643
|
|
617
644
|
sig do
|
618
645
|
overridable.params(
|
619
646
|
indent_level: Integer,
|
620
|
-
options: Options
|
647
|
+
options: Options,
|
621
648
|
).returns(T::Array[String])
|
622
649
|
end
|
623
650
|
# Generates the RBI lines for the body of this namespace. This consists of
|
@@ -631,14 +658,22 @@ module Parlour
|
|
631
658
|
|
632
659
|
result += [options.indented(indent_level, 'final!'), ''] if final
|
633
660
|
|
634
|
-
|
661
|
+
# Split away the eigen constants; these need to be put in a
|
662
|
+
# "class << self" block later
|
663
|
+
eigen_constants, non_eigen_constants = constants.partition(&:eigen_constant)
|
664
|
+
eigen_constants.sort_by!(&:name) if options.sort_namespaces
|
665
|
+
|
666
|
+
if includes.any? || extends.any? || aliases.any? || non_eigen_constants.any?
|
635
667
|
result += (options.sort_namespaces ? includes.sort_by(&:name) : includes)
|
636
668
|
.flat_map { |x| x.generate_rbi(indent_level, options) }
|
637
669
|
.reject { |x| x.strip == '' }
|
638
670
|
result += (options.sort_namespaces ? extends.sort_by(&:name) : extends)
|
639
671
|
.flat_map { |x| x.generate_rbi(indent_level, options) }
|
640
672
|
.reject { |x| x.strip == '' }
|
641
|
-
result += (options.sort_namespaces ?
|
673
|
+
result += (options.sort_namespaces ? aliases.sort_by(&:name) : aliases)
|
674
|
+
.flat_map { |x| x.generate_rbi(indent_level, options) }
|
675
|
+
.reject { |x| x.strip == '' }
|
676
|
+
result += (options.sort_namespaces ? non_eigen_constants.sort_by(&:name) : non_eigen_constants)
|
642
677
|
.flat_map { |x| x.generate_rbi(indent_level, options) }
|
643
678
|
.reject { |x| x.strip == '' }
|
644
679
|
result << ""
|
@@ -658,21 +693,36 @@ module Parlour
|
|
658
693
|
child.is_a?(Attribute) && child.class_attribute
|
659
694
|
end
|
660
695
|
|
661
|
-
|
662
|
-
|
696
|
+
# Handle the "class << self block"
|
697
|
+
result << options.indented(indent_level, 'class << self') \
|
698
|
+
if class_attributes.any? || eigen_constants.any?
|
699
|
+
|
700
|
+
if eigen_constants.any?
|
701
|
+
first, *rest = eigen_constants
|
702
|
+
result += T.must(first).generate_rbi(indent_level + 1, options) + T.must(rest)
|
703
|
+
.map { |obj| obj.generate_rbi(indent_level + 1, options) }
|
704
|
+
.map { |lines| [""] + lines }
|
705
|
+
.flatten
|
706
|
+
end
|
707
|
+
|
708
|
+
result << '' if eigen_constants.any? && class_attributes.any?
|
663
709
|
|
710
|
+
if class_attributes.any?
|
664
711
|
first, *rest = class_attributes
|
665
712
|
result += T.must(first).generate_rbi(indent_level + 1, options) + T.must(rest)
|
666
713
|
.map { |obj| obj.generate_rbi(indent_level + 1, options) }
|
667
714
|
.map { |lines| [""] + lines }
|
668
715
|
.flatten
|
716
|
+
end
|
717
|
+
|
718
|
+
if class_attributes.any? || eigen_constants.any?
|
669
719
|
result << options.indented(indent_level, 'end')
|
670
720
|
result << ''
|
671
721
|
end
|
672
722
|
|
673
723
|
first, *rest = remaining_children.reject do |child|
|
674
724
|
# We already processed these kinds of children
|
675
|
-
child.is_a?(Include) || child.is_a?(Extend) || child.is_a?(Constant)
|
725
|
+
child.is_a?(Include) || child.is_a?(Extend) || child.is_a?(Constant) || child.is_a?(TypeAlias)
|
676
726
|
end
|
677
727
|
unless first
|
678
728
|
# Remove any trailing whitespace due to includes or class attributes
|
@@ -1,6 +1,7 @@
|
|
1
1
|
# typed: true
|
2
|
+
require 'rainbow'
|
2
3
|
module Parlour
|
3
|
-
class RbiGenerator
|
4
|
+
class RbiGenerator < Generator
|
4
5
|
# Represents a method parameter with a Sorbet type signature.
|
5
6
|
class Parameter
|
6
7
|
extend T::Sig
|
@@ -8,7 +9,7 @@ module Parlour
|
|
8
9
|
sig do
|
9
10
|
params(
|
10
11
|
name: String,
|
11
|
-
type: T.nilable(
|
12
|
+
type: T.nilable(Types::TypeLike),
|
12
13
|
default: T.nilable(String)
|
13
14
|
).void
|
14
15
|
end
|
@@ -42,7 +43,7 @@ module Parlour
|
|
42
43
|
|
43
44
|
@kind = :keyword if kind == :normal && name.end_with?(':')
|
44
45
|
|
45
|
-
@type = type
|
46
|
+
@type = type || 'T.untyped'
|
46
47
|
@default = default
|
47
48
|
end
|
48
49
|
|
@@ -80,10 +81,10 @@ module Parlour
|
|
80
81
|
T.must(name[prefix.length..-1])
|
81
82
|
end
|
82
83
|
|
83
|
-
sig { returns(
|
84
|
+
sig { returns(Types::TypeLike) }
|
84
85
|
# A Sorbet string of this parameter's type, such as +"String"+ or
|
85
86
|
# +"T.untyped"+.
|
86
|
-
# @return [String
|
87
|
+
# @return [String]
|
87
88
|
attr_reader :type
|
88
89
|
|
89
90
|
sig { returns(T.nilable(String)) }
|
@@ -118,8 +119,8 @@ module Parlour
|
|
118
119
|
#
|
119
120
|
# @return [String]
|
120
121
|
def to_sig_param
|
121
|
-
"#{name_without_kind}: #{type
|
122
|
-
end
|
122
|
+
"#{name_without_kind}: #{String === @type ? @type : @type.generate_rbi}"
|
123
|
+
end
|
123
124
|
|
124
125
|
# A mapping of {kind} values to the characteristic prefixes each kind has.
|
125
126
|
PREFIXES = {
|
@@ -128,6 +129,11 @@ module Parlour
|
|
128
129
|
double_splat: '**',
|
129
130
|
block: '&'
|
130
131
|
}.freeze
|
132
|
+
|
133
|
+
sig { void }
|
134
|
+
def generalize_from_rbi!
|
135
|
+
@type = TypeParser.parse_single_type(@type) if String === @type
|
136
|
+
end
|
131
137
|
end
|
132
138
|
end
|
133
139
|
end
|
@@ -1,17 +1,15 @@
|
|
1
1
|
# typed: true
|
2
2
|
module Parlour
|
3
|
-
class RbiGenerator
|
3
|
+
class RbiGenerator < Generator
|
4
4
|
# An abstract class which is subclassed by any classes which can generate
|
5
5
|
# entire lines of an RBI, such as {Namespace} and {Method}. (As an example,
|
6
6
|
# {Parameter} is _not_ a subclass because it does not generate lines, only
|
7
7
|
# segments of definition and signature lines.)
|
8
8
|
# @abstract
|
9
|
-
class RbiObject
|
10
|
-
extend T::Helpers
|
11
|
-
extend T::Sig
|
9
|
+
class RbiObject < TypedObject
|
12
10
|
abstract!
|
13
|
-
|
14
|
-
sig { params(generator:
|
11
|
+
|
12
|
+
sig { params(generator: Generator, name: String).void }
|
15
13
|
# Creates a new RBI object.
|
16
14
|
# @note Don't call this directly.
|
17
15
|
#
|
@@ -19,60 +17,16 @@ module Parlour
|
|
19
17
|
# @param name [String] The name of this module.
|
20
18
|
# @return [void]
|
21
19
|
def initialize(generator, name)
|
20
|
+
super(name)
|
22
21
|
@generator = generator
|
23
|
-
@generated_by = generator.current_plugin
|
24
|
-
@name = name
|
25
|
-
@comments = []
|
22
|
+
@generated_by = RbiGenerator === generator ? generator.current_plugin : nil
|
26
23
|
end
|
27
24
|
|
28
|
-
sig { returns(
|
25
|
+
sig { returns(Generator) }
|
29
26
|
# The generator which this object belongs to.
|
30
|
-
# @return [
|
27
|
+
# @return [Generator]
|
31
28
|
attr_reader :generator
|
32
29
|
|
33
|
-
sig { returns(T.nilable(Plugin)) }
|
34
|
-
# The {Plugin} which was controlling the {generator} when this object was
|
35
|
-
# created.
|
36
|
-
# @return [Plugin, nil]
|
37
|
-
attr_reader :generated_by
|
38
|
-
|
39
|
-
sig { returns(String) }
|
40
|
-
# The name of this object.
|
41
|
-
# @return [String]
|
42
|
-
attr_reader :name
|
43
|
-
|
44
|
-
sig { returns(T::Array[String]) }
|
45
|
-
# An array of comments which will be placed above the object in the RBI
|
46
|
-
# file.
|
47
|
-
# @return [Array<String>]
|
48
|
-
attr_reader :comments
|
49
|
-
|
50
|
-
sig { params(comment: T.any(String, T::Array[String])).void }
|
51
|
-
# Adds one or more comments to this RBI object. Comments always go above
|
52
|
-
# the definition for this object, not in the definition's body.
|
53
|
-
#
|
54
|
-
# @example Creating a module with a comment.
|
55
|
-
# namespace.create_module('M') do |m|
|
56
|
-
# m.add_comment('This is a module')
|
57
|
-
# end
|
58
|
-
#
|
59
|
-
# @example Creating a class with a multi-line comment.
|
60
|
-
# namespace.create_class('C') do |c|
|
61
|
-
# c.add_comment(['This is a multi-line comment!', 'It can be as long as you want!'])
|
62
|
-
# end
|
63
|
-
#
|
64
|
-
# @param comment [String, Array<String>] The new comment(s).
|
65
|
-
# @return [void]
|
66
|
-
def add_comment(comment)
|
67
|
-
if comment.is_a?(String)
|
68
|
-
comments << comment
|
69
|
-
elsif comment.is_a?(Array)
|
70
|
-
comments.concat(comment)
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
alias_method :add_comments, :add_comment
|
75
|
-
|
76
30
|
sig do
|
77
31
|
abstract.params(
|
78
32
|
indent_level: Integer,
|
@@ -115,32 +69,19 @@ module Parlour
|
|
115
69
|
# @return [void]
|
116
70
|
def merge_into_self(others); end
|
117
71
|
|
118
|
-
sig {
|
119
|
-
|
120
|
-
|
121
|
-
#
|
122
|
-
# @abstract
|
123
|
-
# @return [String]
|
124
|
-
def describe; end
|
125
|
-
|
126
|
-
private
|
127
|
-
|
128
|
-
sig do
|
129
|
-
params(
|
130
|
-
indent_level: Integer,
|
131
|
-
options: Options
|
132
|
-
).returns(T::Array[String])
|
72
|
+
sig { override.overridable.returns(String) }
|
73
|
+
def describe
|
74
|
+
'RBI object'
|
133
75
|
end
|
134
|
-
|
76
|
+
|
77
|
+
sig { abstract.void }
|
78
|
+
# Assuming that the types throughout this object and its children have
|
79
|
+
# been specified as RBI-style types, generalises them into type instances
|
80
|
+
# from the {Parlour::Types} module.
|
135
81
|
#
|
136
|
-
# @
|
137
|
-
# @
|
138
|
-
|
139
|
-
def generate_comments(indent_level, options)
|
140
|
-
comments.any? \
|
141
|
-
? comments.map { |c| options.indented(indent_level, "# #{c}") }
|
142
|
-
: []
|
143
|
-
end
|
82
|
+
# @abstract
|
83
|
+
# @return [void]
|
84
|
+
def generalize_from_rbi!; end
|
144
85
|
end
|
145
86
|
end
|
146
87
|
end
|