no_patch 0.0.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ebf954c3148f71f22cb603d579dbb3a5c0bf3a98
4
+ data.tar.gz: c256e4f5049feb8449604e4f145841b9f9282a92
5
+ SHA512:
6
+ metadata.gz: 0296c80d93cf9e46d0dc19867564c383def570546924c6c2d564302cd05a835bb64c6a9d3ff8dff6dacd111ff0ea359f155e0ee28219b1a8029c8327d46aff76
7
+ data.tar.gz: 8c5181cae66292dab95f386db2328320890ca044671b9a5a7f74ca250e235621cf5f7c99cde29c8082dee0f05486a9c1be824db68bf730a48e7976f8b7994a3d
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in no_patch.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Franky W.
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,57 @@
1
+ # NoPatch
2
+
3
+ Prevent monkey patching of classes
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'no_patch'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install no_patch
20
+
21
+ ## Usage
22
+
23
+ Include it as a module to any class.
24
+
25
+ ```ruby
26
+ class MyClass
27
+ include NoPatch
28
+ end
29
+ ```
30
+
31
+ Now, it should raise errors when redefining a method that is already existent.
32
+
33
+ ```ruby
34
+ class MyClass
35
+ def foo
36
+ puts "all good here"
37
+ end
38
+ end
39
+ # => :foo
40
+
41
+ class MyClass
42
+ def foo
43
+ puts "Redefining"
44
+ end
45
+ end
46
+
47
+ #=> raises NoPath::RedifinitionError
48
+ ```
49
+
50
+
51
+ ## Contributing
52
+
53
+ 1. Fork it ( https://github.com/[my-github-username]/no_patch/fork )
54
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
55
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
56
+ 4. Push to the branch (`git push origin my-new-feature`)
57
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,40 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rubygems'
3
+
4
+ begin
5
+ require 'bundler'
6
+ rescue LoadError => e
7
+ warn e.message
8
+ warn "Run `gem install bundler` to install Bundler."
9
+ exit(-1)
10
+ end
11
+
12
+ begin
13
+ Bundler.setup(:development)
14
+ rescue Bundler::BundlerError => e
15
+ warn e.message
16
+ warn "Run `bundle install` to install missing gems."
17
+ exit e.status_code
18
+ end
19
+
20
+ require 'rake'
21
+
22
+ require 'rubygems/tasks'
23
+ Gem::Tasks.new do |tasks|
24
+ tasks.console.command = 'pry'
25
+ end
26
+
27
+ require 'rdoc/task'
28
+ RDoc::Task.new do |rdoc|
29
+ rdoc.title = "super_hooks"
30
+ end
31
+ task :doc => :rdoc
32
+
33
+ require 'rspec/core/rake_task'
34
+ RSpec::Core::RakeTask.new
35
+
36
+ task :test => :spec
37
+ task :default => :spec
38
+
39
+ task :rebuild => [:build, :install]
40
+
data/lib/no_patch.rb ADDED
@@ -0,0 +1,35 @@
1
+ require "no_patch/version"
2
+
3
+ module NoPatch
4
+
5
+ class RedifinitionError < StandardError; end
6
+
7
+ def self.included(klass)
8
+
9
+ def klass.method_added(sym)
10
+ raise RedifinitionError if self.immutable_instance_methods.include? sym
11
+ @immutable_instance_methods << sym
12
+ super
13
+ end
14
+
15
+ # Heads up, this calls itself after being defined
16
+ def klass.singleton_method_added(sym)
17
+ @immutable_class_methods ||= []
18
+ raise RedifinitionError if @immutable_class_methods.include? sym
19
+ @immutable_class_methods << sym
20
+ super
21
+ end
22
+
23
+ private
24
+ def klass.immutable_instance_methods
25
+ @immutable_instance_methods ||= []
26
+ end
27
+
28
+ def klass.immutable_class_methods
29
+ @immutable_class_methods ||= []
30
+ end
31
+
32
+ end
33
+
34
+
35
+ end
@@ -0,0 +1,24 @@
1
+ module NoPatch
2
+
3
+ # A version object
4
+ class Version
5
+ # Major release
6
+ MAJOR = 0
7
+ # Minor release
8
+ MINOR = 0
9
+ # Patch level
10
+ PATCH = 0
11
+ # Preview
12
+ PRE = nil
13
+
14
+ # Return the current version of SuperHooks
15
+ # following the semantics versioning
16
+ def self.to_s
17
+ [MAJOR, MINOR, PATCH, PRE].compact.join(".")
18
+ end
19
+ end
20
+
21
+ # The current version of SuperHooks
22
+ VERSION = Version.to_s
23
+
24
+ end
data/no_patch.gemspec ADDED
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ require 'no_patch/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = "no_patch"
9
+ spec.version = NoPatch::VERSION
10
+ spec.authors = ["Franky W."]
11
+ spec.email = ["frankywahl@users.noreply.github.com"]
12
+ spec.summary = %q{Raise messages on monkey patching}
13
+ spec.description = %q{This tools allows for monkey patching of classes to be prevented}
14
+ spec.homepage = ""
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0")
18
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.7"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency 'pry'
25
+ spec.add_development_dependency 'rdoc'
26
+ spec.add_development_dependency 'rspec'
27
+ spec.add_development_dependency 'rubygems-tasks', '~> 0.2'
28
+ end
@@ -0,0 +1,80 @@
1
+ require 'spec_helper'
2
+ describe NoPatch do
3
+ before(:each) do
4
+ class Klass
5
+ def foo; end
6
+ end
7
+ end
8
+
9
+ after(:each)do
10
+ Object.send(:remove_const, :Klass)
11
+ end
12
+
13
+ context "not including the module" do
14
+ it "can redefine a method" do
15
+ expect{
16
+ class Klass
17
+ def foo
18
+ "foo"
19
+ end
20
+ end
21
+ }.not_to raise_error
22
+ expect(Klass.new.foo).to eql "foo"
23
+ end
24
+
25
+ end
26
+ context "including the module" do
27
+ before(:each) do
28
+ class Klass
29
+ include NoPatch
30
+ def foo
31
+ "initial"
32
+ end
33
+ def self.bar
34
+ "end"
35
+ end
36
+ end
37
+ end
38
+
39
+
40
+ context "instance methods" do
41
+ it "can be defined" do
42
+ expect {
43
+ class Klass
44
+ def bar
45
+ end
46
+ end
47
+ }.not_to raise_error
48
+ end
49
+
50
+ it "raises an error when being redefined" do
51
+ expect {
52
+ class Klass
53
+ def foo
54
+ end
55
+ end
56
+ }.to raise_error NoPatch::RedifinitionError
57
+ end
58
+ end
59
+
60
+ context "class methods" do
61
+ it "can be defined" do
62
+ expect {
63
+ class Klass
64
+ def self.super
65
+ end
66
+ end
67
+ }.not_to raise_error
68
+ end
69
+
70
+ it "raises an error when being redefined" do
71
+ expect {
72
+ class Klass
73
+ def self.bar
74
+ end
75
+ end
76
+ }.to raise_error NoPatch::RedifinitionError
77
+ end
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,7 @@
1
+ require 'pry'
2
+ require 'no_patch'
3
+
4
+ RSpec.configure do |c|
5
+ c.color = true
6
+ c.formatter = :documentation
7
+ end
metadata ADDED
@@ -0,0 +1,140 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: no_patch
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Franky W.
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-01-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: pry
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rdoc
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubygems-tasks
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.2'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0.2'
97
+ description: This tools allows for monkey patching of classes to be prevented
98
+ email:
99
+ - frankywahl@users.noreply.github.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - Gemfile
106
+ - LICENSE.txt
107
+ - README.md
108
+ - Rakefile
109
+ - lib/no_patch.rb
110
+ - lib/no_patch/version.rb
111
+ - no_patch.gemspec
112
+ - spec/lib/no_patch_spec.rb
113
+ - spec/spec_helper.rb
114
+ homepage: ''
115
+ licenses:
116
+ - MIT
117
+ metadata: {}
118
+ post_install_message:
119
+ rdoc_options: []
120
+ require_paths:
121
+ - lib
122
+ required_ruby_version: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - ">="
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
127
+ required_rubygems_version: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ requirements: []
133
+ rubyforge_project:
134
+ rubygems_version: 2.4.5
135
+ signing_key:
136
+ specification_version: 4
137
+ summary: Raise messages on monkey patching
138
+ test_files:
139
+ - spec/lib/no_patch_spec.rb
140
+ - spec/spec_helper.rb