singleton 0.1.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/dependabot.yml +6 -0
- data/.github/workflows/push_gem.yml +46 -0
- data/.github/workflows/test.yml +16 -7
- data/{LICENSE.txt → BSDL} +3 -3
- data/COPYING +56 -0
- data/lib/singleton.rb +88 -26
- data/singleton.gemspec +2 -2
- metadata +10 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e4a0824cb3d773a47e6253026f7ed1a64838b6d83318e6c30632c9257fc1f7e7
|
4
|
+
data.tar.gz: 36a4eafc00c5cfa9d96d25fe73ec99631d47f0a37354aa65d671ca29f3ee033a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ee3e7eda2525837a6019328e6fa27b5745090737952b16c538d5702f74d9146d47d8d634787689dfcf5d9fb108570ac5218e518522eca4bc01b150ce4d6c253b
|
7
|
+
data.tar.gz: b2a588e68ae7bf836ff14de1c849f6c0fb7d1af0408174cb6d4ec0023e500f0f1fa348fc1d87d4142f455f0417ce4baafe7664f2510e420a53bf2a82d2eda056
|
@@ -0,0 +1,46 @@
|
|
1
|
+
name: Publish gem to rubygems.org
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
tags:
|
6
|
+
- 'v*'
|
7
|
+
|
8
|
+
permissions:
|
9
|
+
contents: read
|
10
|
+
|
11
|
+
jobs:
|
12
|
+
push:
|
13
|
+
if: github.repository == 'ruby/singleton'
|
14
|
+
runs-on: ubuntu-latest
|
15
|
+
|
16
|
+
environment:
|
17
|
+
name: rubygems.org
|
18
|
+
url: https://rubygems.org/gems/singleton
|
19
|
+
|
20
|
+
permissions:
|
21
|
+
contents: write
|
22
|
+
id-token: write
|
23
|
+
|
24
|
+
steps:
|
25
|
+
- name: Harden Runner
|
26
|
+
uses: step-security/harden-runner@91182cccc01eb5e619899d80e4e971d6181294a7 # v2.10.1
|
27
|
+
with:
|
28
|
+
egress-policy: audit
|
29
|
+
|
30
|
+
- uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4
|
31
|
+
|
32
|
+
- name: Set up Ruby
|
33
|
+
uses: ruby/setup-ruby@a6e6f86333f0a2523ece813039b8b4be04560854 # v1.190.0
|
34
|
+
with:
|
35
|
+
bundler-cache: true
|
36
|
+
ruby-version: ruby
|
37
|
+
|
38
|
+
- name: Publish to RubyGems
|
39
|
+
uses: rubygems/release-gem@612653d273a73bdae1df8453e090060bb4db5f31 # v1
|
40
|
+
|
41
|
+
- name: Create GitHub release
|
42
|
+
run: |
|
43
|
+
tag_name="$(git describe --tags --abbrev=0)"
|
44
|
+
gh release create "${tag_name}" --verify-tag --generate-notes
|
45
|
+
env:
|
46
|
+
GITHUB_TOKEN: ${{ secrets.MATZBOT_GITHUB_WORKFLOW_TOKEN }}
|
data/.github/workflows/test.yml
CHANGED
@@ -3,22 +3,31 @@ name: test
|
|
3
3
|
on: [push, pull_request]
|
4
4
|
|
5
5
|
jobs:
|
6
|
-
|
6
|
+
ruby-versions:
|
7
|
+
uses: ruby/actions/.github/workflows/ruby_versions.yml@master
|
8
|
+
with:
|
9
|
+
min_version: 2.4
|
10
|
+
test:
|
11
|
+
needs: ruby-versions
|
7
12
|
name: build (${{ matrix.ruby }} / ${{ matrix.os }})
|
8
13
|
strategy:
|
14
|
+
fail-fast: false
|
9
15
|
matrix:
|
10
|
-
ruby:
|
11
|
-
os: [ ubuntu-latest, macos-latest ]
|
16
|
+
ruby: ${{ fromJson(needs.ruby-versions.outputs.versions) }}
|
17
|
+
os: [ ubuntu-latest, macos-latest, windows-latest ]
|
18
|
+
exclude:
|
19
|
+
- { os: macos-latest, ruby: 2.4 }
|
20
|
+
- { os: macos-latest, ruby: 2.5 }
|
21
|
+
- { os: windows-latest, ruby: truffleruby }
|
22
|
+
- { os: windows-latest, ruby: truffleruby-head }
|
12
23
|
runs-on: ${{ matrix.os }}
|
13
24
|
steps:
|
14
|
-
- uses: actions/checkout@
|
25
|
+
- uses: actions/checkout@v4
|
15
26
|
- name: Set up Ruby
|
16
27
|
uses: ruby/setup-ruby@v1
|
17
28
|
with:
|
18
29
|
ruby-version: ${{ matrix.ruby }}
|
19
30
|
- name: Install dependencies
|
20
|
-
run:
|
21
|
-
gem install bundler --no-document
|
22
|
-
bundle install
|
31
|
+
run: bundle install
|
23
32
|
- name: Run test
|
24
33
|
run: rake test
|
data/{LICENSE.txt → BSDL}
RENAMED
@@ -4,10 +4,10 @@ Redistribution and use in source and binary forms, with or without
|
|
4
4
|
modification, are permitted provided that the following conditions
|
5
5
|
are met:
|
6
6
|
1. Redistributions of source code must retain the above copyright
|
7
|
-
notice, this list of conditions and the following disclaimer.
|
7
|
+
notice, this list of conditions and the following disclaimer.
|
8
8
|
2. Redistributions in binary form must reproduce the above copyright
|
9
|
-
notice, this list of conditions and the following disclaimer in the
|
10
|
-
documentation and/or other materials provided with the distribution.
|
9
|
+
notice, this list of conditions and the following disclaimer in the
|
10
|
+
documentation and/or other materials provided with the distribution.
|
11
11
|
|
12
12
|
THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
13
13
|
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
data/COPYING
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
Ruby is copyrighted free software by Yukihiro Matsumoto <matz@netlab.jp>.
|
2
|
+
You can redistribute it and/or modify it under either the terms of the
|
3
|
+
2-clause BSDL (see the file BSDL), or the conditions below:
|
4
|
+
|
5
|
+
1. You may make and give away verbatim copies of the source form of the
|
6
|
+
software without restriction, provided that you duplicate all of the
|
7
|
+
original copyright notices and associated disclaimers.
|
8
|
+
|
9
|
+
2. You may modify your copy of the software in any way, provided that
|
10
|
+
you do at least ONE of the following:
|
11
|
+
|
12
|
+
a. place your modifications in the Public Domain or otherwise
|
13
|
+
make them Freely Available, such as by posting said
|
14
|
+
modifications to Usenet or an equivalent medium, or by allowing
|
15
|
+
the author to include your modifications in the software.
|
16
|
+
|
17
|
+
b. use the modified software only within your corporation or
|
18
|
+
organization.
|
19
|
+
|
20
|
+
c. give non-standard binaries non-standard names, with
|
21
|
+
instructions on where to get the original software distribution.
|
22
|
+
|
23
|
+
d. make other distribution arrangements with the author.
|
24
|
+
|
25
|
+
3. You may distribute the software in object code or binary form,
|
26
|
+
provided that you do at least ONE of the following:
|
27
|
+
|
28
|
+
a. distribute the binaries and library files of the software,
|
29
|
+
together with instructions (in the manual page or equivalent)
|
30
|
+
on where to get the original distribution.
|
31
|
+
|
32
|
+
b. accompany the distribution with the machine-readable source of
|
33
|
+
the software.
|
34
|
+
|
35
|
+
c. give non-standard binaries non-standard names, with
|
36
|
+
instructions on where to get the original software distribution.
|
37
|
+
|
38
|
+
d. make other distribution arrangements with the author.
|
39
|
+
|
40
|
+
4. You may modify and include the part of the software into any other
|
41
|
+
software (possibly commercial). But some files in the distribution
|
42
|
+
are not written by the author, so that they are not under these terms.
|
43
|
+
|
44
|
+
For the list of those files and their copying conditions, see the
|
45
|
+
file LEGAL.
|
46
|
+
|
47
|
+
5. The scripts and library files supplied as input to or produced as
|
48
|
+
output from the software do not automatically fall under the
|
49
|
+
copyright of the software, but belong to whomever generated them,
|
50
|
+
and may be sold commercially, and may be aggregated with this
|
51
|
+
software.
|
52
|
+
|
53
|
+
6. THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
|
54
|
+
IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
55
|
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
56
|
+
PURPOSE.
|
data/lib/singleton.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# frozen_string_literal:
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
3
|
# The Singleton module implements the Singleton pattern.
|
4
4
|
#
|
@@ -92,22 +92,25 @@
|
|
92
92
|
# p a.strip # => nil
|
93
93
|
#
|
94
94
|
module Singleton
|
95
|
-
VERSION = "0.
|
95
|
+
VERSION = "0.3.0"
|
96
96
|
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
97
|
+
module SingletonInstanceMethods
|
98
|
+
# Raises a TypeError to prevent cloning.
|
99
|
+
def clone
|
100
|
+
raise TypeError, "can't clone instance of singleton #{self.class}"
|
101
|
+
end
|
101
102
|
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
103
|
+
# Raises a TypeError to prevent duping.
|
104
|
+
def dup
|
105
|
+
raise TypeError, "can't dup instance of singleton #{self.class}"
|
106
|
+
end
|
106
107
|
|
107
|
-
|
108
|
-
|
109
|
-
|
108
|
+
# By default, do not retain any state when marshalling.
|
109
|
+
def _dump(depth = -1)
|
110
|
+
''
|
111
|
+
end
|
110
112
|
end
|
113
|
+
include SingletonInstanceMethods
|
111
114
|
|
112
115
|
module SingletonClassMethods # :nodoc:
|
113
116
|
|
@@ -121,12 +124,7 @@ module Singleton
|
|
121
124
|
end
|
122
125
|
|
123
126
|
def instance # :nodoc:
|
124
|
-
|
125
|
-
@singleton__mutex__.synchronize {
|
126
|
-
return @singleton__instance__ if @singleton__instance__
|
127
|
-
@singleton__instance__ = new()
|
128
|
-
}
|
129
|
-
@singleton__instance__
|
127
|
+
@singleton__instance__ || @singleton__mutex__.synchronize { @singleton__instance__ ||= new }
|
130
128
|
end
|
131
129
|
|
132
130
|
private
|
@@ -135,22 +133,42 @@ module Singleton
|
|
135
133
|
super
|
136
134
|
Singleton.__init__(sub_klass)
|
137
135
|
end
|
136
|
+
|
137
|
+
def set_instance(val)
|
138
|
+
@singleton__instance__ = val
|
139
|
+
end
|
140
|
+
|
141
|
+
def set_mutex(val)
|
142
|
+
@singleton__mutex__ = val
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
def self.module_with_class_methods
|
147
|
+
SingletonClassMethods
|
138
148
|
end
|
139
149
|
|
140
|
-
|
150
|
+
module SingletonClassProperties
|
151
|
+
|
152
|
+
def self.included(c)
|
153
|
+
# extending an object with Singleton is a bad idea
|
154
|
+
c.undef_method :extend_object
|
155
|
+
end
|
156
|
+
|
157
|
+
def self.extended(c)
|
158
|
+
# extending an object with Singleton is a bad idea
|
159
|
+
c.singleton_class.send(:undef_method, :extend_object)
|
160
|
+
end
|
161
|
+
|
141
162
|
def __init__(klass) # :nodoc:
|
142
163
|
klass.instance_eval {
|
143
|
-
|
144
|
-
|
164
|
+
set_instance(nil)
|
165
|
+
set_mutex(Thread::Mutex.new)
|
145
166
|
}
|
146
167
|
klass
|
147
168
|
end
|
148
169
|
|
149
170
|
private
|
150
171
|
|
151
|
-
# extending an object with Singleton is a bad idea
|
152
|
-
undef_method :extend_object
|
153
|
-
|
154
172
|
def append_features(mod)
|
155
173
|
# help out people counting on transitive mixins
|
156
174
|
unless mod.instance_of?(Class)
|
@@ -162,10 +180,11 @@ module Singleton
|
|
162
180
|
def included(klass)
|
163
181
|
super
|
164
182
|
klass.private_class_method :new, :allocate
|
165
|
-
klass.extend
|
183
|
+
klass.extend module_with_class_methods
|
166
184
|
Singleton.__init__(klass)
|
167
185
|
end
|
168
186
|
end
|
187
|
+
extend SingletonClassProperties
|
169
188
|
|
170
189
|
##
|
171
190
|
# :singleton-method: _load
|
@@ -175,3 +194,46 @@ module Singleton
|
|
175
194
|
# :singleton-method: instance
|
176
195
|
# Returns the singleton instance.
|
177
196
|
end
|
197
|
+
|
198
|
+
if defined?(Ractor)
|
199
|
+
module RactorLocalSingleton
|
200
|
+
include Singleton::SingletonInstanceMethods
|
201
|
+
|
202
|
+
module RactorLocalSingletonClassMethods
|
203
|
+
include Singleton::SingletonClassMethods
|
204
|
+
def instance
|
205
|
+
set_mutex(Thread::Mutex.new) if Ractor.current[mutex_key].nil?
|
206
|
+
return Ractor.current[instance_key] if Ractor.current[instance_key]
|
207
|
+
Ractor.current[mutex_key].synchronize {
|
208
|
+
return Ractor.current[instance_key] if Ractor.current[instance_key]
|
209
|
+
set_instance(new())
|
210
|
+
}
|
211
|
+
Ractor.current[instance_key]
|
212
|
+
end
|
213
|
+
|
214
|
+
private
|
215
|
+
|
216
|
+
def instance_key
|
217
|
+
:"__RactorLocalSingleton_instance_with_class_id_#{object_id}__"
|
218
|
+
end
|
219
|
+
|
220
|
+
def mutex_key
|
221
|
+
:"__RactorLocalSingleton_mutex_with_class_id_#{object_id}__"
|
222
|
+
end
|
223
|
+
|
224
|
+
def set_instance(val)
|
225
|
+
Ractor.current[instance_key] = val
|
226
|
+
end
|
227
|
+
|
228
|
+
def set_mutex(val)
|
229
|
+
Ractor.current[mutex_key] = val
|
230
|
+
end
|
231
|
+
end
|
232
|
+
|
233
|
+
def self.module_with_class_methods
|
234
|
+
RactorLocalSingletonClassMethods
|
235
|
+
end
|
236
|
+
|
237
|
+
extend Singleton::SingletonClassProperties
|
238
|
+
end
|
239
|
+
end
|
data/singleton.gemspec
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
name = File.basename(__FILE__, ".gemspec")
|
4
|
-
version = ["lib", Array.new(name.count("-")+1, "
|
4
|
+
version = ["lib", Array.new(name.count("-")+1, ".").join("/")].find do |dir|
|
5
5
|
break File.foreach(File.join(__dir__, dir, "#{name.tr('-', '/')}.rb")) do |line|
|
6
6
|
/^\s*VERSION\s*=\s*"(.*)"/ =~ line and break $1
|
7
7
|
end rescue nil
|
@@ -22,7 +22,7 @@ Gem::Specification.new do |spec|
|
|
22
22
|
spec.metadata["source_code_uri"] = spec.homepage
|
23
23
|
|
24
24
|
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
25
|
-
`git ls-files -z 2
|
25
|
+
`git ls-files -z 2>#{IO::NULL}`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
26
26
|
end
|
27
27
|
spec.bindir = "exe"
|
28
28
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: singleton
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yukihiro Matsumoto
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-11-08 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: The Singleton module implements the Singleton pattern.
|
14
14
|
email:
|
@@ -17,10 +17,13 @@ executables: []
|
|
17
17
|
extensions: []
|
18
18
|
extra_rdoc_files: []
|
19
19
|
files:
|
20
|
+
- ".github/dependabot.yml"
|
21
|
+
- ".github/workflows/push_gem.yml"
|
20
22
|
- ".github/workflows/test.yml"
|
21
23
|
- ".gitignore"
|
24
|
+
- BSDL
|
25
|
+
- COPYING
|
22
26
|
- Gemfile
|
23
|
-
- LICENSE.txt
|
24
27
|
- README.md
|
25
28
|
- Rakefile
|
26
29
|
- bin/console
|
@@ -34,7 +37,7 @@ licenses:
|
|
34
37
|
metadata:
|
35
38
|
homepage_uri: https://github.com/ruby/singleton
|
36
39
|
source_code_uri: https://github.com/ruby/singleton
|
37
|
-
post_install_message:
|
40
|
+
post_install_message:
|
38
41
|
rdoc_options: []
|
39
42
|
require_paths:
|
40
43
|
- lib
|
@@ -49,8 +52,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
49
52
|
- !ruby/object:Gem::Version
|
50
53
|
version: '0'
|
51
54
|
requirements: []
|
52
|
-
rubygems_version: 3.
|
53
|
-
signing_key:
|
55
|
+
rubygems_version: 3.5.11
|
56
|
+
signing_key:
|
54
57
|
specification_version: 4
|
55
58
|
summary: The Singleton module implements the Singleton pattern.
|
56
59
|
test_files: []
|