rbs 0.18.0 → 1.0.0.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +31 -0
  3. data/Rakefile +4 -0
  4. data/core/builtin.rbs +4 -0
  5. data/core/file.rbs +0 -4
  6. data/core/hash.rbs +1 -3
  7. data/core/io.rbs +159 -6
  8. data/core/kernel.rbs +1 -1
  9. data/core/time.rbs +0 -12
  10. data/goodcheck.yml +20 -0
  11. data/lib/rbs.rb +2 -0
  12. data/lib/rbs/ast/declarations.rb +7 -2
  13. data/lib/rbs/ast/members.rb +10 -4
  14. data/lib/rbs/cli.rb +10 -10
  15. data/lib/rbs/definition.rb +70 -3
  16. data/lib/rbs/definition_builder.rb +544 -989
  17. data/lib/rbs/definition_builder/ancestor_builder.rb +476 -0
  18. data/lib/rbs/definition_builder/method_builder.rb +217 -0
  19. data/lib/rbs/environment.rb +5 -1
  20. data/lib/rbs/environment_loader.rb +1 -1
  21. data/lib/rbs/environment_walker.rb +16 -10
  22. data/lib/rbs/errors.rb +71 -66
  23. data/lib/rbs/method_type.rb +1 -31
  24. data/lib/rbs/parser.rb +1000 -894
  25. data/lib/rbs/parser.y +108 -57
  26. data/lib/rbs/prototype/rb.rb +14 -3
  27. data/lib/rbs/prototype/rbi.rb +6 -6
  28. data/lib/rbs/prototype/runtime.rb +53 -33
  29. data/lib/rbs/substitution.rb +4 -0
  30. data/lib/rbs/test.rb +3 -1
  31. data/lib/rbs/test/hook.rb +24 -7
  32. data/lib/rbs/types.rb +63 -6
  33. data/lib/rbs/validator.rb +4 -2
  34. data/lib/rbs/variance_calculator.rb +5 -1
  35. data/lib/rbs/version.rb +1 -1
  36. data/lib/rbs/writer.rb +9 -1
  37. data/schema/members.json +5 -1
  38. data/sig/definition.rbs +6 -1
  39. data/sig/definition_builder.rbs +3 -0
  40. data/sig/errors.rbs +20 -0
  41. data/sig/members.rbs +4 -1
  42. data/sig/method_types.rbs +3 -16
  43. data/sig/type_name_resolver.rbs +4 -2
  44. data/sig/types.rbs +17 -1
  45. data/sig/validator.rbs +12 -0
  46. data/stdlib/dbm/0/dbm.rbs +0 -2
  47. data/stdlib/logger/0/log_device.rbs +1 -2
  48. data/stdlib/monitor/0/monitor.rbs +119 -0
  49. data/stdlib/time/0/time.rbs +327 -0
  50. data/stdlib/tsort/0/tsort.rbs +8 -0
  51. data/stdlib/uri/0/common.rbs +401 -0
  52. data/stdlib/uri/0/rfc2396_parser.rbs +9 -0
  53. data/stdlib/uri/0/rfc3986_parser.rbs +2 -0
  54. data/steep/Gemfile.lock +13 -14
  55. metadata +14 -5
@@ -138,8 +138,6 @@ class DBM
138
138
  #
139
139
  def include?: (String) -> bool
140
140
 
141
- def index: (untyped) -> (String | NilClass)
142
-
143
141
  # Returns a Hash (not a DBM database) created by using each value in the
144
142
  # database as a key, with the corresponding key as its value.
145
143
  #
@@ -1,7 +1,6 @@
1
1
  class Logger
2
2
  class LogDevice
3
- # TODO: Write type signature for MonitorMixin
4
- # include MonitorMixin
3
+ include MonitorMixin
5
4
 
6
5
  include Period
7
6
 
@@ -0,0 +1,119 @@
1
+ # Use the Monitor class when you want to have a lock object for blocks with
2
+ # mutual exclusion.
3
+ #
4
+ # require 'monitor'
5
+ #
6
+ # lock = Monitor.new
7
+ # lock.synchronize do
8
+ # # exclusive access
9
+ # end
10
+ class Monitor
11
+ public
12
+
13
+ def enter: () -> nil
14
+
15
+ def exit: () -> nil
16
+
17
+ def mon_check_owner: () -> nil
18
+
19
+ alias mon_enter enter
20
+
21
+ alias mon_exit exit
22
+
23
+ def mon_locked?: () -> bool
24
+
25
+ def mon_owned?: () -> bool
26
+
27
+ alias mon_synchronize synchronize
28
+
29
+ alias mon_try_enter try_enter
30
+
31
+ def new_cond: () -> ::MonitorMixin::ConditionVariable
32
+
33
+ def synchronize: [T] () { () -> T } -> T
34
+
35
+ def try_enter: () -> bool
36
+
37
+ # for compatibility
38
+ alias try_mon_enter try_enter
39
+
40
+ def wait_for_cond: (::MonitorMixin::ConditionVariable, Numeric? timeout) -> untyped
41
+ end
42
+
43
+ module MonitorMixin
44
+ def self.extend_object: (untyped obj) -> untyped
45
+
46
+ public
47
+
48
+ # Enters exclusive section.
49
+ def mon_enter: () -> nil
50
+
51
+ # Leaves exclusive section.
52
+ def mon_exit: () -> nil
53
+
54
+ # Returns true if this monitor is locked by any thread
55
+ def mon_locked?: () -> bool
56
+
57
+ # Returns true if this monitor is locked by current thread.
58
+ def mon_owned?: () -> bool
59
+
60
+ # Enters exclusive section and executes the block. Leaves the exclusive section
61
+ # automatically when the block exits. See example under `MonitorMixin`.
62
+ def mon_synchronize: [T] () { () -> T } -> T
63
+
64
+ # Attempts to enter exclusive section. Returns `false` if lock fails.
65
+ def mon_try_enter: () -> bool
66
+
67
+ # Creates a new MonitorMixin::ConditionVariable associated with the Monitor
68
+ # object.
69
+ def new_cond: () -> ::MonitorMixin::ConditionVariable
70
+
71
+ alias synchronize mon_synchronize
72
+
73
+ # For backward compatibility
74
+ alias try_mon_enter mon_try_enter
75
+
76
+ private
77
+
78
+ # Use `extend MonitorMixin` or `include MonitorMixin` instead of this
79
+ # constructor. Have look at the examples above to understand how to use this
80
+ # module.
81
+ def initialize: (*untyped) { (*untyped) -> untyped } -> void
82
+
83
+ def mon_check_owner: () -> nil
84
+
85
+ # Initializes the MonitorMixin after being included in a class or when an object
86
+ # has been extended with the MonitorMixin
87
+ def mon_initialize: () -> untyped
88
+ end
89
+
90
+ # FIXME: This isn't documented in Nutshell.
91
+ #
92
+ # Since MonitorMixin.new_cond returns a ConditionVariable, and the example above
93
+ # calls while_wait and signal, this class should be documented.
94
+ class MonitorMixin::ConditionVariable
95
+ public
96
+
97
+ # Wakes up all threads waiting for this lock.
98
+ def broadcast: () -> Thread::ConditionVariable
99
+
100
+ # Wakes up the first thread in line waiting for this lock.
101
+ def signal: () -> Thread::ConditionVariable
102
+
103
+ # Releases the lock held in the associated monitor and waits; reacquires the
104
+ # lock on wakeup.
105
+ #
106
+ # If `timeout` is given, this method returns after `timeout` seconds passed,
107
+ # even if no other thread doesn't signal.
108
+ def wait: (?Numeric? timeout) -> untyped
109
+
110
+ # Calls wait repeatedly until the given block yields a truthy value.
111
+ def wait_until: () { () -> boolish } -> untyped
112
+
113
+ # Calls wait repeatedly while the given block yields a truthy value.
114
+ def wait_while: () { () -> boolish } -> untyped
115
+
116
+ private
117
+
118
+ def initialize: (Monitor monitor) -> void
119
+ end
@@ -0,0 +1,327 @@
1
+ class Time
2
+ interface _TimeLike
3
+ def year: () -> Integer
4
+ def mon: () -> Integer
5
+ def day: () -> Integer
6
+ end
7
+
8
+ #
9
+ # Return the number of seconds the specified time zone differs
10
+ # from UTC.
11
+ #
12
+ # Numeric time zones that include minutes, such as
13
+ # <code>-10:00</code> or <code>+1330</code> will work, as will
14
+ # simpler hour-only time zones like <code>-10</code> or
15
+ # <code>+13</code>.
16
+ #
17
+ # Textual time zones listed in ZoneOffset are also supported.
18
+ #
19
+ # If the time zone does not match any of the above, +zone_offset+
20
+ # will check if the local time zone (both with and without
21
+ # potential Daylight Saving \Time changes being in effect) matches
22
+ # +zone+. Specifying a value for +year+ will change the year used
23
+ # to find the local time zone.
24
+ #
25
+ # If +zone_offset+ is unable to determine the offset, nil will be
26
+ # returned.
27
+ #
28
+ # require 'time'
29
+ #
30
+ # Time.zone_offset("EST") #=> -18000
31
+ #
32
+ # You must require 'time' to use this method.
33
+ #
34
+ def self.zone_offset: (String zone, ?Integer year) -> Integer
35
+
36
+ #
37
+ # Takes a string representation of a Time and attempts to parse it
38
+ # using a heuristic.
39
+ #
40
+ # require 'time'
41
+ #
42
+ # Time.parse("2010-10-31") #=> 2010-10-31 00:00:00 -0500
43
+ #
44
+ # Any missing pieces of the date are inferred based on the current date.
45
+ #
46
+ # require 'time'
47
+ #
48
+ # # assuming the current date is "2011-10-31"
49
+ # Time.parse("12:00") #=> 2011-10-31 12:00:00 -0500
50
+ #
51
+ # We can change the date used to infer our missing elements by passing a second
52
+ # object that responds to #mon, #day and #year, such as Date, Time or DateTime.
53
+ # We can also use our own object.
54
+ #
55
+ # require 'time'
56
+ #
57
+ # class MyDate
58
+ # attr_reader :mon, :day, :year
59
+ #
60
+ # def initialize(mon, day, year)
61
+ # @mon, @day, @year = mon, day, year
62
+ # end
63
+ # end
64
+ #
65
+ # d = Date.parse("2010-10-28")
66
+ # t = Time.parse("2010-10-29")
67
+ # dt = DateTime.parse("2010-10-30")
68
+ # md = MyDate.new(10,31,2010)
69
+ #
70
+ # Time.parse("12:00", d) #=> 2010-10-28 12:00:00 -0500
71
+ # Time.parse("12:00", t) #=> 2010-10-29 12:00:00 -0500
72
+ # Time.parse("12:00", dt) #=> 2010-10-30 12:00:00 -0500
73
+ # Time.parse("12:00", md) #=> 2010-10-31 12:00:00 -0500
74
+ #
75
+ # If a block is given, the year described in +date+ is converted
76
+ # by the block. This is specifically designed for handling two
77
+ # digit years. For example, if you wanted to treat all two digit
78
+ # years prior to 70 as the year 2000+ you could write this:
79
+ #
80
+ # require 'time'
81
+ #
82
+ # Time.parse("01-10-31") {|year| year + (year < 70 ? 2000 : 1900)}
83
+ # #=> 2001-10-31 00:00:00 -0500
84
+ # Time.parse("70-10-31") {|year| year + (year < 70 ? 2000 : 1900)}
85
+ # #=> 1970-10-31 00:00:00 -0500
86
+ #
87
+ # If the upper components of the given time are broken or missing, they are
88
+ # supplied with those of +now+. For the lower components, the minimum
89
+ # values (1 or 0) are assumed if broken or missing. For example:
90
+ #
91
+ # require 'time'
92
+ #
93
+ # # Suppose it is "Thu Nov 29 14:33:20 2001" now and
94
+ # # your time zone is EST which is GMT-5.
95
+ # now = Time.parse("Thu Nov 29 14:33:20 2001")
96
+ # Time.parse("16:30", now) #=> 2001-11-29 16:30:00 -0500
97
+ # Time.parse("7/23", now) #=> 2001-07-23 00:00:00 -0500
98
+ # Time.parse("Aug 31", now) #=> 2001-08-31 00:00:00 -0500
99
+ # Time.parse("Aug 2000", now) #=> 2000-08-01 00:00:00 -0500
100
+ #
101
+ # Since there are numerous conflicts among locally defined time zone
102
+ # abbreviations all over the world, this method is not intended to
103
+ # understand all of them. For example, the abbreviation "CST" is
104
+ # used variously as:
105
+ #
106
+ # -06:00 in America/Chicago,
107
+ # -05:00 in America/Havana,
108
+ # +08:00 in Asia/Harbin,
109
+ # +09:30 in Australia/Darwin,
110
+ # +10:30 in Australia/Adelaide,
111
+ # etc.
112
+ #
113
+ # Based on this fact, this method only understands the time zone
114
+ # abbreviations described in RFC 822 and the system time zone, in the
115
+ # order named. (i.e. a definition in RFC 822 overrides the system
116
+ # time zone definition.) The system time zone is taken from
117
+ # <tt>Time.local(year, 1, 1).zone</tt> and
118
+ # <tt>Time.local(year, 7, 1).zone</tt>.
119
+ # If the extracted time zone abbreviation does not match any of them,
120
+ # it is ignored and the given time is regarded as a local time.
121
+ #
122
+ # ArgumentError is raised if Date._parse cannot extract information from
123
+ # +date+ or if the Time class cannot represent specified date.
124
+ #
125
+ # This method can be used as a fail-safe for other parsing methods as:
126
+ #
127
+ # Time.rfc2822(date) rescue Time.parse(date)
128
+ # Time.httpdate(date) rescue Time.parse(date)
129
+ # Time.xmlschema(date) rescue Time.parse(date)
130
+ #
131
+ # A failure of Time.parse should be checked, though.
132
+ #
133
+ # You must require 'time' to use this method.
134
+ #
135
+ def self.parse: (String date, ?_TimeLike now) ?{ (Integer) -> Integer } -> Time
136
+
137
+ #
138
+ # Works similar to +parse+ except that instead of using a
139
+ # heuristic to detect the format of the input string, you provide
140
+ # a second argument that describes the format of the string.
141
+ #
142
+ # If a block is given, the year described in +date+ is converted by the
143
+ # block. For example:
144
+ #
145
+ # Time.strptime(...) {|y| y < 100 ? (y >= 69 ? y + 1900 : y + 2000) : y}
146
+ #
147
+ # Below is a list of the formatting options:
148
+ #
149
+ # %a :: The abbreviated weekday name ("Sun")
150
+ # %A :: The full weekday name ("Sunday")
151
+ # %b :: The abbreviated month name ("Jan")
152
+ # %B :: The full month name ("January")
153
+ # %c :: The preferred local date and time representation
154
+ # %C :: Century (20 in 2009)
155
+ # %d :: Day of the month (01..31)
156
+ # %D :: Date (%m/%d/%y)
157
+ # %e :: Day of the month, blank-padded ( 1..31)
158
+ # %F :: Equivalent to %Y-%m-%d (the ISO 8601 date format)
159
+ # %g :: The last two digits of the commercial year
160
+ # %G :: The week-based year according to ISO-8601 (week 1 starts on Monday
161
+ # and includes January 4)
162
+ # %h :: Equivalent to %b
163
+ # %H :: Hour of the day, 24-hour clock (00..23)
164
+ # %I :: Hour of the day, 12-hour clock (01..12)
165
+ # %j :: Day of the year (001..366)
166
+ # %k :: hour, 24-hour clock, blank-padded ( 0..23)
167
+ # %l :: hour, 12-hour clock, blank-padded ( 0..12)
168
+ # %L :: Millisecond of the second (000..999)
169
+ # %m :: Month of the year (01..12)
170
+ # %M :: Minute of the hour (00..59)
171
+ # %n :: Newline (\n)
172
+ # %N :: Fractional seconds digits
173
+ # %p :: Meridian indicator ("AM" or "PM")
174
+ # %P :: Meridian indicator ("am" or "pm")
175
+ # %r :: time, 12-hour (same as %I:%M:%S %p)
176
+ # %R :: time, 24-hour (%H:%M)
177
+ # %s :: Number of seconds since 1970-01-01 00:00:00 UTC.
178
+ # %S :: Second of the minute (00..60)
179
+ # %t :: Tab character (\t)
180
+ # %T :: time, 24-hour (%H:%M:%S)
181
+ # %u :: Day of the week as a decimal, Monday being 1. (1..7)
182
+ # %U :: Week number of the current year, starting with the first Sunday as
183
+ # the first day of the first week (00..53)
184
+ # %v :: VMS date (%e-%b-%Y)
185
+ # %V :: Week number of year according to ISO 8601 (01..53)
186
+ # %W :: Week number of the current year, starting with the first Monday
187
+ # as the first day of the first week (00..53)
188
+ # %w :: Day of the week (Sunday is 0, 0..6)
189
+ # %x :: Preferred representation for the date alone, no time
190
+ # %X :: Preferred representation for the time alone, no date
191
+ # %y :: Year without a century (00..99)
192
+ # %Y :: Year which may include century, if provided
193
+ # %z :: Time zone as hour offset from UTC (e.g. +0900)
194
+ # %Z :: Time zone name
195
+ # %% :: Literal "%" character
196
+ # %+ :: date(1) (%a %b %e %H:%M:%S %Z %Y)
197
+ #
198
+ # require 'time'
199
+ #
200
+ # Time.strptime("2000-10-31", "%Y-%m-%d") #=> 2000-10-31 00:00:00 -0500
201
+ #
202
+ # You must require 'time' to use this method.
203
+ #
204
+ def self.strptime: (String date, String format, ?_TimeLike now) ?{ (Integer) -> Integer } -> Time
205
+
206
+ #
207
+ # Parses +date+ as date-time defined by RFC 2822 and converts it to a Time
208
+ # object. The format is identical to the date format defined by RFC 822 and
209
+ # updated by RFC 1123.
210
+ #
211
+ # ArgumentError is raised if +date+ is not compliant with RFC 2822
212
+ # or if the Time class cannot represent specified date.
213
+ #
214
+ # See #rfc2822 for more information on this format.
215
+ #
216
+ # require 'time'
217
+ #
218
+ # Time.rfc2822("Wed, 05 Oct 2011 22:26:12 -0400")
219
+ # #=> 2010-10-05 22:26:12 -0400
220
+ #
221
+ # You must require 'time' to use this method.
222
+ #
223
+ def self.rfc2822: (String date) -> Time
224
+
225
+ alias self.rfc822 self.rfc2822
226
+
227
+ #
228
+ # Parses +date+ as an HTTP-date defined by RFC 2616 and converts it to a
229
+ # Time object.
230
+ #
231
+ # ArgumentError is raised if +date+ is not compliant with RFC 2616 or if
232
+ # the Time class cannot represent specified date.
233
+ #
234
+ # See #httpdate for more information on this format.
235
+ #
236
+ # require 'time'
237
+ #
238
+ # Time.httpdate("Thu, 06 Oct 2011 02:26:12 GMT")
239
+ # #=> 2011-10-06 02:26:12 UTC
240
+ #
241
+ # You must require 'time' to use this method.
242
+ #
243
+ def self.httpdate: (String date) -> Time
244
+
245
+ #
246
+ # Parses +date+ as a dateTime defined by the XML Schema and converts it to
247
+ # a Time object. The format is a restricted version of the format defined
248
+ # by ISO 8601.
249
+ #
250
+ # ArgumentError is raised if +date+ is not compliant with the format or if
251
+ # the Time class cannot represent specified date.
252
+ #
253
+ # See #xmlschema for more information on this format.
254
+ #
255
+ # require 'time'
256
+ #
257
+ # Time.xmlschema("2011-10-05T22:26:12-04:00")
258
+ # #=> 2011-10-05 22:26:12-04:00
259
+ #
260
+ # You must require 'time' to use this method.
261
+ #
262
+ def self.xmlschema: (String date) -> Time
263
+
264
+ alias self.iso8601 self.xmlschema
265
+
266
+ #
267
+ # Returns a string which represents the time as date-time defined by RFC 2822:
268
+ #
269
+ # day-of-week, DD month-name CCYY hh:mm:ss zone
270
+ #
271
+ # where zone is [+-]hhmm.
272
+ #
273
+ # If +self+ is a UTC time, -0000 is used as zone.
274
+ #
275
+ # require 'time'
276
+ #
277
+ # t = Time.now
278
+ # t.rfc2822 # => "Wed, 05 Oct 2011 22:26:12 -0400"
279
+ #
280
+ # You must require 'time' to use this method.
281
+ #
282
+ def rfc2822: () -> String
283
+
284
+ alias rfc822 rfc2822
285
+
286
+ #
287
+ # Returns a string which represents the time as RFC 1123 date of HTTP-date
288
+ # defined by RFC 2616:
289
+ #
290
+ # day-of-week, DD month-name CCYY hh:mm:ss GMT
291
+ #
292
+ # Note that the result is always UTC (GMT).
293
+ #
294
+ # require 'time'
295
+ #
296
+ # t = Time.now
297
+ # t.httpdate # => "Thu, 06 Oct 2011 02:26:12 GMT"
298
+ #
299
+ # You must require 'time' to use this method.
300
+ #
301
+ def httpdate: () -> String
302
+
303
+ #
304
+ # Returns a string which represents the time as a dateTime defined by XML
305
+ # Schema:
306
+ #
307
+ # CCYY-MM-DDThh:mm:ssTZD
308
+ # CCYY-MM-DDThh:mm:ss.sssTZD
309
+ #
310
+ # where TZD is Z or [+-]hh:mm.
311
+ #
312
+ # If self is a UTC time, Z is used as TZD. [+-]hh:mm is used otherwise.
313
+ #
314
+ # +fractional_digits+ specifies a number of digits to use for fractional
315
+ # seconds. Its default value is 0.
316
+ #
317
+ # require 'time'
318
+ #
319
+ # t = Time.now
320
+ # t.iso8601 # => "2011-10-05T22:26:12-04:00"
321
+ #
322
+ # You must require 'time' to use this method.
323
+ #
324
+ def xmlschema: (?Integer fraction_digits) -> String
325
+
326
+ alias iso8601 xmlschema
327
+ end