ProtectedConstructor 2.0.0 → 2.0.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 5a1adc2bc4c1c992ef2cbe8c1f30d01f14c6f138
4
- data.tar.gz: ba00219daee59b1201f047857ee24579af29c3be
2
+ SHA256:
3
+ metadata.gz: 671d92fcd73b13e1c4478c5e23ae61af06ffa183fefa05cbdc7aadb02a866cca
4
+ data.tar.gz: 3679469548417824ae75fb5e0c7db466e6acb9e7174884acb54f3b777d3c9ff4
5
5
  SHA512:
6
- metadata.gz: ce24631357e789057cfda725f195727b930abe9990b89c3882c9990993ce7370e2921e23616da702ad4bfc36f94d071857ae4ebc92e08e53b00b7061523f3efa
7
- data.tar.gz: 0abcbf4a583bc0aec98f07886c14d2be0bf85285cd3ae9c5bdc6fe29f202789054127dcb4c5f8008f794663caeae16f492d132c03dc89cf8697e19bc2e8ff013
6
+ metadata.gz: d129b1a4e6815a292196be7f89920d8c131c0067f618afb3cf50b0c8f58b0447e1aa39fac3e17fabbfa0da46c28e618ccdb34af33d0cd4ed669289e598c66f3c
7
+ data.tar.gz: 896770e47b0e5a312290a56abdff24f020544288c22fa7e741ef90fa10836d7cc2c63e2719b2873beca9e2dbd53b95e71a95ce42e8e301673c4c225dc182844b
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
- *.rbc
3
- .bundle
4
- .config
5
- .yardoc
6
- Gemfile.lock
7
- InstalledFiles
8
- _yardoc
9
- coverage
10
- doc/
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
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.6.3
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ### 2.0.3
2
+ * changes
3
+ * Clean up ProtectedConstructor call to module_eval of unnecessary code.
4
+ * Update gems and especially rake gem version to patch redcarpet CVE-2020-26298, yard CVE-2017-17042 and CVE-2019-1020001.
5
+ * Fix rubocop violations.
data/Gemfile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
4
 
3
5
  # Specify your gem's dependencies in ProtectedConstructor.gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,87 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ ProtectedConstructor (2.0.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.13.1)
20
+ coderay (~> 1.1)
21
+ method_source (~> 1.0)
22
+ pry-byebug (3.9.0)
23
+ byebug (~> 11.0)
24
+ pry (~> 0.13.0)
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,31 +1,37 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
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 = "ProtectedConstructor"
10
+ spec.name = 'ProtectedConstructor'
8
11
  spec.version = ProtectedConstructor::VERSION
9
- spec.authors = ["Gene M. Angelo, Jr."]
10
- spec.email = ["public.gma@gmail.com"]
11
- spec.description = %q{ProtectedConstructor Gem}
12
- spec.summary = %q{Provides a module that may be included in a Ruby class, that protects the constructor; good for enforcing instantiation of classes using, for instance, a class factory.}
13
- spec.homepage = "http://www.geneangelo.com"
14
- spec.license = "MIT"
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 = ["lib"]
20
-
21
- #spec.add_development_dependency "bundler", "~> 1.3"
22
- #spec.add_development_dependency "rake"
23
-
24
+ spec.require_paths = ['lib']
24
25
 
25
- spec.required_ruby_version = '~> 2.0.0'
26
- spec.add_development_dependency "bundler", "~> 1.3"
27
- spec.add_development_dependency "rake", "~>0"
28
- spec.add_development_dependency "rspec", "~> 3.0", ">= 3.0.0"
29
- spec.add_development_dependency "yard", "0.8.6.2"
30
- spec.add_development_dependency "redcarpet", '~> 2.3', '>= 2.3.0'
26
+ spec.required_ruby_version = '~> 2.6.0'
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'
31
37
  end
data/README.md CHANGED
@@ -1,5 +1,13 @@
1
- # ProtectedConstructor
1
+ [![GitHub version](http://badge.fury.io/gh/gangelo%2FProtectedConstructor.svg?v=2.0.0)](http://badge.fury.io/gh/gangelo%2FProtectedConstructor.svg?v=2.0.0)
2
+ [![Gem Version](https://badge.fury.io/rb/ProtectedConstructor.svg)](https://badge.fury.io/rb/ProtectedConstructor.svg)
3
+
4
+ ![](http://ruby-gem-downloads-badge.herokuapp.com/ProtectedConstructor?type=total)
5
+ [![Documentation](http://img.shields.io/badge/docs-rdoc.info-blue.svg)](http://www.rubydoc.info/gems/ProtectedConstructor/)
2
6
 
7
+ [![Report Issues](https://img.shields.io/badge/report-issues-red.svg)](https://github.com/gangelo/ProtectedConstructor/issues)
8
+
9
+ [![License](http://img.shields.io/badge/license-MIT-yellowgreen.svg)](#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.
data/Rakefile CHANGED
@@ -1,13 +1,15 @@
1
- require "bundler/gem_tasks"
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 => e
7
- task "spec" do
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 :default => :spec
15
+ task default: :spec
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ProtectedConstructor
2
- VERSION = "2.0.0"
4
+ VERSION = '2.0.3'
3
5
  end
@@ -1,4 +1,6 @@
1
- require "ProtectedConstructor/version"
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
- require_relative '../spec_helper'
1
+ # frozen_string_literal: true
2
2
 
3
- describe 'ProtectedConstructor' do
3
+ # rubocop:disable Metrics/BlockLength
4
+ describe 'ProtectedConstructor', type: :module do
5
+ let(:id) { 1 }
4
6
 
5
- it 'should throw a NoMethodError exception if attempting to instantiate Klass without using the KlassFactory' do
6
- lambda { klass = Klass.new(1) }.should raise_error NoMethodError
7
- end
7
+ describe 'when the module is included in a class' do
8
+ subject do
9
+ KlassFactory
10
+ end
8
11
 
9
- it 'should create a Klass object when using the factory' do
10
- klass = KlassFactory::create(0)
11
- klass.nil?.should == false
12
- klass.is_a?(Klass).should == true
13
- end
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
- it 'should create a Klass object when using the factory and pass constructor parameters' do
16
- klass = KlassFactory::create(99)
17
- klass.nil?.should == false
18
- klass.is_a?(Klass).should == true
19
- klass.id.should == 99
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
- end
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,14 +1,22 @@
1
- require 'klass'
2
- require 'klass_factory'
1
+ # frozen_string_literal: true
2
+
3
+ require 'pry-byebug'
3
4
  require_relative '../lib/ProtectedConstructor'
4
5
 
5
- # Use :should in stead of :expect
6
+ Dir[File.join(Dir.pwd, 'spec/support/**/*.rb')].sort.each { |f| require f }
7
+
6
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
+
7
15
  config.expect_with :rspec do |c|
8
- c.syntax = :should
16
+ c.syntax = :expect
9
17
  end
18
+
10
19
  config.mock_with :rspec do |c|
11
- c.syntax = :should
20
+ c.syntax = :expect
12
21
  end
13
- #config.raise_errors_for_deprecations!
14
- 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