parlour 0.8.1 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +13 -0
- data/README.md +6 -5
- data/exe/parlour +5 -3
- data/lib/parlour.rb +1 -0
- data/lib/parlour/rbi_generator/class_namespace.rb +4 -2
- data/lib/parlour/rbi_generator/enum_class_namespace.rb +90 -0
- data/lib/parlour/rbi_generator/method.rb +14 -4
- data/lib/parlour/rbi_generator/module_namespace.rb +4 -2
- data/lib/parlour/rbi_generator/namespace.rb +67 -9
- data/lib/parlour/version.rb +1 -1
- data/parlour.gemspec +1 -0
- metadata +17 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f603ddca16331f43a36b4120b7d12aa5a4b7c83f753e8527b91bc1391109e9fe
|
4
|
+
data.tar.gz: f550cdf4cc358dd6ac0c21853ad26756d4729c7f28f3695af53d25775b3f45f0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a962191c42becbe6dbe213eb63be142df100643786006093e5663af51f80049890c26ff8974b718cfd89198387cf0ec801b8d3e10cbf032aaf3aa86f746fda97
|
7
|
+
data.tar.gz: 1bfafd7afbcf81105379d7b747e0c204e47fdd593b0b1a67e659275b0ebd8d236753e48b5bc05896e1e1759ac6495ad3e8132f85a497f28b35c436ddb3cb1585
|
data/CHANGELOG.md
CHANGED
@@ -3,6 +3,19 @@ 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
|
+
## [1.0.0] - 2019-11-22
|
7
|
+
### Added
|
8
|
+
- `T::Enum` classes have been implemented, and can be generated using
|
9
|
+
`#create_enum_class`.
|
10
|
+
- Methods and namespaces can now be made final using the `final:` keyword
|
11
|
+
argument.
|
12
|
+
- Type aliases can be created on namespaces using `#create_type_alias`.
|
13
|
+
- The `.parlour` file can now have globs in `relative_requires` to load many
|
14
|
+
files matching a pattern at once.
|
15
|
+
|
16
|
+
### Fixed
|
17
|
+
- Commander is now a gemspec dependency.
|
18
|
+
|
6
19
|
## [0.8.1] - 2019-09-27
|
7
20
|
### Added
|
8
21
|
- Running with the PARLOUR_DEBUG environment variable set will now print debug
|
data/README.md
CHANGED
@@ -9,7 +9,7 @@ Parlour is an RBI generator and merger for Sorbet. It consists of two key parts:
|
|
9
9
|
an intuitive DSL.
|
10
10
|
|
11
11
|
- The plugin/build system, which allows multiple Parlour plugins to generate
|
12
|
-
RBIs for the same codebase. These are combined automatically as much as
|
12
|
+
RBIs for the same codebase. These are combined automatically as much as
|
13
13
|
possible, but any other conflicts can be resolved manually through prompts.
|
14
14
|
|
15
15
|
## Why should I use this?
|
@@ -64,7 +64,7 @@ end
|
|
64
64
|
```
|
65
65
|
|
66
66
|
### Writing a plugin
|
67
|
-
Plugins are better than using the generator alone, as your plugin can be
|
67
|
+
Plugins are better than using the generator alone, as your plugin can be
|
68
68
|
combined with others to produce larger RBIs without conflicts.
|
69
69
|
|
70
70
|
We could write the above example as a plugin like this:
|
@@ -102,7 +102,8 @@ output_file: output.rbi
|
|
102
102
|
|
103
103
|
relative_requires:
|
104
104
|
- plugin.rb
|
105
|
-
|
105
|
+
- app/models/*.rb
|
106
|
+
|
106
107
|
plugins:
|
107
108
|
MyPlugin: {}
|
108
109
|
```
|
@@ -125,7 +126,7 @@ output_file: output.rbi
|
|
125
126
|
|
126
127
|
requires:
|
127
128
|
- parlour-gem
|
128
|
-
|
129
|
+
|
129
130
|
plugins:
|
130
131
|
MyPlugin: {}
|
131
132
|
```
|
@@ -139,7 +140,7 @@ requires:
|
|
139
140
|
- gem1
|
140
141
|
- gem2
|
141
142
|
- gem3
|
142
|
-
|
143
|
+
|
143
144
|
plugins:
|
144
145
|
Gem1::Plugin: {}
|
145
146
|
Gem2::Plugin: {}
|
data/exe/parlour
CHANGED
@@ -36,7 +36,9 @@ command :run do |c|
|
|
36
36
|
|
37
37
|
configuration[:requires].each { |source| require(source) }
|
38
38
|
configuration[:relative_requires].each do |source|
|
39
|
-
|
39
|
+
Dir[File.join(Dir.pwd, source)].each do |file|
|
40
|
+
require_relative(file)
|
41
|
+
end
|
40
42
|
end
|
41
43
|
|
42
44
|
# Collect the instances of each plugin into an array
|
@@ -82,7 +84,7 @@ command :run do |c|
|
|
82
84
|
unique_strictness_levels = requested_strictness_levels.uniq
|
83
85
|
if unique_strictness_levels.empty?
|
84
86
|
# If no requests were made, just use the default
|
85
|
-
strictness = 'strong'
|
87
|
+
strictness = 'strong'
|
86
88
|
else
|
87
89
|
# Sort the strictnesses into "strictness order" and pick the weakest
|
88
90
|
strictness = unique_strictness_levels.min_by do |level|
|
@@ -94,7 +96,7 @@ command :run do |c|
|
|
94
96
|
puts Rainbow('Note: ').yellow.bold + "Plugins specified multiple strictness levels, chose the weakest (#{strictness})"
|
95
97
|
end
|
96
98
|
end
|
97
|
-
|
99
|
+
|
98
100
|
# Write the final RBI
|
99
101
|
File.write(configuration[:output_file], gen.rbi(strictness))
|
100
102
|
end
|
data/lib/parlour.rb
CHANGED
@@ -21,6 +21,7 @@ require 'parlour/rbi_generator/constant'
|
|
21
21
|
require 'parlour/rbi_generator/namespace'
|
22
22
|
require 'parlour/rbi_generator/module_namespace'
|
23
23
|
require 'parlour/rbi_generator/class_namespace'
|
24
|
+
require 'parlour/rbi_generator/enum_class_namespace'
|
24
25
|
require 'parlour/rbi_generator'
|
25
26
|
|
26
27
|
require 'parlour/conflict_resolver'
|
@@ -9,6 +9,7 @@ module Parlour
|
|
9
9
|
params(
|
10
10
|
generator: RbiGenerator,
|
11
11
|
name: String,
|
12
|
+
final: T::Boolean,
|
12
13
|
superclass: T.nilable(String),
|
13
14
|
abstract: T::Boolean,
|
14
15
|
block: T.nilable(T.proc.params(x: ClassNamespace).void)
|
@@ -19,13 +20,14 @@ module Parlour
|
|
19
20
|
#
|
20
21
|
# @param generator [RbiGenerator] The current RbiGenerator.
|
21
22
|
# @param name [String] The name of this class.
|
23
|
+
# @param final [Boolean] Whether this namespace is final.
|
22
24
|
# @param superclass [String, nil] The superclass of this class, or nil if it doesn't
|
23
25
|
# have one.
|
24
26
|
# @param abstract [Boolean] A boolean indicating whether this class is abstract.
|
25
27
|
# @param block A block which the new instance yields itself to.
|
26
28
|
# @return [void]
|
27
|
-
def initialize(generator, name, superclass, abstract, &block)
|
28
|
-
super(generator, name, &block)
|
29
|
+
def initialize(generator, name, final, superclass, abstract, &block)
|
30
|
+
super(generator, name, final, &block)
|
29
31
|
@superclass = superclass
|
30
32
|
@abstract = abstract
|
31
33
|
end
|
@@ -0,0 +1,90 @@
|
|
1
|
+
# typed: true
|
2
|
+
module Parlour
|
3
|
+
class RbiGenerator
|
4
|
+
# Represents an enum definition; that is, a class with an +enum+ call.
|
5
|
+
class EnumClassNamespace < ClassNamespace
|
6
|
+
extend T::Sig
|
7
|
+
|
8
|
+
sig do
|
9
|
+
params(
|
10
|
+
generator: RbiGenerator,
|
11
|
+
name: String,
|
12
|
+
final: T::Boolean,
|
13
|
+
enums: T::Array[T.any([String, String], String)],
|
14
|
+
abstract: T::Boolean,
|
15
|
+
block: T.nilable(T.proc.params(x: EnumClassNamespace).void)
|
16
|
+
).void
|
17
|
+
end
|
18
|
+
# Creates a new enum class definition.
|
19
|
+
# @note You should use {Namespace#create_class} rather than this directly.
|
20
|
+
#
|
21
|
+
# @param generator [RbiGenerator] The current RbiGenerator.
|
22
|
+
# @param name [String] The name of this class.
|
23
|
+
# @param final [Boolean] Whether this namespace is final.
|
24
|
+
# @param enums [Array<(String, String), String>] The values of the enumeration.
|
25
|
+
# @param abstract [Boolean] A boolean indicating whether this class is abstract.
|
26
|
+
# @param block A block which the new instance yields itself to.
|
27
|
+
# @return [void]
|
28
|
+
def initialize(generator, name, final, enums, abstract, &block)
|
29
|
+
super(generator, name, final, 'T::Enum', abstract, &block)
|
30
|
+
@enums = enums
|
31
|
+
end
|
32
|
+
|
33
|
+
sig { returns(T::Array[T.any([String, String], String)]) }
|
34
|
+
# The values of the enumeration.
|
35
|
+
# @return [Array<(String, String), String>]
|
36
|
+
attr_reader :enums
|
37
|
+
|
38
|
+
sig do
|
39
|
+
override.params(
|
40
|
+
indent_level: Integer,
|
41
|
+
options: Options
|
42
|
+
).returns(T::Array[String])
|
43
|
+
end
|
44
|
+
# Generates the RBI lines for the body of this enum. This consists of
|
45
|
+
# {enums}, {includes}, {extends} and {children}.
|
46
|
+
#
|
47
|
+
# @param indent_level [Integer] The indentation level to generate the lines at.
|
48
|
+
# @param options [Options] The formatting options to use.
|
49
|
+
# @return [Array<String>] The RBI lines for the body, formatted as specified.
|
50
|
+
def generate_body(indent_level, options)
|
51
|
+
result = [options.indented(indent_level, 'enums do')]
|
52
|
+
enums.each do |enum_value|
|
53
|
+
case enum_value
|
54
|
+
when String
|
55
|
+
line = "#{enum_value} = new"
|
56
|
+
when Array
|
57
|
+
line = "#{enum_value[0]} = new(#{enum_value[1]})"
|
58
|
+
else
|
59
|
+
T.absurd(enum_value)
|
60
|
+
end
|
61
|
+
|
62
|
+
result << options.indented(indent_level + 1, line)
|
63
|
+
end
|
64
|
+
result << options.indented(indent_level, 'end')
|
65
|
+
result << ''
|
66
|
+
|
67
|
+
result + super
|
68
|
+
end
|
69
|
+
|
70
|
+
sig do
|
71
|
+
override.params(
|
72
|
+
others: T::Array[RbiGenerator::RbiObject]
|
73
|
+
).returns(T::Boolean)
|
74
|
+
end
|
75
|
+
# Given an array of {EnumClassNamespace} instances, returns true if they may
|
76
|
+
# be merged into this instance using {merge_into_self}. For instances to
|
77
|
+
# be mergeable, they must either all be abstract or all not be abstract,
|
78
|
+
# and they must define the same superclass (or none at all).
|
79
|
+
#
|
80
|
+
# @param others [Array<RbiGenerator::RbiObject>] An array of other {EnumClassNamespace} instances.
|
81
|
+
# @return [Boolean] Whether this instance may be merged with them.
|
82
|
+
def mergeable?(others)
|
83
|
+
others = T.cast(others, T::Array[EnumClassNamespace]) rescue (return false)
|
84
|
+
all = others + [self]
|
85
|
+
|
86
|
+
T.must(super && all.map(&:enums).uniq.length <= 1)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
@@ -16,6 +16,7 @@ module Parlour
|
|
16
16
|
override: T::Boolean,
|
17
17
|
overridable: T::Boolean,
|
18
18
|
class_method: T::Boolean,
|
19
|
+
final: T::Boolean,
|
19
20
|
type_parameters: T.nilable(T::Array[Symbol]),
|
20
21
|
block: T.nilable(T.proc.params(x: Method).void)
|
21
22
|
).void
|
@@ -38,10 +39,11 @@ module Parlour
|
|
38
39
|
# @param overridable [Boolean] Whether this method is overridable by subclasses.
|
39
40
|
# @param class_method [Boolean] Whether this method is a class method; that is, it
|
40
41
|
# it is defined using +self.+.
|
41
|
-
# @param
|
42
|
+
# @param final [Boolean] Whether this method is final.
|
43
|
+
# @param type_parameters [Array<Symbol>, nil] This method's type parameters.
|
42
44
|
# @param block A block which the new instance yields itself to.
|
43
45
|
# @return [void]
|
44
|
-
def initialize(generator, name, parameters, return_type = nil, abstract: false, implementation: false, override: false, overridable: false, class_method: false, type_parameters: nil, &block)
|
46
|
+
def initialize(generator, name, parameters, return_type = nil, abstract: false, implementation: false, override: false, overridable: false, class_method: false, final: false, type_parameters: nil, &block)
|
45
47
|
super(generator, name)
|
46
48
|
@parameters = parameters
|
47
49
|
@return_type = return_type
|
@@ -50,6 +52,7 @@ module Parlour
|
|
50
52
|
@override = override
|
51
53
|
@overridable = overridable
|
52
54
|
@class_method = class_method
|
55
|
+
@final = final
|
53
56
|
@type_parameters = type_parameters || []
|
54
57
|
yield_self(&block) if block
|
55
58
|
end
|
@@ -70,6 +73,7 @@ module Parlour
|
|
70
73
|
override == other.override &&
|
71
74
|
overridable == other.overridable &&
|
72
75
|
class_method == other.class_method &&
|
76
|
+
final == other.final &&
|
73
77
|
type_parameters == other.type_parameters
|
74
78
|
end
|
75
79
|
|
@@ -114,6 +118,11 @@ module Parlour
|
|
114
118
|
# @return [Boolean]
|
115
119
|
attr_reader :class_method
|
116
120
|
|
121
|
+
sig { returns(T::Boolean) }
|
122
|
+
# Whether this method is final.
|
123
|
+
# @return [Boolean]
|
124
|
+
attr_reader :final
|
125
|
+
|
117
126
|
sig { returns(T::Array[Symbol]) }
|
118
127
|
# This method's type parameters.
|
119
128
|
# @return [Array<Symbol>]
|
@@ -132,11 +141,12 @@ module Parlour
|
|
132
141
|
# @return [Array<String>] The RBI lines, formatted as specified.
|
133
142
|
def generate_rbi(indent_level, options)
|
134
143
|
return_call = return_type ? "returns(#{return_type})" : 'void'
|
144
|
+
sig_args = final ? '(:final)' : ''
|
135
145
|
|
136
146
|
sig_params = parameters.map(&:to_sig_param)
|
137
147
|
sig_lines = parameters.length >= options.break_params \
|
138
148
|
? [
|
139
|
-
options.indented(indent_level,
|
149
|
+
options.indented(indent_level, "sig#{sig_args} do"),
|
140
150
|
options.indented(indent_level + 1, "#{qualifiers}params("),
|
141
151
|
] +
|
142
152
|
(
|
@@ -155,7 +165,7 @@ module Parlour
|
|
155
165
|
|
156
166
|
: [options.indented(
|
157
167
|
indent_level,
|
158
|
-
"sig { #{parameters.empty? ? qualifiers[0...-1] : qualifiers}#{
|
168
|
+
"sig#{sig_args} { #{parameters.empty? ? qualifiers[0...-1] : qualifiers}#{
|
159
169
|
parameters.empty? ? '' : "params(#{sig_params.join(', ')})"
|
160
170
|
}#{
|
161
171
|
qualifiers.empty? && parameters.empty? ? '' : '.'
|
@@ -9,6 +9,7 @@ module Parlour
|
|
9
9
|
params(
|
10
10
|
generator: RbiGenerator,
|
11
11
|
name: String,
|
12
|
+
final: T::Boolean,
|
12
13
|
interface: T::Boolean,
|
13
14
|
block: T.nilable(T.proc.params(x: ClassNamespace).void)
|
14
15
|
).void
|
@@ -18,12 +19,13 @@ module Parlour
|
|
18
19
|
#
|
19
20
|
# @param generator [RbiGenerator] The current RbiGenerator.
|
20
21
|
# @param name [String] The name of this module.
|
22
|
+
# @param final [Boolean] Whether this namespace is final.
|
21
23
|
# @param interface [Boolean] A boolean indicating whether this module is an
|
22
24
|
# interface.
|
23
25
|
# @param block A block which the new instance yields itself to.
|
24
26
|
# @return [void]
|
25
|
-
def initialize(generator, name, interface, &block)
|
26
|
-
super(generator, name, &block)
|
27
|
+
def initialize(generator, name, final, interface, &block)
|
28
|
+
super(generator, name, final, &block)
|
27
29
|
@name = name
|
28
30
|
@interface = interface
|
29
31
|
end
|
@@ -26,6 +26,7 @@ module Parlour
|
|
26
26
|
params(
|
27
27
|
generator: RbiGenerator,
|
28
28
|
name: T.nilable(String),
|
29
|
+
final: T::Boolean,
|
29
30
|
block: T.nilable(T.proc.params(x: Namespace).void)
|
30
31
|
).void
|
31
32
|
end
|
@@ -35,15 +36,22 @@ module Parlour
|
|
35
36
|
#
|
36
37
|
# @param generator [RbiGenerator] The current RbiGenerator.
|
37
38
|
# @param name [String, nil] The name of this module.
|
39
|
+
# @param final [Boolean] Whether this namespace is final.
|
38
40
|
# @param block A block which the new instance yields itself to.
|
39
41
|
# @return [void]
|
40
|
-
def initialize(generator, name = nil, &block)
|
42
|
+
def initialize(generator, name = nil, final = false, &block)
|
41
43
|
super(generator, name || '<anonymous namespace>')
|
42
44
|
@children = []
|
43
45
|
@next_comments = []
|
46
|
+
@final = final
|
44
47
|
yield_self(&block) if block
|
45
48
|
end
|
46
49
|
|
50
|
+
sig { returns(T::Boolean) }
|
51
|
+
# Whether this namespace is final.
|
52
|
+
# @return [Boolean]
|
53
|
+
attr_reader :final
|
54
|
+
|
47
55
|
sig { returns(T::Array[RbiObject]) }
|
48
56
|
# The child {RbiObject} instances inside this namespace.
|
49
57
|
# @return [Array<RbiObject>]
|
@@ -131,6 +139,7 @@ module Parlour
|
|
131
139
|
sig do
|
132
140
|
params(
|
133
141
|
name: String,
|
142
|
+
final: T::Boolean,
|
134
143
|
superclass: T.nilable(String),
|
135
144
|
abstract: T::Boolean,
|
136
145
|
block: T.nilable(T.proc.params(x: ClassNamespace).void)
|
@@ -147,13 +156,14 @@ module Parlour
|
|
147
156
|
# namespace.create_class('Bar', superclass: 'Foo') #=> class Bar < Foo
|
148
157
|
#
|
149
158
|
# @param name [String] The name of this class.
|
159
|
+
# @param final [Boolean] Whether this namespace is final.
|
150
160
|
# @param superclass [String, nil] The superclass of this class, or nil if it doesn't
|
151
161
|
# have one.
|
152
162
|
# @param abstract [Boolean] A boolean indicating whether this class is abstract.
|
153
163
|
# @param block A block which the new instance yields itself to.
|
154
164
|
# @return [ClassNamespace]
|
155
|
-
def create_class(name, superclass: nil, abstract: false, &block)
|
156
|
-
new_class = ClassNamespace.new(generator, name, superclass, abstract, &block)
|
165
|
+
def create_class(name, final: false, superclass: nil, abstract: false, &block)
|
166
|
+
new_class = ClassNamespace.new(generator, name, final, superclass, abstract, &block)
|
157
167
|
move_next_comments(new_class)
|
158
168
|
children << new_class
|
159
169
|
new_class
|
@@ -162,6 +172,34 @@ module Parlour
|
|
162
172
|
sig do
|
163
173
|
params(
|
164
174
|
name: String,
|
175
|
+
final: T::Boolean,
|
176
|
+
enums: T.nilable(T::Array[T.any([String, String], String)]),
|
177
|
+
abstract: T::Boolean,
|
178
|
+
block: T.nilable(T.proc.params(x: EnumClassNamespace).void)
|
179
|
+
).returns(EnumClassNamespace)
|
180
|
+
end
|
181
|
+
# Creates a new enum class definition as a child of this namespace.
|
182
|
+
#
|
183
|
+
# @example Create a compass direction enum.
|
184
|
+
# namespace.create_class('Direction', enums: ['North', 'South', 'East', 'West'])
|
185
|
+
#
|
186
|
+
# @param name [String] The name of this class.
|
187
|
+
# @param final [Boolean] Whether this namespace is final.
|
188
|
+
# @param enums [Array<(String, String), String>] The values of the enumeration.
|
189
|
+
# @param abstract [Boolean] A boolean indicating whether this class is abstract.
|
190
|
+
# @param block A block which the new instance yields itself to.
|
191
|
+
# @return [EnumClassNamespace]
|
192
|
+
def create_enum_class(name, final: false, enums: nil, abstract: false, &block)
|
193
|
+
new_enum_class = EnumClassNamespace.new(generator, name, final, enums || [], abstract, &block)
|
194
|
+
move_next_comments(new_enum_class)
|
195
|
+
children << new_enum_class
|
196
|
+
new_enum_class
|
197
|
+
end
|
198
|
+
|
199
|
+
sig do
|
200
|
+
params(
|
201
|
+
name: String,
|
202
|
+
final: T::Boolean,
|
165
203
|
interface: T::Boolean,
|
166
204
|
block: T.nilable(T.proc.params(x: ClassNamespace).void)
|
167
205
|
).returns(ModuleNamespace)
|
@@ -177,12 +215,13 @@ module Parlour
|
|
177
215
|
# end
|
178
216
|
#
|
179
217
|
# @param name [String] The name of this module.
|
218
|
+
# @param final [Boolean] Whether this namespace is final.
|
180
219
|
# @param interface [Boolean] A boolean indicating whether this module is an
|
181
220
|
# interface.
|
182
221
|
# @param block A block which the new instance yields itself to.
|
183
222
|
# @return [ModuleNamespace]
|
184
|
-
def create_module(name, interface: false, &block)
|
185
|
-
new_module = ModuleNamespace.new(generator, name, interface, &block)
|
223
|
+
def create_module(name, final: false, interface: false, &block)
|
224
|
+
new_module = ModuleNamespace.new(generator, name, final, interface, &block)
|
186
225
|
move_next_comments(new_module)
|
187
226
|
children << new_module
|
188
227
|
new_module
|
@@ -199,6 +238,7 @@ module Parlour
|
|
199
238
|
override: T::Boolean,
|
200
239
|
overridable: T::Boolean,
|
201
240
|
class_method: T::Boolean,
|
241
|
+
final: T::Boolean,
|
202
242
|
type_parameters: T.nilable(T::Array[Symbol]),
|
203
243
|
block: T.nilable(T.proc.params(x: Method).void)
|
204
244
|
).returns(Method)
|
@@ -220,10 +260,11 @@ module Parlour
|
|
220
260
|
# @param overridable [Boolean] Whether this method is overridable by subclasses.
|
221
261
|
# @param class_method [Boolean] Whether this method is a class method; that is, it
|
222
262
|
# it is defined using +self.+.
|
223
|
-
# @param
|
263
|
+
# @param final [Boolean] Whether this method is final.
|
264
|
+
# @param type_parameters [Array<Symbol>, nil] This method's type parameters.
|
224
265
|
# @param block A block which the new instance yields itself to.
|
225
266
|
# @return [Method]
|
226
|
-
def create_method(name, parameters: nil, return_type: nil, returns: nil, abstract: false, implementation: false, override: false, overridable: false, class_method: false, type_parameters: nil, &block)
|
267
|
+
def create_method(name, parameters: nil, return_type: nil, returns: nil, abstract: false, implementation: false, override: false, overridable: false, class_method: false, final: false, type_parameters: nil, &block)
|
227
268
|
parameters = parameters || []
|
228
269
|
raise 'cannot specify both return_type: and returns:' if return_type && returns
|
229
270
|
return_type ||= returns
|
@@ -233,10 +274,11 @@ module Parlour
|
|
233
274
|
parameters,
|
234
275
|
return_type,
|
235
276
|
abstract: abstract,
|
236
|
-
implementation: implementation,
|
277
|
+
implementation: implementation,
|
237
278
|
override: override,
|
238
279
|
overridable: overridable,
|
239
280
|
class_method: class_method,
|
281
|
+
final: final,
|
240
282
|
type_parameters: type_parameters,
|
241
283
|
&block
|
242
284
|
)
|
@@ -478,6 +520,20 @@ module Parlour
|
|
478
520
|
new_constant
|
479
521
|
end
|
480
522
|
|
523
|
+
sig { params(name: String, type: String, block: T.nilable(T.proc.params(x: Constant).void)).returns(Constant) }
|
524
|
+
# Adds a new type alias, in the form of a constant, to this namespace.
|
525
|
+
#
|
526
|
+
# @example Add a +MyType+ type alias, to +Integer+, to the class.
|
527
|
+
# class.create_type_alias('MyType', type: 'Integer') #=> MyType = T.type_alias { Integer }
|
528
|
+
#
|
529
|
+
# @param name [String] The name of the type alias.
|
530
|
+
# @param value [String] The type to alias, as a Ruby code string.
|
531
|
+
# @param block A block which the new instance yields itself to.
|
532
|
+
# @return [RbiGenerator::Constant]
|
533
|
+
def create_type_alias(name, type:, &block)
|
534
|
+
create_constant(name, value: "T.type_alias { #{type} }", &block)
|
535
|
+
end
|
536
|
+
|
481
537
|
sig do
|
482
538
|
override.overridable.params(
|
483
539
|
others: T::Array[RbiGenerator::RbiObject]
|
@@ -526,7 +582,7 @@ module Parlour
|
|
526
582
|
private
|
527
583
|
|
528
584
|
sig do
|
529
|
-
params(
|
585
|
+
overridable.params(
|
530
586
|
indent_level: Integer,
|
531
587
|
options: Options
|
532
588
|
).returns(T::Array[String])
|
@@ -540,6 +596,8 @@ module Parlour
|
|
540
596
|
def generate_body(indent_level, options)
|
541
597
|
result = []
|
542
598
|
|
599
|
+
result += [options.indented(indent_level, 'final!'), ''] if final
|
600
|
+
|
543
601
|
if includes.any? || extends.any? || constants.any?
|
544
602
|
result += includes
|
545
603
|
.flat_map { |x| x.generate_rbi(indent_level, options) }
|
data/lib/parlour/version.rb
CHANGED
data/parlour.gemspec
CHANGED
@@ -24,6 +24,7 @@ Gem::Specification.new do |spec|
|
|
24
24
|
|
25
25
|
spec.add_dependency "sorbet-runtime"
|
26
26
|
spec.add_dependency "rainbow", "~> 3.0.0"
|
27
|
+
spec.add_dependency "commander", "~> 4.4.0"
|
27
28
|
|
28
29
|
spec.add_development_dependency "bundler", "~> 2.0"
|
29
30
|
spec.add_development_dependency "rake", "~> 10.0"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: parlour
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aaron Christiansen
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-11-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sorbet-runtime
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: 3.0.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: commander
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 4.4.0
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 4.4.0
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: bundler
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -138,6 +152,7 @@ files:
|
|
138
152
|
- lib/parlour/rbi_generator/attribute.rb
|
139
153
|
- lib/parlour/rbi_generator/class_namespace.rb
|
140
154
|
- lib/parlour/rbi_generator/constant.rb
|
155
|
+
- lib/parlour/rbi_generator/enum_class_namespace.rb
|
141
156
|
- lib/parlour/rbi_generator/extend.rb
|
142
157
|
- lib/parlour/rbi_generator/include.rb
|
143
158
|
- lib/parlour/rbi_generator/method.rb
|