Skip to content

Commit

Permalink
Add types for rqrcode gem
Browse files Browse the repository at this point in the history
RQRCode is a library for creating and rendering QR codes into various formats.
It has a simple interface with all the standard QR code options.

refs: https://github.com/whomwah/rqrcode
  • Loading branch information
tk0miya committed Oct 6, 2023
1 parent 8149bc3 commit 68e1b5d
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -202,3 +202,6 @@
[submodule "gems/recaptcha/5.15/_src"]
path = gems/recaptcha/5.15/_src
url = https://github.com/ambethia/recaptcha.git
[submodule "gems/rqrcode/2.2/_src"]
path = gems/rqrcode/2.2/_src
url = https://github.com/whomwah/rqrcode.git
21 changes: 21 additions & 0 deletions gems/rqrcode/2.2/_scripts/test
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env bash

# Exit command with non-zero status code, Output logs of every command executed, Treat unset variables as an error when substituting.
set -eou pipefail
# Internal Field Separator - Linux shell variable
IFS=$'\n\t'
# Print shell input lines
set -v

# Set RBS_DIR variable to change directory to execute type checks using `steep check`
RBS_DIR=$(cd $(dirname $0)/..; pwd)
# Set REPO_DIR variable to validate RBS files added to the corresponding folder
REPO_DIR=$(cd $(dirname $0)/../../..; pwd)
# Validate RBS files, using the bundler environment present
bundle exec rbs --repo $REPO_DIR -r rqrcode:2.2 -r chunky_png validate --silent

cd ${RBS_DIR}/_test
# Run type checks
bundle exec steep check

$(git rev-parse --show-toplevel)/bin/check-untyped-call.rb
1 change: 1 addition & 0 deletions gems/rqrcode/2.2/_src
Submodule _src added at 481dac
13 changes: 13 additions & 0 deletions gems/rqrcode/2.2/_test/Steepfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
D = Steep::Diagnostic

target :test do
check "."
signature "."

repo_path "../../../"
library "rqrcode"

library "chunky_png"

configure_code_diagnostics(D::Ruby.all_error)
end
47 changes: 47 additions & 0 deletions gems/rqrcode/2.2/_test/test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Write Ruby code to test the RBS.
# It is type checked by `steep check` command.

require "rqrcode"

qr = RQRCode::QRCode.new("https://kyan.com")

puts qr.to_s

qrcode = RQRCode::QRCode.new("http://github.com/")

# NOTE: showing with default options specified explicitly
svg = qrcode.as_svg(
color: "000",
shape_rendering: "crispEdges",
module_size: 11,
standalone: true,
use_path: true
)

qrcode = RQRCode::QRCode.new("http://github.com/")

# NOTE: showing with default options specified explicitly
png = qrcode.as_png(
bit_depth: 1,
border_modules: 4,
color_mode: ChunkyPNG::COLOR_GRAYSCALE,
color: "black",
file: nil,
fill: "white",
module_px_size: 6,
resize_exactly_to: false,
resize_gte_to: false,
size: 120
)

IO.binwrite("/tmp/github-qrcode.png", png.to_s)


qrcode = RQRCode::QRCode.new("http://github.com/")

# NOTE: showing with default options specified explicitly
ansi = qrcode.as_ansi(
light: "\033[47m", dark: "\033[40m",
fill_character: " ",
quiet_zone_size: 4
)
14 changes: 14 additions & 0 deletions gems/rqrcode/2.2/rqrcode.rbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module RQRCode
class QRCode
type level = :l | :m | :q | :h
type mode = :number | :alphanumeric | :byte_8bit | :kanji
type segment = { data: String, mode: mode }

def initialize: (String) -> void
def as_svg: (?offset: Integer, ?fill: String | :white | :currentColor, ?color: String | :black | :currentColor, ?module_size: Integer, ?shape_rendering: "auto" | "optimizeSpeed" | "crispEdges" | "geometricPrecision", ?standalone: bool, ?use_path: bool, ?viewbox: bool, ?svg_attributes: Hash[untyped, untyped]) -> String
def as_png: (?fill: untyped, ?color: untyped, ?size: Integer, ?border_modules: Integer, ?module_px_size: Integer, ?border: Integer, ?resize_exactly_to: bool, ?resize_gte_to: bool) -> ChunkyPNG::Image
| (file: untyped, ?fill: untyped, ?color: untyped, ?color_mode: Integer, ?bit_depth: Integer, ?interlace: bool, ?compression: untyped, ?size: Integer, ?border_modules: Integer, ?module_px_size: Integer, ?border: Integer, ?resize_exactly_to: bool, ?resize_gte_to: bool) -> ChunkyPNG::Image
def as_ansi: (?light: String, ?dark: String, ?fill_character: String, ?quiet_zone_size: Integer) -> String
def to_s: () -> String
end
end

0 comments on commit 68e1b5d

Please sign in to comment.