require_paranoia 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,21 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Christopher J. Bottaro
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,25 @@
1
+ = require_paranoia
2
+
3
+ Temporarily disable +require+ to ensure thread safety.
4
+
5
+ == Examples
6
+
7
+ require "something"
8
+ Kernel.disable_require!
9
+ require "something" # Ok, it's already loaded.
10
+ require "something_else" # Raises RequireParanoia exception.
11
+ Kernel.enable_require!
12
+ require "something_else" # Ok, require has been renabled.
13
+
14
+ You can call <tt>disable_require!</tt> with a block.
15
+
16
+ require "something"
17
+ Kernel.disable_require! do
18
+ require "something" # Ok, it's already loaded.
19
+ require "something_else" # Raises RequireParanoia exception.
20
+ end
21
+ require "something_else" # Ok, require has been renabled.
22
+
23
+ == Copyright
24
+
25
+ Copyright (c) 2010 Christopher J. Bottaro. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,53 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "require_paranoia"
8
+ gem.summary = %Q{Temporarily disable require to ensure thread safety.}
9
+ gem.description = %Q{Temporarily disable Kernel.require to ensure thread safety.}
10
+ gem.email = "cjbottaro@alumni.cs.utexas.edu"
11
+ gem.homepage = "http://github.com/cjbottaro/require_paranoia"
12
+ gem.authors = ["Christopher J. Bottaro"]
13
+ #gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
14
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
15
+ end
16
+ Jeweler::GemcutterTasks.new
17
+ rescue LoadError
18
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
19
+ end
20
+
21
+ require 'rake/testtask'
22
+ Rake::TestTask.new(:test) do |test|
23
+ test.libs << 'lib' << 'test'
24
+ test.pattern = 'test/**/test_*.rb'
25
+ test.verbose = true
26
+ end
27
+
28
+ begin
29
+ require 'rcov/rcovtask'
30
+ Rcov::RcovTask.new do |test|
31
+ test.libs << 'test'
32
+ test.pattern = 'test/**/test_*.rb'
33
+ test.verbose = true
34
+ end
35
+ rescue LoadError
36
+ task :rcov do
37
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
38
+ end
39
+ end
40
+
41
+ task :test => :check_dependencies
42
+
43
+ task :default => :test
44
+
45
+ require 'rake/rdoctask'
46
+ Rake::RDocTask.new do |rdoc|
47
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
48
+
49
+ rdoc.rdoc_dir = 'rdoc'
50
+ rdoc.title = "require_paranoia #{version}"
51
+ rdoc.rdoc_files.include('README*')
52
+ rdoc.rdoc_files.include('lib/**/*.rb')
53
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,38 @@
1
+ require "set"
2
+
3
+ class RequireParanoia < RuntimeError; end
4
+
5
+ module Kernel
6
+
7
+ alias_method :enabled_require, :require
8
+
9
+ def disabled_require(arg)
10
+ without_ext = arg.sub /(\.rb$)|(\.bundle$)/, ""
11
+ files = %w[.rb .bundle].collect{ |ext| without_ext + ext }
12
+ if ($".to_set & files.to_set).empty?
13
+ raise RequireParanoia, "trying to load file -- #{arg}"
14
+ else
15
+ true
16
+ end
17
+ end
18
+
19
+ def self.disable_require!
20
+ class_eval{ alias_method :require, :disabled_require }
21
+
22
+ if block_given?
23
+ begin
24
+ yield
25
+ rescue Exception => e
26
+ raise
27
+ ensure
28
+ enable_require!
29
+ end
30
+ end
31
+
32
+ end
33
+
34
+ def self.enable_require!
35
+ class_eval{ alias_method :require, :enabled_require }
36
+ end
37
+
38
+ end
File without changes
File without changes
File without changes
@@ -0,0 +1,2 @@
1
+ class Test4
2
+ end
data/test/helper.rb ADDED
@@ -0,0 +1,9 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+
4
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
5
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
6
+ require 'require_paranoia'
7
+
8
+ class Test::Unit::TestCase
9
+ end
@@ -0,0 +1,36 @@
1
+ require 'helper'
2
+
3
+ class TestRequireParanoia < Test::Unit::TestCase
4
+
5
+ def test_basic
6
+ Kernel.disable_require!
7
+ assert_raises(RequireParanoia){ require "test/files/test1" }
8
+ Kernel.enable_require!
9
+ assert require("test/files/test1")
10
+
11
+ end
12
+
13
+ def test_with_block
14
+ Kernel.disable_require! do
15
+ assert_raises(RequireParanoia){ require "test/files/test2" }
16
+ end
17
+ assert require("test/files/test2")
18
+ end
19
+
20
+ def test_works_with_already_required_files
21
+ assert require("test/files/test3")
22
+ Kernel.disable_require! do
23
+ assert require("test/files/test3")
24
+ end
25
+ end
26
+
27
+ def test_enable_requires_actually_restores_original
28
+ Kernel.disable_require! do
29
+ assert_raises(RequireParanoia){ require "test/files/test4" }
30
+ end
31
+ assert !defined?(Test4)
32
+ assert require("test/files/test4")
33
+ assert defined?(Test4)
34
+ end
35
+
36
+ end
metadata ADDED
@@ -0,0 +1,85 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: require_paranoia
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - Christopher J. Bottaro
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-06-11 00:00:00 -05:00
19
+ default_executable:
20
+ dependencies: []
21
+
22
+ description: Temporarily disable Kernel.require to ensure thread safety.
23
+ email: cjbottaro@alumni.cs.utexas.edu
24
+ executables: []
25
+
26
+ extensions: []
27
+
28
+ extra_rdoc_files:
29
+ - LICENSE
30
+ - README.rdoc
31
+ files:
32
+ - .document
33
+ - .gitignore
34
+ - LICENSE
35
+ - README.rdoc
36
+ - Rakefile
37
+ - VERSION
38
+ - lib/require_paranoia.rb
39
+ - test/files/test1.rb
40
+ - test/files/test2.rb
41
+ - test/files/test3.rb
42
+ - test/files/test4.rb
43
+ - test/helper.rb
44
+ - test/test_require_paranoia.rb
45
+ has_rdoc: true
46
+ homepage: http://github.com/cjbottaro/require_paranoia
47
+ licenses: []
48
+
49
+ post_install_message:
50
+ rdoc_options:
51
+ - --charset=UTF-8
52
+ require_paths:
53
+ - lib
54
+ required_ruby_version: !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ hash: 3
60
+ segments:
61
+ - 0
62
+ version: "0"
63
+ required_rubygems_version: !ruby/object:Gem::Requirement
64
+ none: false
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ hash: 3
69
+ segments:
70
+ - 0
71
+ version: "0"
72
+ requirements: []
73
+
74
+ rubyforge_project:
75
+ rubygems_version: 1.3.7
76
+ signing_key:
77
+ specification_version: 3
78
+ summary: Temporarily disable require to ensure thread safety.
79
+ test_files:
80
+ - test/files/test1.rb
81
+ - test/files/test2.rb
82
+ - test/files/test3.rb
83
+ - test/files/test4.rb
84
+ - test/helper.rb
85
+ - test/test_require_paranoia.rb