parlour 0.2.2 → 0.3.0

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: 8fab83bcce7bff17a6f4ded59f19e36b35f61b96c0e4c8e1ef50e5f0856e79fb
4
- data.tar.gz: 1173903dcff90d2fe2579dbb0e79d361707f6d33041c6c36295f09f43219c630
3
+ metadata.gz: ded8584a233720f5a345d5bad9b91c344fc12f1dc38b0fbad1b3e0e797178cb9
4
+ data.tar.gz: c23b9bc0207031d207202d95e259521fa4b5826b739094c2f10cab5223392f9b
5
5
  SHA512:
6
- metadata.gz: 0d3a8e0ac15d49a7cac530bc74c31070532a3960ff7cdaac1d70ab2bb28eeba8e6664125bc1bb52b9c676dcd934c0b31c24c97da02bfb1f65ef411dc480b28a9
7
- data.tar.gz: 64d2b979abc0ded7506f1dd176269be3c84f39d972d038bedd3c2d0d34262b464dad0de1daf8591543444cdf0f403a9dc5bc648704429a1b3e61acd45a8dc54f
6
+ metadata.gz: 2f470194db52dd83dbb27df91f3f9044f921946471a800f7d2d42e7f6230496b326585847812c35d77a7cea1eb1a2f874dc1397b9fc4b96bd53f8c2b13d31b4a
7
+ data.tar.gz: 270d77587338e413141952ce06710774e468a91f7ec636cf2636f2856a1bae4a3e9d4852a643aad602f57d0cb30cac88b080b0c46b22395e1905e69a0c56d28c
@@ -3,6 +3,11 @@ 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.3.0] - 2019-07-09
7
+ ### Changed
8
+ - Breaking change: all `Namespace#create_` methods, and the `Parameter` constructor, now take entirely keyword arguments.
9
+ For example, `create_method('A', [], 'String')` is now written as `create_method(name: 'A', returns: 'String')`.
10
+
6
11
  ## [0.2.2] - 2019-07-08
7
12
  ### Fixed
8
13
  - Fixed a bug which occasionally caused includes and extends to generate incorrectly.
data/README.md CHANGED
@@ -25,15 +25,15 @@ API is very likely to change:
25
25
  require 'parlour'
26
26
 
27
27
  generator = Parlour::RbiGenerator.new
28
- generator.root.create_module('A') do |a|
29
- a.create_class('Foo') do |foo|
30
- foo.create_method('add_two_integers', [
31
- Parlour::RbiGenerator::Parameter.new('a', type: 'Integer'),
32
- Parlour::RbiGenerator::Parameter.new('b', type: 'Integer')
33
- ], 'Integer')
28
+ generator.root.create_module(name: 'A') do |a|
29
+ a.create_class(name: 'Foo') do |foo|
30
+ foo.create_method(name: 'add_two_integers', parameters: [
31
+ Parlour::RbiGenerator::Parameter.new(name: 'a', type: 'Integer'),
32
+ Parlour::RbiGenerator::Parameter.new(name: 'b', type: 'Integer')
33
+ ], return_type: 'Integer')
34
34
  end
35
35
 
36
- a.create_class('Bar', superclass: 'Foo')
36
+ a.create_class(name: 'Bar', superclass: 'Foo')
37
37
  end
38
38
 
39
39
  generator.rbi # => Our RBI as a string
@@ -64,15 +64,15 @@ require 'parlour'
64
64
 
65
65
  class MyPlugin < Parlour::Plugin
66
66
  def generate(root)
67
- root.create_module('A') do |a|
68
- a.create_class('Foo') do |foo|
69
- foo.create_method('add_two_integers', [
70
- Parlour::RbiGenerator::Parameter.new('a', type: 'Integer'),
71
- Parlour::RbiGenerator::Parameter.new('b', type: 'Integer')
72
- ], 'Integer')
67
+ root.create_module(name: 'A') do |a|
68
+ a.create_class(name: 'Foo') do |foo|
69
+ foo.create_method(name: 'add_two_integers', parameters: [
70
+ Parlour::RbiGenerator::Parameter.new(name: 'a', type: 'Integer'),
71
+ Parlour::RbiGenerator::Parameter.new(name: 'b', type: 'Integer')
72
+ ], return_type: 'Integer')
73
73
  end
74
74
 
75
- a.create_class('Bar', superclass: 'Foo')
75
+ a.create_class(name: 'Bar', superclass: 'Foo')
76
76
  end
77
77
  end
78
78
  end
@@ -35,7 +35,7 @@ module Parlour
35
35
  super(generator, name, [], type, &block)
36
36
  when :writer
37
37
  super(generator, name, [
38
- Parameter.new(name, type: type)
38
+ Parameter.new(name: name, type: type)
39
39
  ], type, &block)
40
40
  else
41
41
  raise 'unknown kind'
@@ -75,11 +75,11 @@ module Parlour
75
75
  #
76
76
  # @example Creating a module with a comment.
77
77
  # namespace.add_comment_to_next_child('This is a module')
78
- # namespace.create_module('M')
78
+ # namespace.create_module(name: 'M')
79
79
  #
80
80
  # @example Creating a class with a multi-line comment.
81
81
  # namespace.add_comment_to_next_child(['This is a multi-line comment!', 'It can be as long as you want!'])
82
- # namespace.create_class('C')
82
+ # namespace.create_class(name: 'C')
83
83
  #
84
84
  # @param comment [String, Array<String>] The new comment(s).
85
85
  # @return [void]
@@ -93,7 +93,7 @@ module Parlour
93
93
 
94
94
  sig do
95
95
  params(
96
- name: String,
96
+ name: T.nilable(String),
97
97
  superclass: T.nilable(String),
98
98
  abstract: T::Boolean,
99
99
  block: T.nilable(T.proc.params(x: ClassNamespace).void)
@@ -102,12 +102,12 @@ module Parlour
102
102
  # Creates a new class definition as a child of this namespace.
103
103
  #
104
104
  # @example Create a class with a nested module.
105
- # namespace.create_class('Foo') do |foo|
106
- # foo.create_module('Bar')
105
+ # namespace.create_class(name: 'Foo') do |foo|
106
+ # foo.create_module(name: 'Bar')
107
107
  # end
108
108
  #
109
109
  # @example Create a class that is the child of another class.
110
- # namespace.create_class('Bar', superclass: 'Foo') #=> class Bar < Foo
110
+ # namespace.create_class(name: 'Bar', superclass: 'Foo') #=> class Bar < Foo
111
111
  #
112
112
  # @param name [String] The name of this class.
113
113
  # @param superclass [String, nil] The superclass of this class, or nil if it doesn't
@@ -115,7 +115,8 @@ module Parlour
115
115
  # @param abstract [Boolean] A boolean indicating whether this class is abstract.
116
116
  # @param block A block which the new instance yields itself to.
117
117
  # @return [ClassNamespace]
118
- def create_class(name, superclass: nil, abstract: false, &block)
118
+ def create_class(name: nil, superclass: nil, abstract: false, &block)
119
+ name = T.must(name)
119
120
  new_class = ClassNamespace.new(generator, name, superclass, abstract, &block)
120
121
  move_next_comments(new_class)
121
122
  children << new_class
@@ -124,7 +125,7 @@ module Parlour
124
125
 
125
126
  sig do
126
127
  params(
127
- name: String,
128
+ name: T.nilable(String),
128
129
  interface: T::Boolean,
129
130
  block: T.nilable(T.proc.params(x: ClassNamespace).void)
130
131
  ).returns(ModuleNamespace)
@@ -132,11 +133,11 @@ module Parlour
132
133
  # Creates a new module definition as a child of this namespace.
133
134
  #
134
135
  # @example Create a basic module.
135
- # namespace.create_module('Foo')
136
+ # namespace.create_module(name: 'Foo')
136
137
  #
137
138
  # @example Create a module with a method.
138
- # namespace.create_module('Foo') do |foo|
139
- # foo.create_method('method_name', [], 'Integer')
139
+ # namespace.create_module(name: 'Foo') do |foo|
140
+ # foo.create_method(name: 'method_name', parameters: [], return_type: 'Integer')
140
141
  # end
141
142
  #
142
143
  # @param name [String] The name of this module.
@@ -144,7 +145,8 @@ module Parlour
144
145
  # interface.
145
146
  # @param block A block which the new instance yields itself to.
146
147
  # @return [ModuleNamespace]
147
- def create_module(name, interface: false, &block)
148
+ def create_module(name: nil, interface: false, &block)
149
+ name = T.must(name)
148
150
  new_module = ModuleNamespace.new(generator, name, interface, &block)
149
151
  move_next_comments(new_module)
150
152
  children << new_module
@@ -153,9 +155,10 @@ module Parlour
153
155
 
154
156
  sig do
155
157
  params(
156
- name: String,
157
- parameters: T::Array[Parameter],
158
+ name: T.nilable(String),
159
+ parameters: T.nilable(T::Array[Parameter]),
158
160
  return_type: T.nilable(String),
161
+ returns: T.nilable(String),
159
162
  abstract: T::Boolean,
160
163
  implementation: T::Boolean,
161
164
  override: T::Boolean,
@@ -172,6 +175,7 @@ module Parlour
172
175
  # method's parameters.
173
176
  # @param return_type [String, nil] A Sorbet string of what this method returns, such as
174
177
  # +"String"+ or +"T.untyped"+. Passing nil denotes a void return.
178
+ # @param returns [String, nil] Same as return_type.
175
179
  # @param abstract [Boolean] Whether this method is abstract.
176
180
  # @param implementation [Boolean] Whether this method is an implementation of a
177
181
  # parent abstract method.
@@ -182,7 +186,11 @@ module Parlour
182
186
  # it is defined using +self.+.
183
187
  # @param block A block which the new instance yields itself to.
184
188
  # @return [Method]
185
- def create_method(name, parameters, return_type = nil, abstract: false, implementation: false, override: false, overridable: false, class_method: false, &block)
189
+ def create_method(name: nil, parameters: nil, return_type: nil, returns: nil, abstract: false, implementation: false, override: false, overridable: false, class_method: false, &block)
190
+ name = T.must(name)
191
+ parameters = parameters || []
192
+ raise 'cannot specify both return_type: and returns:' if return_type && returns
193
+ return_type ||= returns
186
194
  new_method = RbiGenerator::Method.new(
187
195
  generator,
188
196
  name,
@@ -224,7 +232,10 @@ module Parlour
224
232
  # +"String"+ or +"T.untyped"+.
225
233
  # @param block A block which the new instance yields itself to.
226
234
  # @return [RbiGenerator::Attribute]
227
- def create_attribute(name, kind, type, &block)
235
+ def create_attribute(name: nil, kind: nil, type: nil, &block)
236
+ name = T.must(name)
237
+ kind = T.must(kind)
238
+ type = T.must(type)
228
239
  new_attribute = RbiGenerator::Attribute.new(
229
240
  generator,
230
241
  name,
@@ -245,8 +256,8 @@ module Parlour
245
256
  # +"String"+ or +"T.untyped"+.
246
257
  # @param block A block which the new instance yields itself to.
247
258
  # @return [RbiGenerator::Attribute]
248
- def create_attr_reader(name, type, &block)
249
- create_attribute(name, :reader, type, &block)
259
+ def create_attr_reader(name: nil, type: nil, &block)
260
+ create_attribute(name: name, kind: :reader, type: type, &block)
250
261
  end
251
262
 
252
263
  # Creates a new write-only attribute (+attr_writer+).
@@ -256,8 +267,8 @@ module Parlour
256
267
  # +"String"+ or +"T.untyped"+.
257
268
  # @param block A block which the new instance yields itself to.
258
269
  # @return [RbiGenerator::Attribute]
259
- def create_attr_writer(name, type, &block)
260
- create_attribute(name, :writer, type, &block)
270
+ def create_attr_writer(name: nil, type: nil, &block)
271
+ create_attribute(name: name, kind: :writer, type: type, &block)
261
272
  end
262
273
 
263
274
  # Creates a new read and write attribute (+attr_accessor+).
@@ -267,8 +278,8 @@ module Parlour
267
278
  # +"String"+ or +"T.untyped"+.
268
279
  # @param block A block which the new instance yields itself to.
269
280
  # @return [RbiGenerator::Attribute]
270
- def create_attr_accessor(name, type, &block)
271
- create_attribute(name, :accessor, type, &block)
281
+ def create_attr_accessor(name: nil, type: nil, &block)
282
+ create_attribute(name: name, kind: :accessor, type: type, &block)
272
283
  end
273
284
 
274
285
  sig { params(name: String).void }
@@ -7,7 +7,7 @@ module Parlour
7
7
 
8
8
  sig do
9
9
  params(
10
- name: String,
10
+ name: T.nilable(String),
11
11
  type: T.nilable(String),
12
12
  default: T.nilable(String)
13
13
  ).void
@@ -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('num', type: 'Integer')
18
+ # Parlour::RbiGenerator::Parameter.new(name: 'num', type: 'Integer')
19
19
  # @example Create a nilable array parameter.
20
- # Parlour::RbiGenerator::Parameter.new('array_of_strings_or_symbols', type: 'T.nilable(T::Array(String, Symbol))')
20
+ # Parlour::RbiGenerator::Parameter.new(name: 'array_of_strings_or_symbols', type: 'T.nilable(T::Array(String, Symbol))')
21
21
  # @example Create a block parameter.
22
- # Parlour::RbiGenerator::Parameter.new('&blk', type: 'T.proc.void')
22
+ # Parlour::RbiGenerator::Parameter.new(name: '&blk', type: 'T.proc.void')
23
23
  # @example Create a parameter with a default value.
24
- # Parlour::RbiGenerator::Parameter.new('name', type: 'String', default: 'Parlour')
24
+ # Parlour::RbiGenerator::Parameter.new(name: '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,8 @@ 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, type: nil, default: nil)
36
+ def initialize(name: nil, type: nil, default: nil)
37
+ name = T.must(name)
37
38
  @name = name
38
39
 
39
40
  prefix = /^(\*\*|\*|\&)?/.match(name)&.captures&.first || ''
@@ -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('M') do |m|
55
+ # namespace.create_module(name: '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('C') do |c|
60
+ # namespace.create_class(name: '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
  #
@@ -1,5 +1,5 @@
1
1
  # typed: strong
2
2
  module Parlour
3
3
  # The library version.
4
- VERSION = '0.2.2'
4
+ VERSION = '0.3.0'
5
5
  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('Foo') do |foo|
6
+ root.create_module(name: 'Foo') do |foo|
7
7
  foo.add_comment('This is an example plugin!')
8
- foo.create_module('Bar')
9
- foo.create_module('Bar', interface: true)
8
+ foo.create_module(name: 'Bar')
9
+ foo.create_module(name: '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.2.2
4
+ version: 0.3.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-08 00:00:00.000000000 Z
11
+ date: 2019-07-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sorbet-runtime