Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added note about imports where necessary #13026

Merged
merged 4 commits into from
Feb 13, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/benchmark.cr
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ require "./benchmark/**"
# The Benchmark module provides methods for benchmarking Crystal code, giving
# detailed reports on the time and memory taken for each task.
#
# NOTE: To use `Benchmark`, you must explicitly import it with `require "benchmark"`
#
# ### Measure the number of iterations per second of each task
#
# ```
Expand Down
2 changes: 2 additions & 0 deletions src/big/big_decimal.cr
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ end
# Value contains the actual value, and scale tells the decimal point place.
# E.g. when value is `1234` and scale `2`, the result is `12.34`.
#
# NOTE: To use `BigDecimal`, you must explicitly import it with `require "big"`
#
# The general idea and some of the arithmetic algorithms were adapted from
# the MIT/APACHE-licensed [bigdecimal-rs](https://github.com/akubera/bigdecimal-rs).
struct BigDecimal < Number
Expand Down
2 changes: 2 additions & 0 deletions src/big/big_float.cr
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ require "big"
# A `BigFloat` can represent arbitrarily large floats.
#
# It is implemented under the hood with [GMP](https://gmplib.org/).
#
# NOTE: To use `BigFloat`, you must explicitly import it with `require "big"`
struct BigFloat < Float
include Comparable(Int)
include Comparable(BigFloat)
Expand Down
2 changes: 2 additions & 0 deletions src/big/big_int.cr
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ require "random"
# A `BigInt` can represent arbitrarily large integers.
#
# It is implemented under the hood with [GMP](https://gmplib.org/).
#
# NOTE: To use `BigInt`, you must explicitly import it with `require "big"`
struct BigInt < Int
include Comparable(Int::Signed)
include Comparable(Int::Unsigned)
Expand Down
2 changes: 2 additions & 0 deletions src/big/big_rational.cr
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ require "big"
# denominator and the numerator have no common factors, and that the
# denominator is positive. Zero has the unique representation 0/1.
#
# NOTE: To use `BigRational`, you must explicitly import it with `require "big"`
#
# ```
# require "big"
#
Expand Down
2 changes: 2 additions & 0 deletions src/bit_array.cr
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
# `UInt32`s. The total number of bits stored is set at creation and is
# immutable.
#
# NOTE: To use `BitArray`, you must explicitly import it with `require "bit_array"`
#
# ### Example
#
# ```
Expand Down
2 changes: 2 additions & 0 deletions src/colorize.cr
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
# as its main interface, which calls `to_s` and surrounds it with the necessary escape codes
# when it comes to obtaining a string representation of the object.
#
# NOTE: To use `Colorize`, you must explicitly import it with `require "colorize"`
#
Tamnac marked this conversation as resolved.
Show resolved Hide resolved
# Its first argument changes the foreground color:
#
# ```
Expand Down
2 changes: 2 additions & 0 deletions src/complex.cr
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
# The a is the real part of the number, and the b is the imaginary part of
# the number.
#
# NOTE: To use `Complex`, you must explicitly import it with `require "complex"`
#
# ```
# require "complex"
#
Expand Down
2 changes: 2 additions & 0 deletions src/compress/deflate/deflate.cr
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ require "./*"
#
# See `Gzip`, `Zip` and `Zlib` for modules that provide access
# to DEFLATE-based file formats.
#
# NOTE: To use `Deflate` or its children, you must explicitly import it with `require "compress/deflate"`
module Compress::Deflate
NO_COMPRESSION = 0
BEST_SPEED = 1
Expand Down
2 changes: 2 additions & 0 deletions src/compress/gzip/gzip.cr
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ require "digest/crc32"

# The Gzip module contains readers and writers of gzip format compressed
# data, as specified in [RFC 1952](https://www.ietf.org/rfc/rfc1952.txt).
#
# NOTE: To use `Gzip` or its children, you must explicitly import it with `require "compress/gzip"`
module Compress::Gzip
NO_COMPRESSION = Compress::Deflate::NO_COMPRESSION
BEST_SPEED = Compress::Deflate::BEST_SPEED
Expand Down
2 changes: 2 additions & 0 deletions src/compress/zip/zip.cr
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ require "digest/crc32"
# The Compress::Zip module contains readers and writers of the zip
# file format, described at [PKWARE's site](https://pkware.cachefly.net/webdocs/APPNOTE/APPNOTE-6.3.3.TXT).
#
# NOTE: To use `Zip` or its children, you must explicitly import it with `require "compress/zip"`
#
# ### Reading zip files
#
# Two types are provided to read from zip files:
Expand Down
2 changes: 2 additions & 0 deletions src/compress/zlib/zlib.cr
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ require "digest/adler32"

# The Compress::Zlib module contains readers and writers of zlib format compressed
# data, as specified in [RFC 1950](https://www.ietf.org/rfc/rfc1950.txt).
#
# NOTE: To use `Zlib` or its children, you must explicitly import it with `require "compress/zlib"`
module Compress::Zlib
NO_COMPRESSION = Compress::Deflate::NO_COMPRESSION
BEST_SPEED = Compress::Deflate::BEST_SPEED
Expand Down
2 changes: 2 additions & 0 deletions src/crypto/bcrypt.cr
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ require "./subtle"
# Last but not least: beware of denial of services! Always protect your
# application using an external strategy (eg: rate limiting), otherwise
# endpoints that verifies bcrypt hashes will be an easy target.
#
# NOTE: To use `Bcrypt`, you must explicitly import it with `require "crypto/bcrypt"`
class Crypto::Bcrypt
class Error < Exception
end
Expand Down
2 changes: 2 additions & 0 deletions src/crypto/bcrypt/password.cr
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ require "../subtle"

# Generate, read and verify `Crypto::Bcrypt` hashes.
#
# NOTE: To use `Password`, you must explicitly import it with `require "crypto/bcrypt/password"`
#
# ```
# require "crypto/bcrypt/password"
#
Expand Down
2 changes: 2 additions & 0 deletions src/csv.cr
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#
# This module conforms to [RFC 4180](https://tools.ietf.org/html/rfc4180).
#
# NOTE: To use `CSV` or its children, you must explicitly import it with `require "csv"`
#
# ### Parsing
#
# Several ways of parsing CSV are provided. The most straight-forward, but
Expand Down
2 changes: 2 additions & 0 deletions src/digest/adler32.cr
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ require "lib_z"
require "./digest"

# Implements the Adler32 checksum algorithm.
#
# NOTE: To use `Adler32`, you must explicitly import it with `require "digest/adler32"`
class Digest::Adler32 < ::Digest
extend ClassMethods

Expand Down
2 changes: 2 additions & 0 deletions src/digest/crc32.cr
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ require "lib_z"
require "./digest"

# Implements the CRC32 checksum algorithm.
#
# NOTE: To use `CRC32`, you must explicitly import it with `require "digest/crc32"`
class Digest::CRC32 < ::Digest
extend ClassMethods

Expand Down
2 changes: 2 additions & 0 deletions src/digest/md5.cr
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ require "openssl"

# Implements the MD5 digest algorithm.
#
# NOTE: To use `MD5`, you must explicitly import it with `require "digest/md5"`
#
# WARNING: MD5 is no longer a cryptographically secure hash, and should not be
# used in security-related components, like password hashing. For passwords, see
# `Crypto::Bcrypt::Password`. For a generic cryptographic hash, use SHA-256 via
Expand Down
2 changes: 2 additions & 0 deletions src/digest/sha1.cr
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ require "openssl"

# Implements the SHA1 digest algorithm.
#
# NOTE: To use `SHA1`, you must explicitly import it with `require "digest/sha1"`
#
# WARNING: SHA1 is no longer a cryptographically secure hash, and should not be
# used in security-related components, like password hashing. For passwords, see
# `Crypto::Bcrypt::Password`. For a generic cryptographic hash, use SHA-256 via
Expand Down
2 changes: 2 additions & 0 deletions src/digest/sha256.cr
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ require "./digest"
require "openssl"

# Implements the SHA256 digest algorithm.
#
# NOTE: To use `SHA256`, you must explicitly import it with `require "digest/sha256"`
class Digest::SHA256 < ::OpenSSL::Digest
extend ClassMethods

Expand Down
2 changes: 2 additions & 0 deletions src/digest/sha512.cr
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ require "./digest"
require "openssl"

# Implements the SHA512 digest algorithm.
#
# NOTE: To use `SHA256`, you must explicitly import it with `require "digest/sha512"`
class Digest::SHA512 < ::OpenSSL::Digest
extend ClassMethods

Expand Down
2 changes: 2 additions & 0 deletions src/ecr.cr
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
# tag: `<%# hello %>`. An ECR tag can be inserted directly (i.e. the tag itself may be
# escaped) by using a second `%` like so: `<%% a = b %>` or `<%%= foo %>`.
#
# NOTE: To use `ECR`, you must explicitly import it with `require "ecr"`
Tamnac marked this conversation as resolved.
Show resolved Hide resolved
#
# Quick Example:
#
# Create a simple ECR file named `greeter.ecr`:
Expand Down
1 change: 1 addition & 0 deletions src/file_utils.cr
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# NOTE: To use `FileUtils`, you must explicitly import it with `require "file_utils"`
module FileUtils
extend self

Expand Down
2 changes: 2 additions & 0 deletions src/html.cr
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ require "./html/entities"
# Provides HTML escaping and unescaping methods.
#
# For HTML *parsing* see module XML, especially `XML.parse_html`.
#
# NOTE: To use `HTML`, you must explicitly import it with `require "html"`
module HTML
private SUBSTITUTIONS = {
'&' => "&amp;",
Expand Down
2 changes: 2 additions & 0 deletions src/http.cr
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,7 @@ require "./http/log"
require "./http/common"

# The HTTP module contains `HTTP::Client`, `HTTP::Server` and `HTTP::WebSocket` implementations.
#
# NOTE: To use `HTTP`, you must explicitly import it with `require "http"`
module HTTP
end
2 changes: 2 additions & 0 deletions src/http/client.cr
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

# An HTTP Client.
#
# NOTE: To use `Client`, you must explicitly import it with `require "http/client"`
#
# ### One-shot usage
#
# Without a block, an `HTTP::Client::Response` is returned and the response's body
Expand Down
4 changes: 4 additions & 0 deletions src/http/cookie.cr
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ require "./common"

module HTTP
# Represents a cookie with all its attributes. Provides convenient access and modification of them.
#
# NOTE: To use `Cookie`, you must explicitly import it with `require "http/cookie"`
class Cookie
# Possible values for the `SameSite` cookie as described in the [Same-site Cookies Draft](https://tools.ietf.org/html/draft-west-first-party-cookies-07#section-4.1.1).
enum SameSite
Expand Down Expand Up @@ -273,6 +275,8 @@ module HTTP

# Represents a collection of cookies as it can be present inside
# a HTTP request or response.
#
# NOTE: To use `Cookies`, you must explicitly import it with `require "http/cookie"`
class Cookies
include Enumerable(Cookie)

Expand Down
2 changes: 2 additions & 0 deletions src/http/formdata.cr
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ require "mime/multipart"
# Contains utilities for parsing `multipart/form-data` messages, which are
# commonly used for encoding HTML form data.
#
# NOTE: To use `FormData`, you must explicitly import it with `require "http"`
#
# ### Examples
#
# Commonly, you'll want to parse a from response from a HTTP request, and
Expand Down
2 changes: 2 additions & 0 deletions src/http/headers.cr
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#
# Two headers are considered the same if their downcase representation is the same
# (in which `_` is the downcase version of `-`).
#
# NOTE: To use `Headers`, you must explicitly import it with `require "http/headers"`
struct HTTP::Headers
include Enumerable({String, Array(String)})

Expand Down
2 changes: 2 additions & 0 deletions src/http/request.cr
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ require "socket"
# When creating a request with a `String` or `Bytes` its body
# will be a `IO::Memory` wrapping these, and the `Content-Length`
# header will be set appropriately.
#
# NOTE: To use `Request`, you must explicitly import it with `require "http/request"`
class HTTP::Request
property method : String
property headers : Headers
Expand Down
2 changes: 2 additions & 0 deletions src/http/server.cr
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ require "log"
# A server is initialized with a handler chain responsible for processing each
# incoming request.
#
# NOTE: To use `Server`, you must explicitly import it with `require "http/server"`
#
# ```
# require "http/server"
#
Expand Down
2 changes: 2 additions & 0 deletions src/http/server/handler.cr
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ require "./context"
# You can use a handler to intercept any incoming request and can modify the response.
# These can be used for request throttling, ip-based filtering, adding custom headers e.g.
#
# NOTE: To use `Handler`, you must explicitly import it with `require "http/server/handler"`
#
# ### A custom handler
#
# ```
Expand Down
2 changes: 2 additions & 0 deletions src/http/server/handlers/compress_handler.cr
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

# A handler that configures an `HTTP::Server::Response` to compress the response
# output, either using gzip or deflate, depending on the `Accept-Encoding` request header.
#
# NOTE: To use `CompressHandler`, you must explicitly import it with `require "http"`
class HTTP::CompressHandler
include HTTP::Handler

Expand Down
2 changes: 2 additions & 0 deletions src/http/server/handlers/error_handler.cr
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#
# This handler also logs the exceptions to the specified logger or
# the logger for the source "http.server" by default.
#
# NOTE: To use `ErrorHandler`, you must explicitly import it with `require "http"`
class HTTP::ErrorHandler
include HTTP::Handler

Expand Down
2 changes: 2 additions & 0 deletions src/http/server/handlers/log_handler.cr
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ require "log"

# A handler that logs the request method, resource, status code, and
# the time used to execute the next handler
#
# NOTE: To use `LogHandler`, you must explicitly import it with `require "http"`
class HTTP::LogHandler
include HTTP::Handler

Expand Down
2 changes: 2 additions & 0 deletions src/http/server/handlers/static_file_handler.cr
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ require "mime"
# This handler can send precompressed content, if the client accepts it, and a file
# with the same name and `.gz` extension appended is found in the same directory.
# Precompressed files are only served if they are newer than the original file.
#
# NOTE: To use `StaticFileHandler`, you must explicitly import it with `require "http"`
class HTTP::StaticFileHandler
include HTTP::Handler

Expand Down
2 changes: 2 additions & 0 deletions src/http/server/handlers/websocket_handler.cr
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ require "http/web_socket"

# A handler which adds websocket functionality to an `HTTP::Server`.
#
# NOTE: To use `WebSocketHandler`, you must explicitly import it with `require "http"`
#
# When a request can be upgraded, the associated `HTTP::Websocket` and
# `HTTP::Server::Context` will be yielded to the block. For example:
#
Expand Down
2 changes: 2 additions & 0 deletions src/http/status.cr
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#
# It provides constants for the defined HTTP status codes as well as helper
# methods to easily identify the type of response.
#
# NOTE: To use `Status`, you must explicitly import it with `require "http/status"`
enum HTTP::Status
CONTINUE = 100
SWITCHING_PROTOCOLS = 101
Expand Down
2 changes: 2 additions & 0 deletions src/http/web_socket.cr
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
require "./client"
require "./headers"


# NOTE: To use `WebSocket`, you must explicitly import it with `require "http/web_socket"`
class HTTP::WebSocket
getter? closed = false

Expand Down
1 change: 1 addition & 0 deletions src/ini.cr
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# NOTE: To use `INI`, you must explicitly import it with `require "ini"`
module INI
# Exception thrown on an INI parse error.
class ParseException < Exception
Expand Down
2 changes: 2 additions & 0 deletions src/json.cr
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# The JSON module allows parsing and generating [JSON](http://json.org/) documents.
#
# NOTE: To use `JSON` or its children, you must explicitly import it with `require "json"`
#
# ### General type-safe interface
#
# The general type-safe interface for parsing JSON is to invoke `T.from_json` on a
Expand Down
2 changes: 2 additions & 0 deletions src/levenshtein.cr
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# Levenshtein distance methods.
#
# NOTE: To use `Levenshtein`, you must explicitly import it with `require "levenshtein"`
module Levenshtein
# Computes the [levenshtein distance](http://en.wikipedia.org/wiki/Levenshtein_distance) of two strings.
#
Expand Down
2 changes: 2 additions & 0 deletions src/log.cr
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
# `#error`, and `#fatal` methods. They expect a block that will evaluate to the
# message of the entry:
#
# NOTE: To use `Log`, you must explicitly import it with `require "log"`
#
# ```
# require "log"
#
Expand Down
2 changes: 2 additions & 0 deletions src/mime.cr
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ require "crystal/system/mime"

# This module implements a global MIME registry.
#
# NOTE: To use `MIME`, you must explicitly import it with `require "mime"`
#
# ```
# require "mime"
#
Expand Down
Loading