parlour 0.5.2 → 0.6.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 +12 -0
- data/README.md +12 -12
- data/Rakefile +6 -1
- data/lib/parlour/plugin.rb +1 -1
- data/lib/parlour/rbi_generator/attribute.rb +1 -1
- data/lib/parlour/rbi_generator/namespace.rb +28 -28
- data/lib/parlour/rbi_generator/parameter.rb +5 -5
- data/lib/parlour/rbi_generator/rbi_object.rb +2 -2
- data/lib/parlour/version.rb +1 -1
- data/parlour.gemspec +1 -1
- data/plugin_examples/foobar_plugin.rb +3 -3
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d63ab49b1b2dd56c64f1b61dcfea11d04e4b3e4f90f85b17aa61b70de1bb420f
|
4
|
+
data.tar.gz: 0ff645332e076125f9e5ade86b06ad6a1ccc6b40698e29cbfd512f64c90bb5d7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7f3f908f8a601e8d2555a857470a3d6248ee72af46b63f82a8c44690dc669b8bd894bde4a77b260a433177005517aa88e5994fa593511df99ab9180c99d260af
|
7
|
+
data.tar.gz: dee86c23d9f928a0bef5eae82374914b72dc490b278863506f71cc120757e9d882df2f4aaf73feb2cd3fc8f0658a0c0f8534c99e016dd6a1e36a764aaf5a6cbc
|
data/CHANGELOG.md
CHANGED
@@ -3,6 +3,18 @@ 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
|
+
## [0.6.0] - 2019-07-25
|
7
|
+
### Changed
|
8
|
+
- **Breaking change: the `name: ` keyword argument is now positional instead.**
|
9
|
+
Instead of `create_method(name: 'A', returns: 'String')`, use
|
10
|
+
`create_method('A', returns: 'String')`.
|
11
|
+
- Altered some syntax to improve compatibility with previous Ruby versions.
|
12
|
+
(Full compatibility is still WIP.)
|
13
|
+
|
14
|
+
### Fixed
|
15
|
+
- Fixed some Sorbet type signatures.
|
16
|
+
- Fixed an RSpec warning.
|
17
|
+
|
6
18
|
## [0.5.2] - 2019-07-24
|
7
19
|
### Added
|
8
20
|
- Added the `Namespace#create_includes` and `Namespace#create_extends` methods
|
data/README.md
CHANGED
@@ -35,15 +35,15 @@ Here's a quick example of how you can generate an RBI:
|
|
35
35
|
require 'parlour'
|
36
36
|
|
37
37
|
generator = Parlour::RbiGenerator.new
|
38
|
-
generator.root.create_module(
|
39
|
-
a.create_class(
|
40
|
-
foo.create_method(
|
41
|
-
Parlour::RbiGenerator::Parameter.new(
|
42
|
-
Parlour::RbiGenerator::Parameter.new(
|
38
|
+
generator.root.create_module('A') do |a|
|
39
|
+
a.create_class('Foo') do |foo|
|
40
|
+
foo.create_method('add_two_integers', parameters: [
|
41
|
+
Parlour::RbiGenerator::Parameter.new('a', type: 'Integer'),
|
42
|
+
Parlour::RbiGenerator::Parameter.new('b', type: 'Integer')
|
43
43
|
], return_type: 'Integer')
|
44
44
|
end
|
45
45
|
|
46
|
-
a.create_class(
|
46
|
+
a.create_class('Bar', superclass: 'Foo')
|
47
47
|
end
|
48
48
|
|
49
49
|
generator.rbi # => Our RBI as a string
|
@@ -74,15 +74,15 @@ require 'parlour'
|
|
74
74
|
|
75
75
|
class MyPlugin < Parlour::Plugin
|
76
76
|
def generate(root)
|
77
|
-
root.create_module(
|
78
|
-
a.create_class(
|
79
|
-
foo.create_method(
|
80
|
-
Parlour::RbiGenerator::Parameter.new(
|
81
|
-
Parlour::RbiGenerator::Parameter.new(
|
77
|
+
root.create_module('A') do |a|
|
78
|
+
a.create_class('Foo') do |foo|
|
79
|
+
foo.create_method('add_two_integers', parameters: [
|
80
|
+
Parlour::RbiGenerator::Parameter.new('a', type: 'Integer'),
|
81
|
+
Parlour::RbiGenerator::Parameter.new('b', type: 'Integer')
|
82
82
|
], return_type: 'Integer')
|
83
83
|
end
|
84
84
|
|
85
|
-
a.create_class(
|
85
|
+
a.create_class('Bar', superclass: 'Foo')
|
86
86
|
end
|
87
87
|
end
|
88
88
|
end
|
data/Rakefile
CHANGED
data/lib/parlour/plugin.rb
CHANGED
@@ -28,7 +28,7 @@ module Parlour
|
|
28
28
|
registered_plugins[T.must(new_plugin.name)] = new_plugin
|
29
29
|
end
|
30
30
|
|
31
|
-
sig { params(plugins: T::Array[Plugin], generator: RbiGenerator).void }
|
31
|
+
sig { params(plugins: T::Array[Plugin], generator: RbiGenerator, allow_failure: T::Boolean).void }
|
32
32
|
# Runs an array of plugins on a given generator instance.
|
33
33
|
#
|
34
34
|
# @param plugins [Array<Plugin>] An array of {Plugin} instances.
|
@@ -96,9 +96,9 @@ module Parlour
|
|
96
96
|
current_part = self
|
97
97
|
parts_with_types.each do |(name, type)|
|
98
98
|
if type == Class
|
99
|
-
current_part = current_part.create_class(name
|
99
|
+
current_part = current_part.create_class(name)
|
100
100
|
elsif type == Module
|
101
|
-
current_part = current_part.create_module(name
|
101
|
+
current_part = current_part.create_module(name)
|
102
102
|
else
|
103
103
|
raise "unexpected type: path part #{name} is a #{type}"
|
104
104
|
end
|
@@ -112,11 +112,11 @@ module Parlour
|
|
112
112
|
#
|
113
113
|
# @example Creating a module with a comment.
|
114
114
|
# namespace.add_comment_to_next_child('This is a module')
|
115
|
-
# namespace.create_module(
|
115
|
+
# namespace.create_module('M')
|
116
116
|
#
|
117
117
|
# @example Creating a class with a multi-line comment.
|
118
118
|
# namespace.add_comment_to_next_child(['This is a multi-line comment!', 'It can be as long as you want!'])
|
119
|
-
# namespace.create_class(
|
119
|
+
# namespace.create_class('C')
|
120
120
|
#
|
121
121
|
# @param comment [String, Array<String>] The new comment(s).
|
122
122
|
# @return [void]
|
@@ -139,12 +139,12 @@ module Parlour
|
|
139
139
|
# Creates a new class definition as a child of this namespace.
|
140
140
|
#
|
141
141
|
# @example Create a class with a nested module.
|
142
|
-
# namespace.create_class(
|
143
|
-
# foo.create_module(
|
142
|
+
# namespace.create_class('Foo') do |foo|
|
143
|
+
# foo.create_module('Bar')
|
144
144
|
# end
|
145
145
|
#
|
146
146
|
# @example Create a class that is the child of another class.
|
147
|
-
# namespace.create_class(
|
147
|
+
# namespace.create_class('Bar', superclass: 'Foo') #=> class Bar < Foo
|
148
148
|
#
|
149
149
|
# @param name [String] The name of this class.
|
150
150
|
# @param superclass [String, nil] The superclass of this class, or nil if it doesn't
|
@@ -152,7 +152,7 @@ module Parlour
|
|
152
152
|
# @param abstract [Boolean] A boolean indicating whether this class is abstract.
|
153
153
|
# @param block A block which the new instance yields itself to.
|
154
154
|
# @return [ClassNamespace]
|
155
|
-
def create_class(name
|
155
|
+
def create_class(name, superclass: nil, abstract: false, &block)
|
156
156
|
new_class = ClassNamespace.new(generator, name, superclass, abstract, &block)
|
157
157
|
move_next_comments(new_class)
|
158
158
|
children << new_class
|
@@ -169,11 +169,11 @@ module Parlour
|
|
169
169
|
# Creates a new module definition as a child of this namespace.
|
170
170
|
#
|
171
171
|
# @example Create a basic module.
|
172
|
-
# namespace.create_module(
|
172
|
+
# namespace.create_module('Foo')
|
173
173
|
#
|
174
174
|
# @example Create a module with a method.
|
175
|
-
# namespace.create_module(
|
176
|
-
# foo.create_method(
|
175
|
+
# namespace.create_module('Foo') do |foo|
|
176
|
+
# foo.create_method('method_name', parameters: [], return_type: 'Integer')
|
177
177
|
# end
|
178
178
|
#
|
179
179
|
# @param name [String] The name of this module.
|
@@ -181,7 +181,7 @@ module Parlour
|
|
181
181
|
# interface.
|
182
182
|
# @param block A block which the new instance yields itself to.
|
183
183
|
# @return [ModuleNamespace]
|
184
|
-
def create_module(name
|
184
|
+
def create_module(name, interface: false, &block)
|
185
185
|
new_module = ModuleNamespace.new(generator, name, interface, &block)
|
186
186
|
move_next_comments(new_module)
|
187
187
|
children << new_module
|
@@ -221,7 +221,7 @@ module Parlour
|
|
221
221
|
# it is defined using +self.+.
|
222
222
|
# @param block A block which the new instance yields itself to.
|
223
223
|
# @return [Method]
|
224
|
-
def create_method(name
|
224
|
+
def create_method(name, parameters: nil, return_type: nil, returns: nil, abstract: false, implementation: false, override: false, overridable: false, class_method: false, &block)
|
225
225
|
parameters = parameters || []
|
226
226
|
raise 'cannot specify both return_type: and returns:' if return_type && returns
|
227
227
|
return_type ||= returns
|
@@ -266,7 +266,7 @@ module Parlour
|
|
266
266
|
# +"String"+ or +"T.untyped"+.
|
267
267
|
# @param block A block which the new instance yields itself to.
|
268
268
|
# @return [RbiGenerator::Attribute]
|
269
|
-
def create_attribute(name
|
269
|
+
def create_attribute(name, kind:, type:, &block)
|
270
270
|
new_attribute = RbiGenerator::Attribute.new(
|
271
271
|
generator,
|
272
272
|
name,
|
@@ -287,8 +287,8 @@ module Parlour
|
|
287
287
|
# +"String"+ or +"T.untyped"+.
|
288
288
|
# @param block A block which the new instance yields itself to.
|
289
289
|
# @return [RbiGenerator::Attribute]
|
290
|
-
def create_attr_reader(name
|
291
|
-
create_attribute(name
|
290
|
+
def create_attr_reader(name, type:, &block)
|
291
|
+
create_attribute(name, kind: :reader, type: type, &block)
|
292
292
|
end
|
293
293
|
|
294
294
|
# Creates a new write-only attribute (+attr_writer+).
|
@@ -298,8 +298,8 @@ module Parlour
|
|
298
298
|
# +"String"+ or +"T.untyped"+.
|
299
299
|
# @param block A block which the new instance yields itself to.
|
300
300
|
# @return [RbiGenerator::Attribute]
|
301
|
-
def create_attr_writer(name
|
302
|
-
create_attribute(name
|
301
|
+
def create_attr_writer(name, type:, &block)
|
302
|
+
create_attribute(name, kind: :writer, type: type, &block)
|
303
303
|
end
|
304
304
|
|
305
305
|
# Creates a new read and write attribute (+attr_accessor+).
|
@@ -309,8 +309,8 @@ module Parlour
|
|
309
309
|
# +"String"+ or +"T.untyped"+.
|
310
310
|
# @param block A block which the new instance yields itself to.
|
311
311
|
# @return [RbiGenerator::Attribute]
|
312
|
-
def create_attr_accessor(name
|
313
|
-
create_attribute(name
|
312
|
+
def create_attr_accessor(name, type:, &block)
|
313
|
+
create_attribute(name, kind: :accessor, type: type, &block)
|
314
314
|
end
|
315
315
|
|
316
316
|
# Creates a new arbitrary code section.
|
@@ -334,13 +334,13 @@ module Parlour
|
|
334
334
|
# Adds a new +extend+ to this namespace.
|
335
335
|
#
|
336
336
|
# @example Add an +extend+ to a class.
|
337
|
-
# class.create_extend(
|
337
|
+
# class.create_extend('ExtendableClass') #=> extend ExtendableClass
|
338
338
|
#
|
339
339
|
# @param object [String] A code string for what is extended, for example
|
340
340
|
# +"MyModule"+.
|
341
341
|
# @param block A block which the new instance yields itself to.
|
342
342
|
# @return [RbiGenerator::Extend]
|
343
|
-
def create_extend(name
|
343
|
+
def create_extend(name, &block)
|
344
344
|
new_extend = RbiGenerator::Extend.new(
|
345
345
|
generator,
|
346
346
|
name: name,
|
@@ -362,7 +362,7 @@ module Parlour
|
|
362
362
|
def create_extends(extendables)
|
363
363
|
returned_extendables = []
|
364
364
|
extendables.each do |extendable|
|
365
|
-
returned_extendables << create_extend(
|
365
|
+
returned_extendables << create_extend(extendable)
|
366
366
|
end
|
367
367
|
returned_extendables
|
368
368
|
end
|
@@ -371,13 +371,13 @@ module Parlour
|
|
371
371
|
# Adds a new +include+ to this namespace.
|
372
372
|
#
|
373
373
|
# @example Add an +include+ to a class.
|
374
|
-
# class.create_include(
|
374
|
+
# class.create_include('IncludableClass') #=> include IncludableClass
|
375
375
|
#
|
376
376
|
# @param [String] name A code string for what is included, for example
|
377
377
|
# +"Enumerable"+.
|
378
378
|
# @param block A block which the new instance yields itself to.
|
379
379
|
# @return [RbiGenerator::Include]
|
380
|
-
def create_include(name
|
380
|
+
def create_include(name, &block)
|
381
381
|
new_include = RbiGenerator::Include.new(
|
382
382
|
generator,
|
383
383
|
name: name,
|
@@ -399,7 +399,7 @@ module Parlour
|
|
399
399
|
def create_includes(includables)
|
400
400
|
returned_includables = []
|
401
401
|
includables.each do |includable|
|
402
|
-
returned_includables << create_include(
|
402
|
+
returned_includables << create_include(includable)
|
403
403
|
end
|
404
404
|
returned_includables
|
405
405
|
end
|
@@ -408,13 +408,13 @@ module Parlour
|
|
408
408
|
# Adds a new constant definition to this namespace.
|
409
409
|
#
|
410
410
|
# @example Add an +Elem+ constant to the class.
|
411
|
-
# class.create_constant(
|
411
|
+
# class.create_constant('Elem', value: 'String') #=> Elem = String
|
412
412
|
#
|
413
413
|
# @param name [String] The name of the constant.
|
414
414
|
# @param value [String] The value of the constant, as a Ruby code string.
|
415
415
|
# @param block A block which the new instance yields itself to.
|
416
416
|
# @return [RbiGenerator::Constant]
|
417
|
-
def create_constant(name
|
417
|
+
def create_constant(name, value:, &block)
|
418
418
|
new_constant = RbiGenerator::Constant.new(
|
419
419
|
generator,
|
420
420
|
name: name,
|
@@ -15,13 +15,13 @@ module Parlour
|
|
15
15
|
# Create a new method parameter.
|
16
16
|
#
|
17
17
|
# @example Create a simple Integer parameter named +num+.
|
18
|
-
# Parlour::RbiGenerator::Parameter.new(
|
18
|
+
# Parlour::RbiGenerator::Parameter.new('num', type: 'Integer')
|
19
19
|
# @example Create a nilable array parameter.
|
20
|
-
# Parlour::RbiGenerator::Parameter.new(
|
20
|
+
# Parlour::RbiGenerator::Parameter.new('array_of_strings_or_symbols', type: 'T.nilable(T::Array(String, Symbol))')
|
21
21
|
# @example Create a block parameter.
|
22
|
-
# Parlour::RbiGenerator::Parameter.new(
|
22
|
+
# Parlour::RbiGenerator::Parameter.new('&blk', type: 'T.proc.void')
|
23
23
|
# @example Create a parameter with a default value.
|
24
|
-
# Parlour::RbiGenerator::Parameter.new(
|
24
|
+
# Parlour::RbiGenerator::Parameter.new('name', type: 'String', default: 'Parlour')
|
25
25
|
#
|
26
26
|
# @param name [String] The name of this parameter. This may start with +*+, +**+,
|
27
27
|
# or +&+, or end with +:+, which will infer the {kind} of this
|
@@ -33,7 +33,7 @@ module Parlour
|
|
33
33
|
# as +"\"\""+ (or +'""'+). The default value of the decimal +3.14+
|
34
34
|
# would be +"3.14"+.
|
35
35
|
# @return [void]
|
36
|
-
def initialize(name
|
36
|
+
def initialize(name, type: nil, default: nil)
|
37
37
|
name = T.must(name)
|
38
38
|
@name = name
|
39
39
|
|
@@ -52,12 +52,12 @@ module Parlour
|
|
52
52
|
# the definition for this object, not in the definition's body.
|
53
53
|
#
|
54
54
|
# @example Creating a module with a comment.
|
55
|
-
# namespace.create_module(
|
55
|
+
# namespace.create_module('M') do |m|
|
56
56
|
# m.add_comment('This is a module')
|
57
57
|
# end
|
58
58
|
#
|
59
59
|
# @example Creating a class with a multi-line comment.
|
60
|
-
# namespace.create_class(
|
60
|
+
# namespace.create_class('C') do |c|
|
61
61
|
# c.add_comment(['This is a multi-line comment!', 'It can be as long as you want!'])
|
62
62
|
# end
|
63
63
|
#
|
data/lib/parlour/version.rb
CHANGED
data/parlour.gemspec
CHANGED
@@ -28,6 +28,6 @@ Gem::Specification.new do |spec|
|
|
28
28
|
spec.add_development_dependency "bundler", "~> 2.0"
|
29
29
|
spec.add_development_dependency "rake", "~> 10.0"
|
30
30
|
spec.add_development_dependency "rspec", "~> 3.0"
|
31
|
-
spec.add_development_dependency "sorbet"
|
31
|
+
spec.add_development_dependency "sorbet", "= 0.4.4254"
|
32
32
|
spec.add_development_dependency "simplecov"
|
33
33
|
end
|
@@ -3,10 +3,10 @@ require 'parlour'
|
|
3
3
|
module FooBar
|
4
4
|
class Plugin < Parlour::Plugin
|
5
5
|
def generate(root)
|
6
|
-
root.create_module(
|
6
|
+
root.create_module('Foo') do |foo|
|
7
7
|
foo.add_comment('This is an example plugin!')
|
8
|
-
foo.create_module(
|
9
|
-
foo.create_module(
|
8
|
+
foo.create_module('Bar')
|
9
|
+
foo.create_module('Bar', interface: true)
|
10
10
|
end
|
11
11
|
end
|
12
12
|
end
|
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: 0.6.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-07-
|
11
|
+
date: 2019-07-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sorbet-runtime
|
@@ -84,16 +84,16 @@ dependencies:
|
|
84
84
|
name: sorbet
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
|
-
- -
|
87
|
+
- - '='
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version:
|
89
|
+
version: 0.4.4254
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
|
-
- -
|
94
|
+
- - '='
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version:
|
96
|
+
version: 0.4.4254
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: simplecov
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|