Skip to content

Bundle RBS files #15

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

Merged
merged 3 commits into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 5 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
source "https://rubygems.org"

gemspec

if RUBY_VERSION >= "3.0.0"
gem "rbs", "~> 3.4"
gem "rdoc"
end
10 changes: 10 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,13 @@ Rake::TestTask.new(:test) do |t|
end

task :default => :test

namespace :rbs do
desc "Update embedded RDoc comments in RBS files"
task :rdoc do
sh "rm -rf tmp/rbs/ri"
sh "mkdir -p tmp/rbs"
sh "rdoc lib --format=ri -o tmp/rbs/ri"
sh "rbs annotate --dir=tmp/rbs/ri --no-system --no-filename sig"
end
end
99 changes: 99 additions & 0 deletions sig/mutex_m.rbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
# # mutex_m.rb
#
# When 'mutex_m' is required, any object that extends or includes Mutex_m will
# be treated like a Mutex.
#
# Start by requiring the standard library Mutex_m:
#
# require "mutex_m"
#
# From here you can extend an object with Mutex instance methods:
#
# obj = Object.new
# obj.extend Mutex_m
#
# Or mixin Mutex_m into your module to your class inherit Mutex instance methods
# --- remember to call super() in your class initialize method.
#
# class Foo
# include Mutex_m
# def initialize
# # ...
# super()
# end
# # ...
# end
# obj = Foo.new
# # this obj can be handled like Mutex
#
module Mutex_m
def self.append_features: (Module cl) -> untyped

def self.define_aliases: (Module cl) -> untyped

def self.extend_object: (Object obj) -> untyped

public

def mu_extended: () -> untyped

# <!--
# - mu_lock()
# -->
# See Thread::Mutex#lock
#
def mu_lock: () -> Thread::Mutex

# <!--
# - mu_locked?()
# -->
# See Thread::Mutex#locked?
#
def mu_locked?: () -> bool

# <!--
# - mu_synchronize(&block)
# -->
# See Thread::Mutex#synchronize
#
def mu_synchronize: [T] () { () -> T } -> T

# <!--
# - mu_try_lock()
# -->
# See Thread::Mutex#try_lock
#
def mu_try_lock: () -> bool

# <!--
# - mu_unlock()
# -->
# See Thread::Mutex#unlock
#
def mu_unlock: () -> Thread::Mutex

# <!--
# - sleep(timeout = nil)
# -->
# See Thread::Mutex#sleep
#
def sleep: (?Numeric timeout) -> Integer?

alias locked? mu_locked?

alias lock mu_lock

alias unlock mu_unlock

alias try_lock mu_try_lock

alias synchronize mu_synchronize

private

def initialize: (*untyped args) -> untyped

def mu_initialize: () -> untyped
end

Mutex_m::VERSION: String
62 changes: 62 additions & 0 deletions test/test_rbs_types.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
require 'test/unit'
require 'mutex_m'
begin
require 'rbs/unit_test'
rescue LoadError
return
end

module RBSTypeTest
class Mutex_mInstanceTest < Test::Unit::TestCase
include RBS::UnitTest::TypeAssertions

library 'mutex_m'
testing "::Mutex_m"

def mu
Object.new.tap do |o|
o.extend Mutex_m
end
end

def test_mu_lock
assert_send_type "() -> Thread::Mutex",
mu, :mu_lock
end

def test_mu_locked?
mu = mu()
assert_send_type "() -> false",
mu, :mu_locked?
mu.lock
assert_send_type "() -> true",
mu, :mu_locked?
end

def test_mu_synchronize
assert_send_type "() { () -> String } -> String",
mu, :mu_synchronize do 'foo' end
end

def test_mu_try_lock
assert_send_type "() -> bool",
mu, :mu_try_lock
end

def test_mu_unlock
mu = mu()
mu.lock
assert_send_type "() -> Thread::Mutex",
mu, :mu_unlock
end

def test_sleep
mu = mu()
mu.lock
assert_send_type "(Integer) -> Integer?",
mu, :sleep, 0
assert_send_type "(Float) -> Integer?",
mu, :sleep, 0.1
end
end
end