From d71d0522e822cba8c76e7d1aec5605ead83cc909 Mon Sep 17 00:00:00 2001 From: Hiroshi SHIBATA Date: Fri, 25 Mar 2022 16:24:42 +0900 Subject: [PATCH 01/13] Added dependabot --- .github/dependabot.yml | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .github/dependabot.yml diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..b18fd29 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,6 @@ +version: 2 +updates: + - package-ecosystem: 'github-actions' + directory: '/' + schedule: + interval: 'weekly' From 2046ed2caaba04bef6844f445d205c8f42821e0c Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 25 Mar 2022 07:43:59 +0000 Subject: [PATCH 02/13] Bump actions/checkout from 2 to 3 Bumps [actions/checkout](https://github.com/actions/checkout) from 2 to 3. - [Release notes](https://github.com/actions/checkout/releases) - [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md) - [Commits](https://github.com/actions/checkout/compare/v2...v3) --- updated-dependencies: - dependency-name: actions/checkout dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 1972bee..287a3bd 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -11,7 +11,7 @@ jobs: os: [ ubuntu-latest, macos-latest ] runs-on: ${{ matrix.os }} steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Set up Ruby uses: ruby/setup-ruby@v1 with: From d1bfcba0258d199cf98f33bff9775818be1b8d1b Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Fri, 5 May 2023 18:32:13 +0900 Subject: [PATCH 03/13] Redirect to `IO::NULL` for the portability --- singleton.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/singleton.gemspec b/singleton.gemspec index 88d3111..05d3296 100644 --- a/singleton.gemspec +++ b/singleton.gemspec @@ -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) } From 5fc357d0e8dd0188b45254c0232d2e3ae961eace Mon Sep 17 00:00:00 2001 From: Daniel Pepper Date: Fri, 2 Jun 2023 08:08:36 -0700 Subject: [PATCH 04/13] ruby version testing --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 287a3bd..c8a890c 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -7,7 +7,7 @@ jobs: name: build (${{ matrix.ruby }} / ${{ matrix.os }}) strategy: matrix: - ruby: [ 2.7, 2.6, 2.5, 2.4, head ] + ruby: [ 3.2, 3.1, 3.0, 2.7, head ] os: [ ubuntu-latest, macos-latest ] runs-on: ${{ matrix.os }} steps: From 545b6b61a40d4962cf376085497b197c1486bd23 Mon Sep 17 00:00:00 2001 From: Daniel Pepper Date: Fri, 2 Jun 2023 17:35:11 -0700 Subject: [PATCH 05/13] Simplify the implementation (#7) Remove `__init__` and move logic to `included`. --- lib/singleton.rb | 26 +++++++++----------------- test/test_singleton.rb | 11 +++++++++++ 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/lib/singleton.rb b/lib/singleton.rb index 07420d2..757b77e 100644 --- a/lib/singleton.rb +++ b/lib/singleton.rb @@ -112,7 +112,7 @@ def _dump(depth = -1) module SingletonClassMethods # :nodoc: def clone # :nodoc: - Singleton.__init__(super) + super.include(Singleton) end # By default calls instance(). Override to retain singleton state. @@ -121,31 +121,18 @@ def _load(str) end def instance # :nodoc: - return @singleton__instance__ if @singleton__instance__ - @singleton__mutex__.synchronize { - return @singleton__instance__ if @singleton__instance__ - @singleton__instance__ = new() - } - @singleton__instance__ + @singleton__instance__ || @singleton__mutex__.synchronize { @singleton__instance__ ||= new } end private def inherited(sub_klass) super - Singleton.__init__(sub_klass) + sub_klass.include(Singleton) end end class << Singleton # :nodoc: - def __init__(klass) # :nodoc: - klass.instance_eval { - @singleton__instance__ = nil - @singleton__mutex__ = Thread::Mutex.new - } - klass - end - private # extending an object with Singleton is a bad idea @@ -156,14 +143,19 @@ def append_features(mod) unless mod.instance_of?(Class) raise TypeError, "Inclusion of the OO-Singleton module in module #{mod}" end + super end def included(klass) super + klass.private_class_method :new, :allocate klass.extend SingletonClassMethods - Singleton.__init__(klass) + klass.instance_eval { + @singleton__instance__ = nil + @singleton__mutex__ = Thread::Mutex.new + } end end diff --git a/test/test_singleton.rb b/test/test_singleton.rb index b3c48bb..b08972b 100644 --- a/test/test_singleton.rb +++ b/test/test_singleton.rb @@ -94,6 +94,13 @@ 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_class_level_cloning_preserves_singleton_behavior klass = SingletonTest.clone @@ -101,4 +108,8 @@ def test_class_level_cloning_preserves_singleton_behavior 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 From fa8379eb4c1c61a39c6f0fb6b2d6c9281b71792a Mon Sep 17 00:00:00 2001 From: Daniel Pepper Date: Sat, 3 Jun 2023 09:22:22 -0700 Subject: [PATCH 06/13] expand testing --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index c8a890c..c96783e 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -7,7 +7,7 @@ jobs: name: build (${{ matrix.ruby }} / ${{ matrix.os }}) strategy: matrix: - ruby: [ 3.2, 3.1, 3.0, 2.7, head ] + ruby: [ 3.2, 3.1, 3.0, 2.7, 2.6, 2.5, 2.4, head ] os: [ ubuntu-latest, macos-latest ] runs-on: ${{ matrix.os }} steps: From 911531d508fff36877cdf9242dd6fd0310716629 Mon Sep 17 00:00:00 2001 From: Hiroshi SHIBATA Date: Mon, 5 Jun 2023 10:09:52 +0900 Subject: [PATCH 07/13] Revert "Simplify the implementation (#7)" This reverts commit 545b6b61a40d4962cf376085497b197c1486bd23. This change break Rails CI: https://bugs.ruby-lang.org/issues/19711 --- lib/singleton.rb | 26 +++++++++++++++++--------- test/test_singleton.rb | 11 ----------- 2 files changed, 17 insertions(+), 20 deletions(-) diff --git a/lib/singleton.rb b/lib/singleton.rb index 757b77e..07420d2 100644 --- a/lib/singleton.rb +++ b/lib/singleton.rb @@ -112,7 +112,7 @@ def _dump(depth = -1) module SingletonClassMethods # :nodoc: def clone # :nodoc: - super.include(Singleton) + Singleton.__init__(super) end # By default calls instance(). Override to retain singleton state. @@ -121,18 +121,31 @@ def _load(str) end def instance # :nodoc: - @singleton__instance__ || @singleton__mutex__.synchronize { @singleton__instance__ ||= new } + return @singleton__instance__ if @singleton__instance__ + @singleton__mutex__.synchronize { + return @singleton__instance__ if @singleton__instance__ + @singleton__instance__ = new() + } + @singleton__instance__ end private def inherited(sub_klass) super - sub_klass.include(Singleton) + Singleton.__init__(sub_klass) end end class << Singleton # :nodoc: + def __init__(klass) # :nodoc: + klass.instance_eval { + @singleton__instance__ = nil + @singleton__mutex__ = Thread::Mutex.new + } + klass + end + private # extending an object with Singleton is a bad idea @@ -143,19 +156,14 @@ def append_features(mod) unless mod.instance_of?(Class) raise TypeError, "Inclusion of the OO-Singleton module in module #{mod}" end - super end def included(klass) super - klass.private_class_method :new, :allocate klass.extend SingletonClassMethods - klass.instance_eval { - @singleton__instance__ = nil - @singleton__mutex__ = Thread::Mutex.new - } + Singleton.__init__(klass) end end diff --git a/test/test_singleton.rb b/test/test_singleton.rb index b08972b..b3c48bb 100644 --- a/test/test_singleton.rb +++ b/test/test_singleton.rb @@ -94,13 +94,6 @@ 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_class_level_cloning_preserves_singleton_behavior klass = SingletonTest.clone @@ -108,8 +101,4 @@ def test_class_level_cloning_preserves_singleton_behavior 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 From a67bf24954c7da84148676c6a3d72d5b3b7ca1ea Mon Sep 17 00:00:00 2001 From: Daniel Pepper Date: Sun, 4 Jun 2023 21:29:32 -0700 Subject: [PATCH 08/13] Simplify implementation of `Singleton#instance`. (#9) - Add more tests to cover rails' usage. --- lib/singleton.rb | 7 +------ test/test_singleton.rb | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/lib/singleton.rb b/lib/singleton.rb index 07420d2..7ed17a7 100644 --- a/lib/singleton.rb +++ b/lib/singleton.rb @@ -121,12 +121,7 @@ def _load(str) end def instance # :nodoc: - return @singleton__instance__ if @singleton__instance__ - @singleton__mutex__.synchronize { - return @singleton__instance__ if @singleton__instance__ - @singleton__instance__ = new() - } - @singleton__instance__ + @singleton__instance__ || @singleton__mutex__.synchronize { @singleton__instance__ ||= new } end private diff --git a/test/test_singleton.rb b/test/test_singleton.rb index b3c48bb..e474a0c 100644 --- a/test/test_singleton.rb +++ b/test/test_singleton.rb @@ -94,6 +94,23 @@ 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 @@ -101,4 +118,8 @@ def test_class_level_cloning_preserves_singleton_behavior 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 From 6d734dd6d9fd6e33eafe77d192367b0b8492870a Mon Sep 17 00:00:00 2001 From: Hiroshi SHIBATA Date: Mon, 5 Jun 2023 14:52:58 +0900 Subject: [PATCH 09/13] Use reusing workflow for all tested versions --- .github/workflows/test.yml | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index c96783e..4151a43 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -3,11 +3,17 @@ 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: [ 3.2, 3.1, 3.0, 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: From 2291537692017eb78319496bfee9553333499231 Mon Sep 17 00:00:00 2001 From: Hiroshi SHIBATA Date: Thu, 25 May 2023 15:47:48 +0900 Subject: [PATCH 10/13] Move gemspec files to top of lib directory. They have version.rb files with same directory. But version.rb have been removed at https://github.com/ruby/ruby/pull/3375 There is no reason to locate under the library name of directory. --- singleton.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/singleton.gemspec b/singleton.gemspec index 05d3296..7646914 100644 --- a/singleton.gemspec +++ b/singleton.gemspec @@ -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 From 087d2de84a07e177a90e545fe7c4ae6f1192a759 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 4 Sep 2023 13:03:43 +0000 Subject: [PATCH 11/13] Bump actions/checkout from 3 to 4 Bumps [actions/checkout](https://github.com/actions/checkout) from 3 to 4. - [Release notes](https://github.com/actions/checkout/releases) - [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md) - [Commits](https://github.com/actions/checkout/compare/v3...v4) --- updated-dependencies: - dependency-name: actions/checkout dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 4151a43..eb03e35 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -17,7 +17,7 @@ jobs: os: [ ubuntu-latest, macos-latest ] runs-on: ${{ matrix.os }} steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Set up Ruby uses: ruby/setup-ruby@v1 with: From 3c7fb5f258955faf2458e9e70e5129bbcebb0059 Mon Sep 17 00:00:00 2001 From: Hiroshi SHIBATA Date: Mon, 6 Nov 2023 18:43:52 +0900 Subject: [PATCH 12/13] Bump up 0.2.0 --- lib/singleton.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/singleton.rb b/lib/singleton.rb index 7ed17a7..6da9391 100644 --- a/lib/singleton.rb +++ b/lib/singleton.rb @@ -92,7 +92,7 @@ # p a.strip # => nil # module Singleton - VERSION = "0.1.1" + VERSION = "0.2.0" # Raises a TypeError to prevent cloning. def clone From 23bd52edee0871d702fc885e7f6054d99168a522 Mon Sep 17 00:00:00 2001 From: Hiroshi SHIBATA Date: Tue, 1 Oct 2024 16:54:37 +0900 Subject: [PATCH 13/13] Update license files same as ruby/ruby --- LICENSE.txt => BSDL | 6 ++--- COPYING | 56 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 3 deletions(-) rename LICENSE.txt => BSDL (83%) create mode 100644 COPYING diff --git a/LICENSE.txt b/BSDL similarity index 83% rename from LICENSE.txt rename to BSDL index a009cae..66d9359 100644 --- a/LICENSE.txt +++ b/BSDL @@ -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 diff --git a/COPYING b/COPYING new file mode 100644 index 0000000..48e5a96 --- /dev/null +++ b/COPYING @@ -0,0 +1,56 @@ +Ruby is copyrighted free software by Yukihiro Matsumoto . +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.