rbs 0.2.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 +7 -0
- data/.github/workflows/ruby.yml +28 -0
- data/.gitignore +12 -0
- data/.rubocop.yml +15 -0
- data/BSDL +22 -0
- data/CHANGELOG.md +9 -0
- data/COPYING +56 -0
- data/Gemfile +6 -0
- data/README.md +93 -0
- data/Rakefile +142 -0
- data/bin/annotate-with-rdoc +157 -0
- data/bin/console +14 -0
- data/bin/query-rdoc +103 -0
- data/bin/setup +10 -0
- data/bin/sort +89 -0
- data/bin/test_runner.rb +16 -0
- data/docs/CONTRIBUTING.md +97 -0
- data/docs/sigs.md +148 -0
- data/docs/stdlib.md +152 -0
- data/docs/syntax.md +528 -0
- data/exe/rbs +7 -0
- data/lib/rbs.rb +64 -0
- data/lib/rbs/ast/annotation.rb +27 -0
- data/lib/rbs/ast/comment.rb +27 -0
- data/lib/rbs/ast/declarations.rb +395 -0
- data/lib/rbs/ast/members.rb +362 -0
- data/lib/rbs/buffer.rb +50 -0
- data/lib/rbs/builtin_names.rb +55 -0
- data/lib/rbs/cli.rb +558 -0
- data/lib/rbs/constant.rb +26 -0
- data/lib/rbs/constant_table.rb +150 -0
- data/lib/rbs/definition.rb +170 -0
- data/lib/rbs/definition_builder.rb +919 -0
- data/lib/rbs/environment.rb +281 -0
- data/lib/rbs/environment_loader.rb +136 -0
- data/lib/rbs/environment_walker.rb +124 -0
- data/lib/rbs/errors.rb +187 -0
- data/lib/rbs/location.rb +102 -0
- data/lib/rbs/method_type.rb +123 -0
- data/lib/rbs/namespace.rb +91 -0
- data/lib/rbs/parser.y +1344 -0
- data/lib/rbs/prototype/rb.rb +553 -0
- data/lib/rbs/prototype/rbi.rb +587 -0
- data/lib/rbs/prototype/runtime.rb +381 -0
- data/lib/rbs/substitution.rb +46 -0
- data/lib/rbs/test.rb +26 -0
- data/lib/rbs/test/errors.rb +61 -0
- data/lib/rbs/test/hook.rb +294 -0
- data/lib/rbs/test/setup.rb +58 -0
- data/lib/rbs/test/spy.rb +325 -0
- data/lib/rbs/test/test_helper.rb +183 -0
- data/lib/rbs/test/type_check.rb +254 -0
- data/lib/rbs/type_name.rb +70 -0
- data/lib/rbs/types.rb +936 -0
- data/lib/rbs/variance_calculator.rb +138 -0
- data/lib/rbs/vendorer.rb +47 -0
- data/lib/rbs/version.rb +3 -0
- data/lib/rbs/writer.rb +269 -0
- data/lib/ruby/signature.rb +7 -0
- data/rbs.gemspec +46 -0
- data/stdlib/abbrev/abbrev.rbs +60 -0
- data/stdlib/base64/base64.rbs +71 -0
- data/stdlib/benchmark/benchmark.rbs +372 -0
- data/stdlib/builtin/array.rbs +1997 -0
- data/stdlib/builtin/basic_object.rbs +280 -0
- data/stdlib/builtin/binding.rbs +177 -0
- data/stdlib/builtin/builtin.rbs +45 -0
- data/stdlib/builtin/class.rbs +145 -0
- data/stdlib/builtin/comparable.rbs +116 -0
- data/stdlib/builtin/complex.rbs +400 -0
- data/stdlib/builtin/constants.rbs +37 -0
- data/stdlib/builtin/data.rbs +5 -0
- data/stdlib/builtin/deprecated.rbs +2 -0
- data/stdlib/builtin/dir.rbs +413 -0
- data/stdlib/builtin/encoding.rbs +607 -0
- data/stdlib/builtin/enumerable.rbs +404 -0
- data/stdlib/builtin/enumerator.rbs +260 -0
- data/stdlib/builtin/errno.rbs +781 -0
- data/stdlib/builtin/errors.rbs +582 -0
- data/stdlib/builtin/exception.rbs +194 -0
- data/stdlib/builtin/false_class.rbs +40 -0
- data/stdlib/builtin/fiber.rbs +68 -0
- data/stdlib/builtin/fiber_error.rbs +12 -0
- data/stdlib/builtin/file.rbs +1076 -0
- data/stdlib/builtin/file_test.rbs +59 -0
- data/stdlib/builtin/float.rbs +696 -0
- data/stdlib/builtin/gc.rbs +243 -0
- data/stdlib/builtin/hash.rbs +1029 -0
- data/stdlib/builtin/integer.rbs +707 -0
- data/stdlib/builtin/io.rbs +683 -0
- data/stdlib/builtin/kernel.rbs +576 -0
- data/stdlib/builtin/marshal.rbs +161 -0
- data/stdlib/builtin/match_data.rbs +271 -0
- data/stdlib/builtin/math.rbs +369 -0
- data/stdlib/builtin/method.rbs +185 -0
- data/stdlib/builtin/module.rbs +1104 -0
- data/stdlib/builtin/nil_class.rbs +82 -0
- data/stdlib/builtin/numeric.rbs +409 -0
- data/stdlib/builtin/object.rbs +824 -0
- data/stdlib/builtin/proc.rbs +429 -0
- data/stdlib/builtin/process.rbs +1227 -0
- data/stdlib/builtin/random.rbs +267 -0
- data/stdlib/builtin/range.rbs +226 -0
- data/stdlib/builtin/rational.rbs +424 -0
- data/stdlib/builtin/rb_config.rbs +57 -0
- data/stdlib/builtin/regexp.rbs +1083 -0
- data/stdlib/builtin/ruby_vm.rbs +14 -0
- data/stdlib/builtin/signal.rbs +55 -0
- data/stdlib/builtin/string.rbs +1901 -0
- data/stdlib/builtin/string_io.rbs +284 -0
- data/stdlib/builtin/struct.rbs +40 -0
- data/stdlib/builtin/symbol.rbs +228 -0
- data/stdlib/builtin/thread.rbs +1108 -0
- data/stdlib/builtin/thread_group.rbs +23 -0
- data/stdlib/builtin/time.rbs +1047 -0
- data/stdlib/builtin/trace_point.rbs +290 -0
- data/stdlib/builtin/true_class.rbs +46 -0
- data/stdlib/builtin/unbound_method.rbs +153 -0
- data/stdlib/builtin/warning.rbs +17 -0
- data/stdlib/coverage/coverage.rbs +62 -0
- data/stdlib/csv/csv.rbs +773 -0
- data/stdlib/erb/erb.rbs +392 -0
- data/stdlib/find/find.rbs +40 -0
- data/stdlib/ipaddr/ipaddr.rbs +247 -0
- data/stdlib/json/json.rbs +335 -0
- data/stdlib/pathname/pathname.rbs +1093 -0
- data/stdlib/prime/integer-extension.rbs +23 -0
- data/stdlib/prime/prime.rbs +188 -0
- data/stdlib/securerandom/securerandom.rbs +9 -0
- data/stdlib/set/set.rbs +301 -0
- data/stdlib/tmpdir/tmpdir.rbs +53 -0
- metadata +292 -0
data/stdlib/erb/erb.rbs
ADDED
|
@@ -0,0 +1,392 @@
|
|
|
1
|
+
# # ERB -- Ruby Templating
|
|
2
|
+
#
|
|
3
|
+
# ## Introduction
|
|
4
|
+
#
|
|
5
|
+
# ERB provides an easy to use but powerful templating system for Ruby. Using
|
|
6
|
+
# ERB, actual Ruby code can be added to any plain text document for the purposes
|
|
7
|
+
# of generating document information details and/or flow control.
|
|
8
|
+
#
|
|
9
|
+
# A very simple example is this:
|
|
10
|
+
#
|
|
11
|
+
# require 'erb'
|
|
12
|
+
#
|
|
13
|
+
# x = 42
|
|
14
|
+
# template = ERB.new <<-EOF
|
|
15
|
+
# The value of x is: <%= x %>
|
|
16
|
+
# EOF
|
|
17
|
+
# puts template.result(binding)
|
|
18
|
+
#
|
|
19
|
+
# *Prints:* The value of x is: 42
|
|
20
|
+
#
|
|
21
|
+
# More complex examples are given below.
|
|
22
|
+
#
|
|
23
|
+
# ## Recognized Tags
|
|
24
|
+
#
|
|
25
|
+
# ERB recognizes certain tags in the provided template and converts them based
|
|
26
|
+
# on the rules below:
|
|
27
|
+
#
|
|
28
|
+
# <% Ruby code -- inline with output %>
|
|
29
|
+
# <%= Ruby expression -- replace with result %>
|
|
30
|
+
# <%# comment -- ignored -- useful in testing %>
|
|
31
|
+
# % a line of Ruby code -- treated as <% line %> (optional -- see ERB.new)
|
|
32
|
+
# %% replaced with % if first thing on a line and % processing is used
|
|
33
|
+
# <%% or %%> -- replace with <% or %> respectively
|
|
34
|
+
#
|
|
35
|
+
# All other text is passed through ERB filtering unchanged.
|
|
36
|
+
#
|
|
37
|
+
# ## Options
|
|
38
|
+
#
|
|
39
|
+
# There are several settings you can change when you use ERB:
|
|
40
|
+
# * the nature of the tags that are recognized;
|
|
41
|
+
# * the value of `$SAFE` under which the template is run;
|
|
42
|
+
# * the binding used to resolve local variables in the template.
|
|
43
|
+
#
|
|
44
|
+
#
|
|
45
|
+
# See the ERB.new and ERB#result methods for more detail.
|
|
46
|
+
#
|
|
47
|
+
# ## Character encodings
|
|
48
|
+
#
|
|
49
|
+
# ERB (or Ruby code generated by ERB) returns a string in the same character
|
|
50
|
+
# encoding as the input string. When the input string has a magic comment,
|
|
51
|
+
# however, it returns a string in the encoding specified by the magic comment.
|
|
52
|
+
#
|
|
53
|
+
# # -*- coding: utf-8 -*-
|
|
54
|
+
# require 'erb'
|
|
55
|
+
#
|
|
56
|
+
# template = ERB.new <<EOF
|
|
57
|
+
# <%#-*- coding: Big5 -*-%>
|
|
58
|
+
# \_\_ENCODING\_\_ is <%= \_\_ENCODING\_\_ %>.
|
|
59
|
+
# EOF
|
|
60
|
+
# puts template.result
|
|
61
|
+
#
|
|
62
|
+
# *Prints:* _*ENCODING*_ is Big5.
|
|
63
|
+
#
|
|
64
|
+
# ## Examples
|
|
65
|
+
#
|
|
66
|
+
# ### Plain Text
|
|
67
|
+
#
|
|
68
|
+
# ERB is useful for any generic templating situation. Note that in this
|
|
69
|
+
# example, we use the convenient "% at start of line" tag, and we quote the
|
|
70
|
+
# template literally with `%q{...}` to avoid trouble with the backslash.
|
|
71
|
+
#
|
|
72
|
+
# require "erb"
|
|
73
|
+
#
|
|
74
|
+
# # Create template.
|
|
75
|
+
# template = %q{
|
|
76
|
+
# From: James Edward Gray II <james@grayproductions.net>
|
|
77
|
+
# To: <%= to %>
|
|
78
|
+
# Subject: Addressing Needs
|
|
79
|
+
#
|
|
80
|
+
# <%= to[/\w+/] %>:
|
|
81
|
+
#
|
|
82
|
+
# Just wanted to send a quick note assuring that your needs are being
|
|
83
|
+
# addressed.
|
|
84
|
+
#
|
|
85
|
+
# I want you to know that my team will keep working on the issues,
|
|
86
|
+
# especially:
|
|
87
|
+
#
|
|
88
|
+
# <%# ignore numerous minor requests -- focus on priorities %>
|
|
89
|
+
# % priorities.each do |priority|
|
|
90
|
+
# * <%= priority %>
|
|
91
|
+
# % end
|
|
92
|
+
#
|
|
93
|
+
# Thanks for your patience.
|
|
94
|
+
#
|
|
95
|
+
# James Edward Gray II
|
|
96
|
+
# }.gsub(/^ /, '')
|
|
97
|
+
#
|
|
98
|
+
# message = ERB.new(template, trim_mode: "%<>")
|
|
99
|
+
#
|
|
100
|
+
# # Set up template data.
|
|
101
|
+
# to = "Community Spokesman <spokesman@ruby_community.org>"
|
|
102
|
+
# priorities = [ "Run Ruby Quiz",
|
|
103
|
+
# "Document Modules",
|
|
104
|
+
# "Answer Questions on Ruby Talk" ]
|
|
105
|
+
#
|
|
106
|
+
# # Produce result.
|
|
107
|
+
# email = message.result
|
|
108
|
+
# puts email
|
|
109
|
+
#
|
|
110
|
+
# *Generates:*
|
|
111
|
+
#
|
|
112
|
+
# From: James Edward Gray II <james@grayproductions.net>
|
|
113
|
+
# To: Community Spokesman <spokesman@ruby_community.org>
|
|
114
|
+
# Subject: Addressing Needs
|
|
115
|
+
#
|
|
116
|
+
# Community:
|
|
117
|
+
#
|
|
118
|
+
# Just wanted to send a quick note assuring that your needs are being addressed.
|
|
119
|
+
#
|
|
120
|
+
# I want you to know that my team will keep working on the issues, especially:
|
|
121
|
+
#
|
|
122
|
+
# * Run Ruby Quiz
|
|
123
|
+
# * Document Modules
|
|
124
|
+
# * Answer Questions on Ruby Talk
|
|
125
|
+
#
|
|
126
|
+
# Thanks for your patience.
|
|
127
|
+
#
|
|
128
|
+
# James Edward Gray II
|
|
129
|
+
#
|
|
130
|
+
# ### Ruby in HTML
|
|
131
|
+
#
|
|
132
|
+
# ERB is often used in `.rhtml` files (HTML with embedded Ruby). Notice the
|
|
133
|
+
# need in this example to provide a special binding when the template is run, so
|
|
134
|
+
# that the instance variables in the Product object can be resolved.
|
|
135
|
+
#
|
|
136
|
+
# require "erb"
|
|
137
|
+
#
|
|
138
|
+
# # Build template data class.
|
|
139
|
+
# class Product
|
|
140
|
+
# def initialize( code, name, desc, cost )
|
|
141
|
+
# @code = code
|
|
142
|
+
# @name = name
|
|
143
|
+
# @desc = desc
|
|
144
|
+
# @cost = cost
|
|
145
|
+
#
|
|
146
|
+
# @features = [ ]
|
|
147
|
+
# end
|
|
148
|
+
#
|
|
149
|
+
# def add_feature( feature )
|
|
150
|
+
# @features << feature
|
|
151
|
+
# end
|
|
152
|
+
#
|
|
153
|
+
# # Support templating of member data.
|
|
154
|
+
# def get_binding
|
|
155
|
+
# binding
|
|
156
|
+
# end
|
|
157
|
+
#
|
|
158
|
+
# # ...
|
|
159
|
+
# end
|
|
160
|
+
#
|
|
161
|
+
# # Create template.
|
|
162
|
+
# template = %{
|
|
163
|
+
# <html>
|
|
164
|
+
# <head><title>Ruby Toys -- <%= @name %></title></head>
|
|
165
|
+
# <body>
|
|
166
|
+
#
|
|
167
|
+
# <h1><%= @name %> (<%= @code %>)</h1>
|
|
168
|
+
# <p><%= @desc %></p>
|
|
169
|
+
#
|
|
170
|
+
# <ul>
|
|
171
|
+
# <% @features.each do |f| %>
|
|
172
|
+
# <li><b><%= f %></b></li>
|
|
173
|
+
# <% end %>
|
|
174
|
+
# </ul>
|
|
175
|
+
#
|
|
176
|
+
# <p>
|
|
177
|
+
# <% if @cost < 10 %>
|
|
178
|
+
# <b>Only <%= @cost %>!!!</b>
|
|
179
|
+
# <% else %>
|
|
180
|
+
# Call for a price, today!
|
|
181
|
+
# <% end %>
|
|
182
|
+
# </p>
|
|
183
|
+
#
|
|
184
|
+
# </body>
|
|
185
|
+
# </html>
|
|
186
|
+
# }.gsub(/^ /, '')
|
|
187
|
+
#
|
|
188
|
+
# rhtml = ERB.new(template)
|
|
189
|
+
#
|
|
190
|
+
# # Set up template data.
|
|
191
|
+
# toy = Product.new( "TZ-1002",
|
|
192
|
+
# "Rubysapien",
|
|
193
|
+
# "Geek's Best Friend! Responds to Ruby commands...",
|
|
194
|
+
# 999.95 )
|
|
195
|
+
# toy.add_feature("Listens for verbal commands in the Ruby language!")
|
|
196
|
+
# toy.add_feature("Ignores Perl, Java, and all C variants.")
|
|
197
|
+
# toy.add_feature("Karate-Chop Action!!!")
|
|
198
|
+
# toy.add_feature("Matz signature on left leg.")
|
|
199
|
+
# toy.add_feature("Gem studded eyes... Rubies, of course!")
|
|
200
|
+
#
|
|
201
|
+
# # Produce result.
|
|
202
|
+
# rhtml.run(toy.get_binding)
|
|
203
|
+
#
|
|
204
|
+
# *Generates (some blank lines removed):*
|
|
205
|
+
#
|
|
206
|
+
# <html>
|
|
207
|
+
# <head><title>Ruby Toys -- Rubysapien</title></head>
|
|
208
|
+
# <body>
|
|
209
|
+
#
|
|
210
|
+
# <h1>Rubysapien (TZ-1002)</h1>
|
|
211
|
+
# <p>Geek's Best Friend! Responds to Ruby commands...</p>
|
|
212
|
+
#
|
|
213
|
+
# <ul>
|
|
214
|
+
# <li><b>Listens for verbal commands in the Ruby language!</b></li>
|
|
215
|
+
# <li><b>Ignores Perl, Java, and all C variants.</b></li>
|
|
216
|
+
# <li><b>Karate-Chop Action!!!</b></li>
|
|
217
|
+
# <li><b>Matz signature on left leg.</b></li>
|
|
218
|
+
# <li><b>Gem studded eyes... Rubies, of course!</b></li>
|
|
219
|
+
# </ul>
|
|
220
|
+
#
|
|
221
|
+
# <p>
|
|
222
|
+
# Call for a price, today!
|
|
223
|
+
# </p>
|
|
224
|
+
#
|
|
225
|
+
# </body>
|
|
226
|
+
# </html>
|
|
227
|
+
#
|
|
228
|
+
# ## Notes
|
|
229
|
+
#
|
|
230
|
+
# There are a variety of templating solutions available in various Ruby
|
|
231
|
+
# projects:
|
|
232
|
+
# * ERB's big brother, eRuby, works the same but is written in C for speed;
|
|
233
|
+
# * Amrita (smart at producing HTML/XML);
|
|
234
|
+
# * cs/Template (written in C for speed);
|
|
235
|
+
# * RDoc, distributed with Ruby, uses its own template engine, which can be
|
|
236
|
+
# reused elsewhere;
|
|
237
|
+
# * and others; search [RubyGems.org](https://rubygems.org/) or [The Ruby
|
|
238
|
+
# Toolbox](https://www.ruby-toolbox.com/).
|
|
239
|
+
#
|
|
240
|
+
#
|
|
241
|
+
# Rails, the web application framework, uses ERB to create views.
|
|
242
|
+
#
|
|
243
|
+
class ERB
|
|
244
|
+
# Returns revision information for the erb.rb module.
|
|
245
|
+
#
|
|
246
|
+
def self.version: () -> String
|
|
247
|
+
|
|
248
|
+
# Constructs a new ERB object with the template specified in *str*.
|
|
249
|
+
#
|
|
250
|
+
# An ERB object works by building a chunk of Ruby code that will output the
|
|
251
|
+
# completed template when run. If *safe_level* is set to a non-nil value, ERB
|
|
252
|
+
# code will be run in a separate thread with **$SAFE** set to the provided
|
|
253
|
+
# level.
|
|
254
|
+
#
|
|
255
|
+
# If *trim_mode* is passed a String containing one or more of the following
|
|
256
|
+
# modifiers, ERB will adjust its code generation as listed:
|
|
257
|
+
#
|
|
258
|
+
# % enables Ruby code processing for lines beginning with %
|
|
259
|
+
# <> omit newline for lines starting with <% and ending in %>
|
|
260
|
+
# > omit newline for lines ending in %>
|
|
261
|
+
# - omit blank lines ending in -%>
|
|
262
|
+
#
|
|
263
|
+
# *eoutvar* can be used to set the name of the variable ERB will build up its
|
|
264
|
+
# output in. This is useful when you need to run multiple ERB templates through
|
|
265
|
+
# the same binding and/or when you want to control where output ends up. Pass
|
|
266
|
+
# the name of the variable to be used inside a String.
|
|
267
|
+
#
|
|
268
|
+
# ### Example
|
|
269
|
+
#
|
|
270
|
+
# require "erb"
|
|
271
|
+
#
|
|
272
|
+
# # build data class
|
|
273
|
+
# class Listings
|
|
274
|
+
# PRODUCT = { :name => "Chicken Fried Steak",
|
|
275
|
+
# :desc => "A well messages pattie, breaded and fried.",
|
|
276
|
+
# :cost => 9.95 }
|
|
277
|
+
#
|
|
278
|
+
# attr_reader :product, :price
|
|
279
|
+
#
|
|
280
|
+
# def initialize( product = "", price = "" )
|
|
281
|
+
# @product = product
|
|
282
|
+
# @price = price
|
|
283
|
+
# end
|
|
284
|
+
#
|
|
285
|
+
# def build
|
|
286
|
+
# b = binding
|
|
287
|
+
# # create and run templates, filling member data variables
|
|
288
|
+
# ERB.new(<<-'END_PRODUCT'.gsub(/^\s+/, ""), trim_mode: "", eoutvar: "@product").result b
|
|
289
|
+
# <%= PRODUCT[:name] %>
|
|
290
|
+
# <%= PRODUCT[:desc] %>
|
|
291
|
+
# END_PRODUCT
|
|
292
|
+
# ERB.new(<<-'END_PRICE'.gsub(/^\s+/, ""), trim_mode: "", eoutvar: "@price").result b
|
|
293
|
+
# <%= PRODUCT[:name] %> -- <%= PRODUCT[:cost] %>
|
|
294
|
+
# <%= PRODUCT[:desc] %>
|
|
295
|
+
# END_PRICE
|
|
296
|
+
# end
|
|
297
|
+
# end
|
|
298
|
+
#
|
|
299
|
+
# # setup template data
|
|
300
|
+
# listings = Listings.new
|
|
301
|
+
# listings.build
|
|
302
|
+
#
|
|
303
|
+
# puts listings.product + "\n" + listings.price
|
|
304
|
+
#
|
|
305
|
+
# *Generates*
|
|
306
|
+
#
|
|
307
|
+
# Chicken Fried Steak
|
|
308
|
+
# A well messages pattie, breaded and fried.
|
|
309
|
+
#
|
|
310
|
+
# Chicken Fried Steak -- 9.95
|
|
311
|
+
# A well messages pattie, breaded and fried.
|
|
312
|
+
#
|
|
313
|
+
def initialize: (String, ?eoutvar: String, ?trim_mode: Integer | String | NilClass) -> untyped
|
|
314
|
+
|
|
315
|
+
# The Ruby code generated by ERB
|
|
316
|
+
#
|
|
317
|
+
def src: () -> String
|
|
318
|
+
|
|
319
|
+
# The encoding to eval
|
|
320
|
+
#
|
|
321
|
+
def encoding: () -> Encoding
|
|
322
|
+
|
|
323
|
+
# The optional *filename* argument passed to Kernel#eval when the ERB code is
|
|
324
|
+
# run
|
|
325
|
+
#
|
|
326
|
+
def filename: () -> (String | NilClass)
|
|
327
|
+
def filename=: (String | NilClass) -> untyped
|
|
328
|
+
|
|
329
|
+
# The optional *lineno* argument passed to Kernel#eval when the ERB code is run
|
|
330
|
+
#
|
|
331
|
+
def lineno: () -> Integer
|
|
332
|
+
def lineno=: (Integer) -> untyped
|
|
333
|
+
def location=: (Array[String | Integer]) -> untyped
|
|
334
|
+
|
|
335
|
+
# Generate results and print them. (see ERB#result)
|
|
336
|
+
#
|
|
337
|
+
def run: (?Binding) -> untyped
|
|
338
|
+
|
|
339
|
+
# Executes the generated ERB code to produce a completed template, returning the
|
|
340
|
+
# results of that code. (See ERB::new for details on how this process can be
|
|
341
|
+
# affected by *safe_level*.)
|
|
342
|
+
#
|
|
343
|
+
# *b* accepts a Binding object which is used to set the context of code
|
|
344
|
+
# evaluation.
|
|
345
|
+
#
|
|
346
|
+
def result: (?Binding) -> String
|
|
347
|
+
|
|
348
|
+
# Render a template on a new toplevel binding with local variables specified by
|
|
349
|
+
# a Hash object.
|
|
350
|
+
#
|
|
351
|
+
def result_with_hash: (Hash[untyped, untyped]) -> String
|
|
352
|
+
|
|
353
|
+
# Define *methodname* as instance method of *mod* from compiled Ruby source.
|
|
354
|
+
#
|
|
355
|
+
# example:
|
|
356
|
+
# filename = 'example.rhtml' # 'arg1' and 'arg2' are used in example.rhtml
|
|
357
|
+
# erb = ERB.new(File.read(filename))
|
|
358
|
+
# erb.def_method(MyClass, 'render(arg1, arg2)', filename)
|
|
359
|
+
# print MyClass.new.render('foo', 123)
|
|
360
|
+
#
|
|
361
|
+
def def_method: (Module, String, ?String) -> untyped
|
|
362
|
+
|
|
363
|
+
# Create unnamed module, define *methodname* as instance method of it, and
|
|
364
|
+
# return it.
|
|
365
|
+
#
|
|
366
|
+
# example:
|
|
367
|
+
# filename = 'example.rhtml' # 'arg1' and 'arg2' are used in example.rhtml
|
|
368
|
+
# erb = ERB.new(File.read(filename))
|
|
369
|
+
# erb.filename = filename
|
|
370
|
+
# MyModule = erb.def_module('render(arg1, arg2)')
|
|
371
|
+
# class MyClass
|
|
372
|
+
# include MyModule
|
|
373
|
+
# end
|
|
374
|
+
#
|
|
375
|
+
def def_module: (?String) -> Module
|
|
376
|
+
|
|
377
|
+
# Define unnamed class which has *methodname* as instance method, and return it.
|
|
378
|
+
#
|
|
379
|
+
# example:
|
|
380
|
+
# class MyClass_
|
|
381
|
+
# def initialize(arg1, arg2)
|
|
382
|
+
# @arg1 = arg1; @arg2 = arg2
|
|
383
|
+
# end
|
|
384
|
+
# end
|
|
385
|
+
# filename = 'example.rhtml' # @arg1 and @arg2 are used in example.rhtml
|
|
386
|
+
# erb = ERB.new(File.read(filename))
|
|
387
|
+
# erb.filename = filename
|
|
388
|
+
# MyClass = erb.def_class(MyClass_, 'render()')
|
|
389
|
+
# print MyClass.new('foo', 123).render()
|
|
390
|
+
#
|
|
391
|
+
def def_class: (?Class, ?String) -> Class
|
|
392
|
+
end
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# The `Find` module supports the top-down traversal of a set of file paths.
|
|
2
|
+
#
|
|
3
|
+
# For example, to total the size of all files under your home directory,
|
|
4
|
+
# ignoring anything in a "dot" directory (e.g. $HOME/.ssh):
|
|
5
|
+
#
|
|
6
|
+
# require 'find'
|
|
7
|
+
#
|
|
8
|
+
# total_size = 0
|
|
9
|
+
#
|
|
10
|
+
# Find.find(ENV["HOME"]) do |path|
|
|
11
|
+
# if FileTest.directory?(path)
|
|
12
|
+
# if File.basename(path).start_with?('.')
|
|
13
|
+
# Find.prune # Don't look any further into this directory.
|
|
14
|
+
# else
|
|
15
|
+
# next
|
|
16
|
+
# end
|
|
17
|
+
# else
|
|
18
|
+
# total_size += FileTest.size(path)
|
|
19
|
+
# end
|
|
20
|
+
# end
|
|
21
|
+
#
|
|
22
|
+
module Find
|
|
23
|
+
# Calls the associated block with the name of every file and directory listed as
|
|
24
|
+
# arguments, then recursively on their subdirectories, and so on.
|
|
25
|
+
#
|
|
26
|
+
# Returns an enumerator if no block is given.
|
|
27
|
+
#
|
|
28
|
+
# See the `Find` module documentation for an example.
|
|
29
|
+
#
|
|
30
|
+
def self?.find: (*String | _ToPath paths, ?ignore_error: bool) -> Enumerator[String, nil]
|
|
31
|
+
| (*String | _ToPath paths, ?ignore_error: bool) { (String arg0) -> void } -> nil
|
|
32
|
+
|
|
33
|
+
# Skips the current file or directory, restarting the loop with the next entry.
|
|
34
|
+
# If the current file is a directory, that directory will not be recursively
|
|
35
|
+
# entered. Meaningful only within the block associated with Find::find.
|
|
36
|
+
#
|
|
37
|
+
# See the `Find` module documentation for an example.
|
|
38
|
+
#
|
|
39
|
+
def self?.prune: () -> void
|
|
40
|
+
end
|
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
# IPAddr provides a set of methods to manipulate an IP address. Both IPv4 and
|
|
2
|
+
# IPv6 are supported.
|
|
3
|
+
#
|
|
4
|
+
# ## Example
|
|
5
|
+
#
|
|
6
|
+
# require 'ipaddr'
|
|
7
|
+
#
|
|
8
|
+
# ipaddr1 = IPAddr.new "3ffe:505:2::1"
|
|
9
|
+
#
|
|
10
|
+
# p ipaddr1 #=> #<IPAddr: IPv6:3ffe:0505:0002:0000:0000:0000:0000:0001/ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff>
|
|
11
|
+
#
|
|
12
|
+
# p ipaddr1.to_s #=> "3ffe:505:2::1"
|
|
13
|
+
#
|
|
14
|
+
# ipaddr2 = ipaddr1.mask(48) #=> #<IPAddr: IPv6:3ffe:0505:0002:0000:0000:0000:0000:0000/ffff:ffff:ffff:0000:0000:0000:0000:0000>
|
|
15
|
+
#
|
|
16
|
+
# p ipaddr2.to_s #=> "3ffe:505:2::"
|
|
17
|
+
#
|
|
18
|
+
# ipaddr3 = IPAddr.new "192.168.2.0/24"
|
|
19
|
+
#
|
|
20
|
+
# p ipaddr3 #=> #<IPAddr: IPv4:192.168.2.0/255.255.255.0>
|
|
21
|
+
#
|
|
22
|
+
class IPAddr
|
|
23
|
+
include Comparable
|
|
24
|
+
|
|
25
|
+
# Creates a new ipaddr containing the given network byte ordered string form of
|
|
26
|
+
# an IP address.
|
|
27
|
+
#
|
|
28
|
+
def self.new_ntoh: (String addr) -> IPAddr
|
|
29
|
+
|
|
30
|
+
# Convert a network byte ordered string form of an IP address into human
|
|
31
|
+
# readable form.
|
|
32
|
+
#
|
|
33
|
+
def self.ntop: (String addr) -> String
|
|
34
|
+
|
|
35
|
+
# Creates a new ipaddr object either from a human readable IP address
|
|
36
|
+
# representation in string, or from a packed in_addr value followed by an
|
|
37
|
+
# address family.
|
|
38
|
+
#
|
|
39
|
+
# In the former case, the following are the valid formats that will be
|
|
40
|
+
# recognized: "address", "address/prefixlen" and "address/mask", where IPv6
|
|
41
|
+
# address may be enclosed in square brackets (`[' and `]'). If a prefixlen or a
|
|
42
|
+
# mask is specified, it returns a masked IP address. Although the address
|
|
43
|
+
# family is determined automatically from a specified string, you can specify
|
|
44
|
+
# one explicitly by the optional second argument.
|
|
45
|
+
#
|
|
46
|
+
# Otherwise an IP address is generated from a packed in_addr value and an
|
|
47
|
+
# address family.
|
|
48
|
+
#
|
|
49
|
+
# The IPAddr class defines many methods and operators, and some of those, such
|
|
50
|
+
# as &, |, include? and ==, accept a string, or a packed in_addr value instead
|
|
51
|
+
# of an IPAddr object.
|
|
52
|
+
#
|
|
53
|
+
def initialize: (?String addr, ?untyped family) -> IPAddr
|
|
54
|
+
|
|
55
|
+
# Returns a new ipaddr built by bitwise AND.
|
|
56
|
+
#
|
|
57
|
+
def &: (untyped other) -> IPAddr
|
|
58
|
+
|
|
59
|
+
# Returns a new ipaddr built by bitwise left shift.
|
|
60
|
+
#
|
|
61
|
+
def <<: (Integer num) -> IPAddr
|
|
62
|
+
|
|
63
|
+
# Compares the ipaddr with another.
|
|
64
|
+
#
|
|
65
|
+
def <=>: (untyped other) -> Integer?
|
|
66
|
+
|
|
67
|
+
# Returns true if two ipaddrs are equal.
|
|
68
|
+
#
|
|
69
|
+
def ==: (untyped other) -> bool
|
|
70
|
+
|
|
71
|
+
alias === include?
|
|
72
|
+
|
|
73
|
+
# Returns a new ipaddr built by bitwise right-shift.
|
|
74
|
+
#
|
|
75
|
+
def >>: (Integer num) -> IPAddr
|
|
76
|
+
|
|
77
|
+
# Checks equality used by Hash.
|
|
78
|
+
#
|
|
79
|
+
def eql?: (untyped other) -> bool
|
|
80
|
+
|
|
81
|
+
# Returns the address family of this IP address.
|
|
82
|
+
#
|
|
83
|
+
attr_reader family: Integer
|
|
84
|
+
|
|
85
|
+
# Returns a hash value used by Hash, Set, and Array classes
|
|
86
|
+
#
|
|
87
|
+
def hash: () -> Integer
|
|
88
|
+
|
|
89
|
+
# Returns a network byte ordered string form of the IP address.
|
|
90
|
+
#
|
|
91
|
+
def hton: () -> String
|
|
92
|
+
|
|
93
|
+
# Returns true if the given ipaddr is in the range.
|
|
94
|
+
#
|
|
95
|
+
# e.g.:
|
|
96
|
+
# require 'ipaddr'
|
|
97
|
+
# net1 = IPAddr.new("192.168.2.0/24")
|
|
98
|
+
# net2 = IPAddr.new("192.168.2.100")
|
|
99
|
+
# net3 = IPAddr.new("192.168.3.0")
|
|
100
|
+
# p net1.include?(net2) #=> true
|
|
101
|
+
# p net1.include?(net3) #=> false
|
|
102
|
+
#
|
|
103
|
+
def include?: (untyped other) -> bool
|
|
104
|
+
|
|
105
|
+
# Returns a string containing a human-readable representation of the ipaddr.
|
|
106
|
+
# ("#<IPAddr: family:address/mask>")
|
|
107
|
+
#
|
|
108
|
+
def inspect: () -> String
|
|
109
|
+
|
|
110
|
+
# Returns a string for DNS reverse lookup compatible with RFC3172.
|
|
111
|
+
#
|
|
112
|
+
def ip6_arpa: () -> String
|
|
113
|
+
|
|
114
|
+
# Returns a string for DNS reverse lookup compatible with RFC1886.
|
|
115
|
+
#
|
|
116
|
+
def ip6_int: () -> String
|
|
117
|
+
|
|
118
|
+
# Returns true if the ipaddr is an IPv4 address.
|
|
119
|
+
#
|
|
120
|
+
def ipv4?: () -> bool
|
|
121
|
+
|
|
122
|
+
# Returns a new ipaddr built by converting the native IPv4 address into an
|
|
123
|
+
# IPv4-compatible IPv6 address.
|
|
124
|
+
#
|
|
125
|
+
def ipv4_compat: () -> IPAddr
|
|
126
|
+
|
|
127
|
+
# Returns true if the ipaddr is an IPv4-compatible IPv6 address.
|
|
128
|
+
#
|
|
129
|
+
def ipv4_compat?: () -> bool
|
|
130
|
+
|
|
131
|
+
# Returns a new ipaddr built by converting the native IPv4 address into an
|
|
132
|
+
# IPv4-mapped IPv6 address.
|
|
133
|
+
#
|
|
134
|
+
def ipv4_mapped: () -> IPAddr
|
|
135
|
+
|
|
136
|
+
# Returns true if the ipaddr is an IPv4-mapped IPv6 address.
|
|
137
|
+
#
|
|
138
|
+
def ipv4_mapped?: () -> bool
|
|
139
|
+
|
|
140
|
+
# Returns true if the ipaddr is an IPv6 address.
|
|
141
|
+
#
|
|
142
|
+
def ipv6?: () -> bool
|
|
143
|
+
|
|
144
|
+
# Returns true if the ipaddr is a link-local address. IPv4 addresses in
|
|
145
|
+
# 169.254.0.0/16 reserved by RFC 3927 and Link-Local IPv6 Unicast Addresses in
|
|
146
|
+
# fe80::/10 reserved by RFC 4291 are considered link-local.
|
|
147
|
+
#
|
|
148
|
+
def link_local?: () -> bool
|
|
149
|
+
|
|
150
|
+
# Returns true if the ipaddr is a loopback address.
|
|
151
|
+
#
|
|
152
|
+
def loopback?: () -> bool
|
|
153
|
+
|
|
154
|
+
# Returns a new ipaddr built by masking IP address with the given
|
|
155
|
+
# prefixlen/netmask. (e.g. 8, 64, "255.255.255.0", etc.)
|
|
156
|
+
#
|
|
157
|
+
def mask: (String | Integer prefixlen) -> IPAddr
|
|
158
|
+
|
|
159
|
+
# Returns a new ipaddr built by converting the IPv6 address into a native IPv4
|
|
160
|
+
# address. If the IP address is not an IPv4-mapped or IPv4-compatible IPv6
|
|
161
|
+
# address, returns self.
|
|
162
|
+
#
|
|
163
|
+
def native: () -> IPAddr
|
|
164
|
+
|
|
165
|
+
# Returns the prefix length in bits for the ipaddr.
|
|
166
|
+
#
|
|
167
|
+
def prefix: () -> Integer
|
|
168
|
+
|
|
169
|
+
# Sets the prefix length in bits
|
|
170
|
+
#
|
|
171
|
+
def prefix=: (Integer prefix) -> self
|
|
172
|
+
|
|
173
|
+
# Returns true if the ipaddr is a private address. IPv4 addresses in
|
|
174
|
+
# 10.0.0.0/8, 172.16.0.0/12 and 192.168.0.0/16 as defined in RFC 1918 and IPv6
|
|
175
|
+
# Unique Local Addresses in fc00::/7 as defined in RFC 4193 are considered
|
|
176
|
+
# private.
|
|
177
|
+
#
|
|
178
|
+
def private?: () -> bool
|
|
179
|
+
|
|
180
|
+
# Returns a string for DNS reverse lookup. It returns a string in RFC3172 form
|
|
181
|
+
# for an IPv6 address.
|
|
182
|
+
#
|
|
183
|
+
def reverse: () -> String
|
|
184
|
+
|
|
185
|
+
# Returns the successor to the ipaddr.
|
|
186
|
+
#
|
|
187
|
+
def succ: () -> IPAddr
|
|
188
|
+
|
|
189
|
+
# Returns the integer representation of the ipaddr.
|
|
190
|
+
#
|
|
191
|
+
def to_i: () -> Integer
|
|
192
|
+
|
|
193
|
+
# Creates a Range object for the network address.
|
|
194
|
+
#
|
|
195
|
+
def to_range: () -> Range[IPAddr]
|
|
196
|
+
|
|
197
|
+
# Returns a string containing the IP address representation.
|
|
198
|
+
#
|
|
199
|
+
def to_s: () -> String
|
|
200
|
+
|
|
201
|
+
# Returns a string containing the IP address representation in canonical form.
|
|
202
|
+
#
|
|
203
|
+
def to_string: () -> String
|
|
204
|
+
|
|
205
|
+
# Returns a new ipaddr built by bitwise OR.
|
|
206
|
+
#
|
|
207
|
+
def |: (untyped other) -> IPAddr
|
|
208
|
+
|
|
209
|
+
# Returns a new ipaddr built by bitwise negation.
|
|
210
|
+
#
|
|
211
|
+
def ~: () -> IPAddr
|
|
212
|
+
end
|
|
213
|
+
|
|
214
|
+
# Generic IPAddr related error. Exceptions raised in this class should inherit
|
|
215
|
+
# from Error.
|
|
216
|
+
#
|
|
217
|
+
class IPAddr::Error < ArgumentError
|
|
218
|
+
end
|
|
219
|
+
|
|
220
|
+
# Raised when the provided IP address is an invalid address.
|
|
221
|
+
#
|
|
222
|
+
class IPAddr::InvalidAddressError < IPAddr::Error
|
|
223
|
+
end
|
|
224
|
+
|
|
225
|
+
# Raised when the address family is invalid such as an address with an
|
|
226
|
+
# unsupported family, an address with an inconsistent family, or an address
|
|
227
|
+
# who's family cannot be determined.
|
|
228
|
+
#
|
|
229
|
+
class IPAddr::AddressFamilyError < IPAddr::Error
|
|
230
|
+
end
|
|
231
|
+
|
|
232
|
+
# Raised when the address is an invalid length.
|
|
233
|
+
#
|
|
234
|
+
class IPAddr::InvalidPrefixError < IPAddr::InvalidAddressError
|
|
235
|
+
end
|
|
236
|
+
|
|
237
|
+
# 32 bit mask for IPv4
|
|
238
|
+
#
|
|
239
|
+
IPAddr::IN4MASK: Integer
|
|
240
|
+
|
|
241
|
+
# Format string for IPv6
|
|
242
|
+
#
|
|
243
|
+
IPAddr::IN6FORMAT: String
|
|
244
|
+
|
|
245
|
+
# 128 bit mask for IPv6
|
|
246
|
+
#
|
|
247
|
+
IPAddr::IN6MASK: Integer
|