Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
hsbt authored Oct 1, 2024
2 parents 3960354 + 23bd52e commit 3615d06
Show file tree
Hide file tree
Showing 7 changed files with 99 additions and 15 deletions.
6 changes: 6 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version: 2
updates:
- package-ecosystem: 'github-actions'
directory: '/'
schedule:
interval: 'weekly'
12 changes: 9 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,21 @@ name: test
on: [push, pull_request]

jobs:
build:
ruby-versions:
uses: ruby/actions/.github/workflows/ruby_versions.yml@master
with:
engine: cruby
min_version: 2.4
test:
needs: ruby-versions
name: build (${{ matrix.ruby }} / ${{ matrix.os }})
strategy:
matrix:
ruby: [ 2.7, 2.6, 2.5, 2.4, head ]
ruby: ${{ fromJson(needs.ruby-versions.outputs.versions) }}
os: [ ubuntu-latest, macos-latest ]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
Expand Down
6 changes: 3 additions & 3 deletions LICENSE.txt → BSDL
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
Expand Down
56 changes: 56 additions & 0 deletions COPYING
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
Ruby is copyrighted free software by Yukihiro Matsumoto <[email protected]>.
You can redistribute it and/or modify it under either the terms of the
2-clause BSDL (see the file BSDL), or the conditions below:

1. You may make and give away verbatim copies of the source form of the
software without restriction, provided that you duplicate all of the
original copyright notices and associated disclaimers.

2. You may modify your copy of the software in any way, provided that
you do at least ONE of the following:

a. place your modifications in the Public Domain or otherwise
make them Freely Available, such as by posting said
modifications to Usenet or an equivalent medium, or by allowing
the author to include your modifications in the software.

b. use the modified software only within your corporation or
organization.

c. give non-standard binaries non-standard names, with
instructions on where to get the original software distribution.

d. make other distribution arrangements with the author.

3. You may distribute the software in object code or binary form,
provided that you do at least ONE of the following:

a. distribute the binaries and library files of the software,
together with instructions (in the manual page or equivalent)
on where to get the original distribution.

b. accompany the distribution with the machine-readable source of
the software.

c. give non-standard binaries non-standard names, with
instructions on where to get the original software distribution.

d. make other distribution arrangements with the author.

4. You may modify and include the part of the software into any other
software (possibly commercial). But some files in the distribution
are not written by the author, so that they are not under these terms.

For the list of those files and their copying conditions, see the
file LEGAL.

5. The scripts and library files supplied as input to or produced as
output from the software do not automatically fall under the
copyright of the software, but belong to whomever generated them,
and may be sold commercially, and may be aggregated with this
software.

6. THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE.
9 changes: 2 additions & 7 deletions lib/singleton.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
# p a.strip # => nil
#
module Singleton
VERSION = "0.1.1"
VERSION = "0.2.0"

module SingletonInstanceMethods
# Raises a TypeError to prevent cloning.
Expand Down Expand Up @@ -124,12 +124,7 @@ def _load(str)
end

def instance # :nodoc:
return @singleton__instance__ if @singleton__instance__
@singleton__mutex__.synchronize {
return @singleton__instance__ if @singleton__instance__
set_instance(new())
}
@singleton__instance__
@singleton__instance__ || @singleton__mutex__.synchronize { @singleton__instance__ ||= set_instance(new) }
end

private
Expand Down
4 changes: 2 additions & 2 deletions singleton.gemspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

name = File.basename(__FILE__, ".gemspec")
version = ["lib", Array.new(name.count("-")+1, "..").join("/")].find do |dir|
version = ["lib", Array.new(name.count("-")+1, ".").join("/")].find do |dir|
break File.foreach(File.join(__dir__, dir, "#{name.tr('-', '/')}.rb")) do |line|
/^\s*VERSION\s*=\s*"(.*)"/ =~ line and break $1
end rescue nil
Expand All @@ -22,7 +22,7 @@ Gem::Specification.new do |spec|
spec.metadata["source_code_uri"] = spec.homepage

spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
`git ls-files -z 2>/dev/null`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
`git ls-files -z 2>#{IO::NULL}`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
end
spec.bindir = "exe"
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
Expand Down
21 changes: 21 additions & 0 deletions test/test_singleton.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,32 @@ def test_inheritance_works_with_overridden_inherited_method
assert_same a, b
end

def test_inheritance_creates_separate_singleton
a = SingletonTest.instance
b = Class.new(SingletonTest).instance

assert_not_same a, b
end

def test_inheritance_instantiation
klass = Class.new do
include Singleton

public_class_method :new
end

assert Class.new(klass).new
end

def test_class_level_cloning_preserves_singleton_behavior
klass = SingletonTest.clone

a = klass.instance
b = klass.instance
assert_same a, b
end

def test_class_level_cloning_creates_separate_singleton
assert_not_same SingletonTest.instance, SingletonTest.clone.instance
end
end

0 comments on commit 3615d06

Please sign in to comment.