ProtectedConstructor 1.0.5 → 2.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +19 -16
- data/.rspec +3 -0
- data/.ruby-version +1 -0
- data/CHANGELOG.md +8 -0
- data/Gemfile +2 -5
- data/Gemfile.lock +87 -0
- data/ProtectedConstructor.gemspec +27 -13
- data/README.md +10 -2
- data/Rakefile +6 -4
- data/lib/ProtectedConstructor/version.rb +3 -1
- data/lib/ProtectedConstructor.rb +3 -7
- data/spec/ProtectedConstructor/protected_constructor_spec.rb +58 -16
- data/spec/spec_helper.rb +22 -3
- data/spec/support/shared_klasses/klass_factory.rb +18 -0
- data/spec/support/shared_klasses/klass_factory_two.rb +20 -0
- metadata +177 -45
- data/.idea/.name +0 -1
- data/.idea/.rakeTasks +0 -7
- data/.idea/ProtectedConstructor.iml +0 -20
- data/.idea/encodings.xml +0 -5
- data/.idea/misc.xml +0 -5
- data/.idea/modules.xml +0 -9
- data/.idea/runConfigurations/Start_Yard_Server.xml +0 -26
- data/.idea/scopes/scope_settings.xml +0 -5
- data/.idea/vcs.xml +0 -7
- data/.idea/workspace.xml +0 -606
- data/.rbenv-version +0 -1
- data/projectFilesBackup/.idea/ProtectedConstructor.iml +0 -11
- data/spec/klass.rb +0 -13
- data/spec/klass_factory.rb +0 -10
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 53f567997f4b0dbb923f554f7dd6973dee4f4999230a47aea69d9f0a09c499b3
|
4
|
+
data.tar.gz: 891ec0d8e75293a47681ccb773b22ba183dbde1559474045cab0c68995d29583
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ff08b1c8a2b89ba5ffca832c58ccb48bf285184b8335389a268686a43386c8cf240dbda7d9c50f97236cc501b75d330296c0504a57a0b9eda38578e61fb68519
|
7
|
+
data.tar.gz: a46b096ec35339cc68ce643ebdb7d56e9baf649941fbbda9d51552d805307b0d35d8e3c47027abb679932a65197c6a13f63edfd490f53fcced24ea9eb08d343b
|
data/.gitignore
CHANGED
@@ -1,17 +1,20 @@
|
|
1
|
+
/.bundle/
|
2
|
+
/.yardoc
|
3
|
+
/_yardoc/
|
4
|
+
/coverage/
|
5
|
+
/doc/
|
6
|
+
/pkg/
|
7
|
+
/spec/reports/
|
8
|
+
/tmp/
|
9
|
+
|
10
|
+
/rdoc/
|
1
11
|
*.gem
|
2
|
-
|
3
|
-
|
4
|
-
.
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
lib/bundler/man
|
12
|
-
pkg
|
13
|
-
rdoc
|
14
|
-
spec/reports
|
15
|
-
test/tmp
|
16
|
-
test/version_tmp
|
17
|
-
tmp
|
12
|
+
|
13
|
+
# rspec failure tracking
|
14
|
+
.rspec_status
|
15
|
+
|
16
|
+
/.vscode/
|
17
|
+
*.code-workspace
|
18
|
+
|
19
|
+
scratch.rb
|
20
|
+
readme.txt
|
data/.rspec
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
3.0.1
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
### 2.1.3
|
2
|
+
* changes
|
3
|
+
* Required Ruby version is now 3.0.1.
|
4
|
+
### 2.0.3
|
5
|
+
* changes
|
6
|
+
* Clean up ProtectedConstructor call to module_eval of unnecessary code.
|
7
|
+
* Update gems and especially rake gem version to patch redcarpet CVE-2020-26298, yard CVE-2017-17042 and CVE-2019-1020001.
|
8
|
+
* Fix rubocop violations.
|
data/Gemfile
CHANGED
data/Gemfile.lock
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
ProtectedConstructor (2.1.3)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
ast (2.4.2)
|
10
|
+
byebug (11.1.3)
|
11
|
+
coderay (1.1.3)
|
12
|
+
diff-lcs (1.5.0)
|
13
|
+
json (2.6.2)
|
14
|
+
kwalify (0.7.2)
|
15
|
+
method_source (1.0.0)
|
16
|
+
parallel (1.22.1)
|
17
|
+
parser (3.1.2.1)
|
18
|
+
ast (~> 2.4.1)
|
19
|
+
pry (0.14.1)
|
20
|
+
coderay (~> 1.1)
|
21
|
+
method_source (~> 1.0)
|
22
|
+
pry-byebug (3.10.1)
|
23
|
+
byebug (~> 11.0)
|
24
|
+
pry (>= 0.13, < 0.15)
|
25
|
+
rainbow (3.1.1)
|
26
|
+
rake (13.0.6)
|
27
|
+
redcarpet (3.5.1)
|
28
|
+
reek (6.1.1)
|
29
|
+
kwalify (~> 0.7.0)
|
30
|
+
parser (~> 3.1.0)
|
31
|
+
rainbow (>= 2.0, < 4.0)
|
32
|
+
regexp_parser (2.5.0)
|
33
|
+
rexml (3.2.5)
|
34
|
+
rspec (3.11.0)
|
35
|
+
rspec-core (~> 3.11.0)
|
36
|
+
rspec-expectations (~> 3.11.0)
|
37
|
+
rspec-mocks (~> 3.11.0)
|
38
|
+
rspec-core (3.11.0)
|
39
|
+
rspec-support (~> 3.11.0)
|
40
|
+
rspec-expectations (3.11.0)
|
41
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
42
|
+
rspec-support (~> 3.11.0)
|
43
|
+
rspec-mocks (3.11.1)
|
44
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
45
|
+
rspec-support (~> 3.11.0)
|
46
|
+
rspec-support (3.11.0)
|
47
|
+
rubocop (1.35.0)
|
48
|
+
json (~> 2.3)
|
49
|
+
parallel (~> 1.10)
|
50
|
+
parser (>= 3.1.2.1)
|
51
|
+
rainbow (>= 2.2.2, < 4.0)
|
52
|
+
regexp_parser (>= 1.8, < 3.0)
|
53
|
+
rexml (>= 3.2.5, < 4.0)
|
54
|
+
rubocop-ast (>= 1.20.1, < 2.0)
|
55
|
+
ruby-progressbar (~> 1.7)
|
56
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
57
|
+
rubocop-ast (1.21.0)
|
58
|
+
parser (>= 3.1.1.0)
|
59
|
+
rubocop-performance (1.14.3)
|
60
|
+
rubocop (>= 1.7.0, < 2.0)
|
61
|
+
rubocop-ast (>= 0.4.0)
|
62
|
+
rubocop-rspec (2.12.1)
|
63
|
+
rubocop (~> 1.31)
|
64
|
+
ruby-progressbar (1.11.0)
|
65
|
+
unicode-display_width (2.2.0)
|
66
|
+
webrick (1.7.0)
|
67
|
+
yard (0.9.28)
|
68
|
+
webrick (~> 1.7.0)
|
69
|
+
|
70
|
+
PLATFORMS
|
71
|
+
x86_64-darwin-19
|
72
|
+
|
73
|
+
DEPENDENCIES
|
74
|
+
ProtectedConstructor!
|
75
|
+
bundler (~> 2.2, >= 2.2.17)
|
76
|
+
pry-byebug (~> 3.9)
|
77
|
+
rake (~> 13.0, >= 13.0.6)
|
78
|
+
redcarpet (~> 3.5, >= 3.5.1)
|
79
|
+
reek (~> 6.1, >= 6.1.1)
|
80
|
+
rspec (>= 3.10)
|
81
|
+
rubocop (~> 1.35)
|
82
|
+
rubocop-performance (~> 1.14, >= 1.14.3)
|
83
|
+
rubocop-rspec (~> 2.12, >= 2.12.1)
|
84
|
+
yard (~> 0.9.28)
|
85
|
+
|
86
|
+
BUNDLED WITH
|
87
|
+
2.3.20
|
@@ -1,23 +1,37 @@
|
|
1
|
-
#
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'English'
|
4
|
+
|
5
|
+
lib = File.expand_path('lib', __dir__)
|
3
6
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
7
|
require 'ProtectedConstructor/version'
|
5
8
|
|
6
9
|
Gem::Specification.new do |spec|
|
7
|
-
spec.name =
|
10
|
+
spec.name = 'ProtectedConstructor'
|
8
11
|
spec.version = ProtectedConstructor::VERSION
|
9
|
-
spec.authors = [
|
10
|
-
spec.email = [
|
11
|
-
spec.description =
|
12
|
-
spec.summary =
|
13
|
-
|
14
|
-
|
12
|
+
spec.authors = ['Gene M. Angelo, Jr.']
|
13
|
+
spec.email = ['public.gma@gmail.com']
|
14
|
+
spec.description = 'ProtectedConstructor Gem'
|
15
|
+
spec.summary = 'Provides a module that may be included in a Ruby class, ' \
|
16
|
+
'that protects the constructor; good for enforcing instantiation of classes ' \
|
17
|
+
'using, for instance, a class factory.'
|
18
|
+
spec.homepage = 'http://www.geneangelo.com'
|
19
|
+
spec.license = 'MIT'
|
15
20
|
|
16
|
-
spec.files = `git ls-files`.split(
|
21
|
+
spec.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
|
17
22
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
23
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
-
spec.require_paths = [
|
24
|
+
spec.require_paths = ['lib']
|
20
25
|
|
21
|
-
spec.
|
22
|
-
spec.add_development_dependency
|
26
|
+
spec.required_ruby_version = '~> 3.0.1'
|
27
|
+
spec.add_development_dependency 'bundler', '~> 2.2', '>= 2.2.17'
|
28
|
+
spec.add_development_dependency 'pry-byebug', '~> 3.9'
|
29
|
+
spec.add_development_dependency 'rake', '~> 13.0', '>= 13.0.6'
|
30
|
+
spec.add_development_dependency 'redcarpet', '~> 3.5', '>= 3.5.1'
|
31
|
+
spec.add_development_dependency 'reek', '~> 6.1', '>= 6.1.1'
|
32
|
+
spec.add_development_dependency 'rspec', '>= 3.10'
|
33
|
+
spec.add_development_dependency 'rubocop', '~> 1.35'
|
34
|
+
spec.add_development_dependency 'rubocop-performance', '~> 1.14', '>= 1.14.3'
|
35
|
+
spec.add_development_dependency 'rubocop-rspec', '~> 2.12', '>= 2.12.1'
|
36
|
+
spec.add_development_dependency 'yard', '~> 0.9.28'
|
23
37
|
end
|
data/README.md
CHANGED
@@ -1,5 +1,13 @@
|
|
1
|
-
|
1
|
+
[](http://badge.fury.io/gh/gangelo%2FProtectedConstructor.svg?v=2.0.0)
|
2
|
+
[](https://badge.fury.io/rb/ProtectedConstructor.svg)
|
3
|
+
|
4
|
+

|
5
|
+
[](http://www.rubydoc.info/gems/ProtectedConstructor/)
|
2
6
|
|
7
|
+
[](https://github.com/gangelo/ProtectedConstructor/issues)
|
8
|
+
|
9
|
+
[](#license)
|
10
|
+
# ProtectedConstructor
|
3
11
|
Provides a module that may be included in a Ruby class, that protects the constructor; good for enforcing
|
4
12
|
instantiation of classes using, for instance, a class factory. The code itself is not mine, I just wrapped it
|
5
13
|
in a gem and provided the examples; sorry, I don't remember the origin of the code to give credit.
|
@@ -39,7 +47,7 @@ Or install it yourself as:
|
|
39
47
|
end
|
40
48
|
|
41
49
|
# Constructor is protected.
|
42
|
-
klass = Klass.new
|
50
|
+
klass = Klass.new # NoMethodError
|
43
51
|
|
44
52
|
# Example using factory...
|
45
53
|
klass = KlassFactory::create # works
|
data/Rakefile
CHANGED
@@ -1,13 +1,15 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'bundler/gem_tasks'
|
2
4
|
|
3
5
|
begin
|
4
6
|
require 'rspec/core/rake_task'
|
5
7
|
RSpec::Core::RakeTask.new(:spec)
|
6
|
-
rescue LoadError =>
|
7
|
-
task
|
8
|
+
rescue LoadError => _e
|
9
|
+
task 'spec' do
|
8
10
|
puts "RSpec not loaded - make sure it's installed and you're using bundle exec"
|
9
11
|
exit 1
|
10
12
|
end
|
11
13
|
end
|
12
14
|
|
13
|
-
task :
|
15
|
+
task default: :spec
|
data/lib/ProtectedConstructor.rb
CHANGED
@@ -1,4 +1,6 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'ProtectedConstructor/version'
|
2
4
|
|
3
5
|
# @example
|
4
6
|
# require 'ProtectedConstructor'
|
@@ -37,12 +39,6 @@ module ProtectedConstructor
|
|
37
39
|
klass.module_eval do
|
38
40
|
class << self
|
39
41
|
protected :new
|
40
|
-
|
41
|
-
def inherited(klass)
|
42
|
-
klass.module_eval do
|
43
|
-
def self.new(*args); super; end
|
44
|
-
end
|
45
|
-
end
|
46
42
|
end
|
47
43
|
end
|
48
44
|
end
|
@@ -1,22 +1,64 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
3
|
+
# rubocop:disable Metrics/BlockLength
|
4
|
+
describe 'ProtectedConstructor', type: :module do
|
5
|
+
let(:id) { 1 }
|
4
6
|
|
5
|
-
|
6
|
-
|
7
|
-
|
7
|
+
describe 'when the module is included in a class' do
|
8
|
+
subject do
|
9
|
+
KlassFactory
|
10
|
+
end
|
8
11
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
12
|
+
describe '.new' do
|
13
|
+
context 'when calling .new' do
|
14
|
+
it 'raises an error' do
|
15
|
+
expect { subject.new(id) }.to raise_error NoMethodError
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe '.<class factory method>' do
|
21
|
+
let(:factory_class_object) { subject.create(id) }
|
14
22
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
23
|
+
context 'when wrapped in a factory' do
|
24
|
+
it 'creates an object' do
|
25
|
+
expect(factory_class_object).to be_kind_of subject
|
26
|
+
expect(factory_class_object.id).to eq id
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
20
30
|
end
|
21
31
|
|
22
|
-
|
32
|
+
describe 'multiple inheritance' do
|
33
|
+
subject do
|
34
|
+
KlassFactoryTwo
|
35
|
+
end
|
36
|
+
|
37
|
+
let(:name) { 'john' }
|
38
|
+
|
39
|
+
describe '.new' do
|
40
|
+
context 'when calling .new' do
|
41
|
+
it 'raises an error' do
|
42
|
+
expect { subject.new(name, id) }.to raise_error NoMethodError
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe '.<class factory method>' do
|
48
|
+
context 'when calling .<class factory method>' do
|
49
|
+
let(:factory_class_object) { subject.create(name, id) }
|
50
|
+
|
51
|
+
it 'does not raise an error' do
|
52
|
+
expect { factory_class_object }.to_not raise_error
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'returns a factory class object' do
|
56
|
+
expect(factory_class_object).to be_kind_of subject
|
57
|
+
expect(factory_class_object.name).to eq name
|
58
|
+
expect(factory_class_object.id).to eq id
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
# rubocop:enable Metrics/BlockLength
|
data/spec/spec_helper.rb
CHANGED
@@ -1,3 +1,22 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'pry-byebug'
|
4
|
+
require_relative '../lib/ProtectedConstructor'
|
5
|
+
|
6
|
+
Dir[File.join(Dir.pwd, 'spec/support/**/*.rb')].sort.each { |f| require f }
|
7
|
+
|
8
|
+
RSpec.configure do |config|
|
9
|
+
# Enable flags like --only-failures and --next-failure
|
10
|
+
config.example_status_persistence_file_path = '.rspec_status'
|
11
|
+
|
12
|
+
# Disable RSpec exposing methods globally on `Module` and `main`
|
13
|
+
# config.disable_monkey_patching!
|
14
|
+
|
15
|
+
config.expect_with :rspec do |c|
|
16
|
+
c.syntax = :expect
|
17
|
+
end
|
18
|
+
|
19
|
+
config.mock_with :rspec do |c|
|
20
|
+
c.syntax = :expect
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Defines a class factory that includes ProtectedConstructor.
|
4
|
+
class KlassFactory
|
5
|
+
include ProtectedConstructor
|
6
|
+
|
7
|
+
class << self
|
8
|
+
def create(id)
|
9
|
+
send(:new, id)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
attr_reader :id
|
14
|
+
|
15
|
+
def initialize(id)
|
16
|
+
@id = id
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'klass_factory'
|
4
|
+
|
5
|
+
# Defines a class factory that inherits from a class
|
6
|
+
# that includes ProtectedConstructor.
|
7
|
+
class KlassFactoryTwo < KlassFactory
|
8
|
+
class << self
|
9
|
+
def create(name, id)
|
10
|
+
send(:new, name, id)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
attr_reader :name
|
15
|
+
|
16
|
+
def initialize(name, id)
|
17
|
+
super id
|
18
|
+
@name = name
|
19
|
+
end
|
20
|
+
end
|