open_namespace 0.2.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.
- data/.gitignore +7 -0
- data/.specopts +1 -0
- data/.yardopts +1 -0
- data/ChangeLog.md +10 -0
- data/LICENSE.txt +22 -0
- data/README.md +69 -0
- data/Rakefile +43 -0
- data/lib/open_namespace.rb +2 -0
- data/lib/open_namespace/class_methods.rb +116 -0
- data/lib/open_namespace/open_namespace.rb +7 -0
- data/lib/open_namespace/version.rb +4 -0
- data/open_namespace.gemspec +87 -0
- data/spec/classes/custom/bad_constant.rb +8 -0
- data/spec/classes/custom/constant_one.rb +8 -0
- data/spec/classes/custom/constant_two.rb +8 -0
- data/spec/classes/custom/sub/constant_four.rb +10 -0
- data/spec/classes/custom_namespace.rb +10 -0
- data/spec/classes/simple_namespace.rb +7 -0
- data/spec/classes/simple_namespace/bad_constant.rb +6 -0
- data/spec/classes/simple_namespace/constant_one.rb +6 -0
- data/spec/classes/simple_namespace/constant_two.rb +6 -0
- data/spec/classes/simple_namespace/sub/constant_four.rb +8 -0
- data/spec/open_namespace_spec.rb +153 -0
- data/spec/spec_helper.rb +7 -0
- metadata +139 -0
data/.gitignore
ADDED
data/.specopts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--colour --format specdoc
|
data/.yardopts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--markup markdown --title 'OpenNamespace Documentation' --protected --files ChangeLog.md,LICENSE.txt
|
data/ChangeLog.md
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
### 0.2.0 / 2010-04-13
|
2
|
+
|
3
|
+
* Renamed the open-namespace gem to open_namespace, for naming consistency.
|
4
|
+
|
5
|
+
### 0.1.0 / 2010-02-11
|
6
|
+
|
7
|
+
* Require extlib >= 0.9.14.
|
8
|
+
* Provides implicit loading of constants via `const_missing`.
|
9
|
+
* Provides explicit loading of constants via `require_const`.
|
10
|
+
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
|
2
|
+
Copyright (c) 2010 Hal Brodigan
|
3
|
+
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
5
|
+
a copy of this software and associated documentation files (the
|
6
|
+
'Software'), to deal in the Software without restriction, including
|
7
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
8
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
9
|
+
permit persons to whom the Software is furnished to do so, subject to
|
10
|
+
the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be
|
13
|
+
included in all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
17
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
18
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
19
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
20
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
21
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
|
+
|
data/README.md
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
# OpenNamespace
|
2
|
+
|
3
|
+
* [github.com/postmodern/open_namespace](http://github.com/postmodern/open_namespace)
|
4
|
+
* [github.com/postmodern/open_namespace/issues](http://github.com/postmodern/open_namespace/issues)
|
5
|
+
* Postmodern (postmodern.mod3 at gmail.com)
|
6
|
+
|
7
|
+
## Description
|
8
|
+
|
9
|
+
OpenNamespace allows namespaces to require and find classes and modules from
|
10
|
+
RubyGems. Using OpenNamespace you can make a `Plugins` module able to
|
11
|
+
load plugin modules/classes from other gems.
|
12
|
+
|
13
|
+
## Features
|
14
|
+
|
15
|
+
* Provides implicit loading of constants via `const_missing`.
|
16
|
+
* Provides explicit loading of constants via `require_const`.
|
17
|
+
|
18
|
+
## Examples
|
19
|
+
|
20
|
+
Explicit and implicit loading of constants:
|
21
|
+
|
22
|
+
require 'open_namespace'
|
23
|
+
|
24
|
+
module Project
|
25
|
+
module Plugins
|
26
|
+
include OpenNamespace
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
# explicit loading of constants
|
31
|
+
Project::Plguins.require_const :foo_bar
|
32
|
+
# => Project::Plugins::FooBar
|
33
|
+
|
34
|
+
# explicitly loading constants via sub-paths
|
35
|
+
Project::Plguins.require_const 'templates/erb'
|
36
|
+
# => Project::Plugins::Templates::Erb
|
37
|
+
|
38
|
+
# implicit loading of constants via const_missing
|
39
|
+
Project::Plugins::Other
|
40
|
+
# => Project::Plugins::Other
|
41
|
+
|
42
|
+
Loading constants from alternate namespaces / directories:
|
43
|
+
|
44
|
+
module Project
|
45
|
+
module UI
|
46
|
+
module CommandLine
|
47
|
+
include OpenNamespace
|
48
|
+
|
49
|
+
self.namespace = 'Project::UI::CommandLine::Commands'
|
50
|
+
self.namespace_root = File.join('project','ui','command_line','commands')
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
Project::UI::CommandLine.require_const :help
|
56
|
+
# => Project::UI::CommandLine::Commands::Help
|
57
|
+
|
58
|
+
## Requirements
|
59
|
+
|
60
|
+
* [extlib](http://gemcutter.org/gems/extlib) >= 0.9.14
|
61
|
+
|
62
|
+
## Install
|
63
|
+
|
64
|
+
$ sudo gem install open_namespace
|
65
|
+
|
66
|
+
## License
|
67
|
+
|
68
|
+
See {file:LICENSE.txt} for license information.
|
69
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
require './lib/open_namespace/version.rb'
|
4
|
+
|
5
|
+
begin
|
6
|
+
require 'jeweler'
|
7
|
+
Jeweler::Tasks.new do |gem|
|
8
|
+
gem.name = 'open_namespace'
|
9
|
+
gem.version = OpenNamespace::VERSION
|
10
|
+
gem.license = 'MIT'
|
11
|
+
gem.summary = %Q{Allows namespaces to load constants on-demand}
|
12
|
+
gem.description = %Q{OpenNamespace allows namespaces to require and find classes and modules from other RubyGems.}
|
13
|
+
gem.email = 'postmodern.mod3@gmail.com'
|
14
|
+
gem.homepage = 'http://github.com/postmodern/open-namespace'
|
15
|
+
gem.authors = ['Postmodern']
|
16
|
+
gem.add_dependency 'extlib', '>= 0.9.14'
|
17
|
+
gem.add_development_dependency 'rspec', '>= 1.2.9'
|
18
|
+
gem.add_development_dependency 'yard', '>= 0.5.3'
|
19
|
+
gem.has_rdoc = 'yard'
|
20
|
+
end
|
21
|
+
rescue LoadError
|
22
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
23
|
+
end
|
24
|
+
|
25
|
+
require 'spec/rake/spectask'
|
26
|
+
Spec::Rake::SpecTask.new(:spec) do |spec|
|
27
|
+
spec.libs += ['lib', 'spec']
|
28
|
+
spec.spec_files = FileList['spec/**/*_spec.rb']
|
29
|
+
spec.spec_opts = ['--options', '.specopts']
|
30
|
+
end
|
31
|
+
|
32
|
+
task :spec => :check_dependencies
|
33
|
+
task :default => :spec
|
34
|
+
|
35
|
+
begin
|
36
|
+
require 'yard'
|
37
|
+
|
38
|
+
YARD::Rake::YardocTask.new
|
39
|
+
rescue LoadError
|
40
|
+
task :yard do
|
41
|
+
abort "YARD is not available. In order to run yard, you must: gem install yard"
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,116 @@
|
|
1
|
+
require 'extlib'
|
2
|
+
|
3
|
+
module OpenNamespace
|
4
|
+
module ClassMethods
|
5
|
+
#
|
6
|
+
# The namespace to search within.
|
7
|
+
#
|
8
|
+
# @return [String]
|
9
|
+
# The namespace to search for constants within.
|
10
|
+
#
|
11
|
+
def namespace
|
12
|
+
@namespace ||= self.name
|
13
|
+
end
|
14
|
+
|
15
|
+
#
|
16
|
+
# Sets the namespace to search within.
|
17
|
+
#
|
18
|
+
# @param [Module, Class, String] new_namespace
|
19
|
+
# The new namespace to search within.
|
20
|
+
#
|
21
|
+
# @return [String]
|
22
|
+
# The namespace to search within.
|
23
|
+
#
|
24
|
+
def namespace=(new_namespace)
|
25
|
+
case new_namespace
|
26
|
+
when Module, Class
|
27
|
+
@namespace = new_namespace.name
|
28
|
+
else
|
29
|
+
@namespace = new_namespace.to_s
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
#
|
34
|
+
# The file path that represents the namespace.
|
35
|
+
#
|
36
|
+
# @return [String]
|
37
|
+
# The file path used to load constants into the namespace.
|
38
|
+
#
|
39
|
+
def namespace_root
|
40
|
+
@namespace_root ||= self.name.to_const_path
|
41
|
+
end
|
42
|
+
|
43
|
+
#
|
44
|
+
# Sets the file path of the namespace.
|
45
|
+
#
|
46
|
+
# @param [String] new_path
|
47
|
+
# The new path of the namespace.
|
48
|
+
#
|
49
|
+
# @return [String]
|
50
|
+
# The file path used to load constants into the namespace.
|
51
|
+
#
|
52
|
+
def namespace_root=(new_path)
|
53
|
+
@namespace_root = new_path.to_s
|
54
|
+
end
|
55
|
+
|
56
|
+
#
|
57
|
+
# Requires the file and finds the newly defined constant.
|
58
|
+
#
|
59
|
+
# @param [String, Symbol] name
|
60
|
+
# The name or sub-path of the file.
|
61
|
+
#
|
62
|
+
# @return [Class, Module, nil]
|
63
|
+
# The constant loaded from the file. If +nil+ is returned, then either
|
64
|
+
# the file could not be loaded or the required constant could not be
|
65
|
+
# found.
|
66
|
+
#
|
67
|
+
# @example Loading a constant.
|
68
|
+
# require_const :helper
|
69
|
+
# # => Fully::Qualiffied::Namespace::Helper
|
70
|
+
#
|
71
|
+
# @example Loading a constant from a sub-path.
|
72
|
+
# require_const 'network/helper'
|
73
|
+
# # => Fully::Qualified::Namespace::Network::Helper
|
74
|
+
#
|
75
|
+
def require_const(name)
|
76
|
+
name = name.to_s
|
77
|
+
path = File.join(namespace_root,File.expand_path(File.join('',name)))
|
78
|
+
|
79
|
+
begin
|
80
|
+
require path
|
81
|
+
rescue Gem::LoadError
|
82
|
+
raise(e)
|
83
|
+
rescue ::LoadError
|
84
|
+
return nil
|
85
|
+
end
|
86
|
+
|
87
|
+
const_name = (self.namespace + '::' + name.to_const_string)
|
88
|
+
|
89
|
+
begin
|
90
|
+
return Object.full_const_get(const_name)
|
91
|
+
rescue NameError
|
92
|
+
return nil
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
protected
|
97
|
+
|
98
|
+
#
|
99
|
+
# Provides transparent access to require_const.
|
100
|
+
#
|
101
|
+
# @param [Symbol] name
|
102
|
+
# The name of the constant to load.
|
103
|
+
#
|
104
|
+
# @return [Class, Module]
|
105
|
+
# The loaded constant.
|
106
|
+
#
|
107
|
+
# @raise [NameError]
|
108
|
+
# Could not load or find the required constant.
|
109
|
+
#
|
110
|
+
# @see require_const.
|
111
|
+
#
|
112
|
+
def const_missing(name)
|
113
|
+
require_const(name.to_s.to_const_path) || super(name)
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{open_namespace}
|
8
|
+
s.version = "0.2.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Postmodern"]
|
12
|
+
s.date = %q{2010-04-13}
|
13
|
+
s.description = %q{OpenNamespace allows namespaces to require and find classes and modules from other RubyGems.}
|
14
|
+
s.email = %q{postmodern.mod3@gmail.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"ChangeLog.md",
|
17
|
+
"LICENSE.txt",
|
18
|
+
"README.md"
|
19
|
+
]
|
20
|
+
s.files = [
|
21
|
+
".gitignore",
|
22
|
+
".specopts",
|
23
|
+
".yardopts",
|
24
|
+
"ChangeLog.md",
|
25
|
+
"LICENSE.txt",
|
26
|
+
"README.md",
|
27
|
+
"Rakefile",
|
28
|
+
"lib/open_namespace.rb",
|
29
|
+
"lib/open_namespace/class_methods.rb",
|
30
|
+
"lib/open_namespace/open_namespace.rb",
|
31
|
+
"lib/open_namespace/version.rb",
|
32
|
+
"open_namespace.gemspec",
|
33
|
+
"spec/classes/custom/bad_constant.rb",
|
34
|
+
"spec/classes/custom/constant_one.rb",
|
35
|
+
"spec/classes/custom/constant_two.rb",
|
36
|
+
"spec/classes/custom/sub/constant_four.rb",
|
37
|
+
"spec/classes/custom_namespace.rb",
|
38
|
+
"spec/classes/simple_namespace.rb",
|
39
|
+
"spec/classes/simple_namespace/bad_constant.rb",
|
40
|
+
"spec/classes/simple_namespace/constant_one.rb",
|
41
|
+
"spec/classes/simple_namespace/constant_two.rb",
|
42
|
+
"spec/classes/simple_namespace/sub/constant_four.rb",
|
43
|
+
"spec/open_namespace_spec.rb",
|
44
|
+
"spec/spec_helper.rb"
|
45
|
+
]
|
46
|
+
s.has_rdoc = %q{yard}
|
47
|
+
s.homepage = %q{http://github.com/postmodern/open-namespace}
|
48
|
+
s.licenses = ["MIT"]
|
49
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
50
|
+
s.require_paths = ["lib"]
|
51
|
+
s.rubygems_version = %q{1.3.6}
|
52
|
+
s.summary = %q{Allows namespaces to load constants on-demand}
|
53
|
+
s.test_files = [
|
54
|
+
"spec/spec_helper.rb",
|
55
|
+
"spec/open_namespace_spec.rb",
|
56
|
+
"spec/classes/custom_namespace.rb",
|
57
|
+
"spec/classes/custom/constant_two.rb",
|
58
|
+
"spec/classes/custom/constant_one.rb",
|
59
|
+
"spec/classes/custom/bad_constant.rb",
|
60
|
+
"spec/classes/custom/sub/constant_four.rb",
|
61
|
+
"spec/classes/simple_namespace.rb",
|
62
|
+
"spec/classes/simple_namespace/constant_two.rb",
|
63
|
+
"spec/classes/simple_namespace/constant_one.rb",
|
64
|
+
"spec/classes/simple_namespace/bad_constant.rb",
|
65
|
+
"spec/classes/simple_namespace/sub/constant_four.rb"
|
66
|
+
]
|
67
|
+
|
68
|
+
if s.respond_to? :specification_version then
|
69
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
70
|
+
s.specification_version = 3
|
71
|
+
|
72
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
73
|
+
s.add_runtime_dependency(%q<extlib>, [">= 0.9.14"])
|
74
|
+
s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
|
75
|
+
s.add_development_dependency(%q<yard>, [">= 0.5.3"])
|
76
|
+
else
|
77
|
+
s.add_dependency(%q<extlib>, [">= 0.9.14"])
|
78
|
+
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
79
|
+
s.add_dependency(%q<yard>, [">= 0.5.3"])
|
80
|
+
end
|
81
|
+
else
|
82
|
+
s.add_dependency(%q<extlib>, [">= 0.9.14"])
|
83
|
+
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
84
|
+
s.add_dependency(%q<yard>, [">= 0.5.3"])
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
@@ -0,0 +1,153 @@
|
|
1
|
+
require 'open_namespace/version'
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
require 'classes/simple_namespace'
|
5
|
+
require 'classes/custom_namespace'
|
6
|
+
|
7
|
+
describe OpenNamespace do
|
8
|
+
it "should have a VERSION constant" do
|
9
|
+
OpenNamespace.const_defined?('VERSION').should == true
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "default namespace" do
|
13
|
+
before(:all) do
|
14
|
+
@module = Classes::SimpleNamespace
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should have the same namespace as the module name" do
|
18
|
+
@module.namespace.should == 'Classes::SimpleNamespace'
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should have the same namespace root as the module's directory" do
|
22
|
+
@module.namespace_root.should == File.join('classes','simple_namespace')
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should load constants into the namespace" do
|
26
|
+
@module.require_const :constant_one
|
27
|
+
|
28
|
+
@module.should be_const_defined('ConstantOne')
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should find loaded constants in the namespace" do
|
32
|
+
const = @module.require_const(:constant_one)
|
33
|
+
|
34
|
+
const.class.should == Class
|
35
|
+
const.name.should == 'Classes::SimpleNamespace::ConstantOne'
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should load constants via sub-paths" do
|
39
|
+
@module.require_const File.join('sub','constant_four')
|
40
|
+
|
41
|
+
@module.should be_const_defined('Sub')
|
42
|
+
@sub = @module.const_get('Sub')
|
43
|
+
|
44
|
+
@sub.should be_const_defined('ConstantFour')
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should find constants loaded via sub-paths" do
|
48
|
+
const = @module.require_const(File.join('sub','constant_four'))
|
49
|
+
|
50
|
+
const.class.should == Class
|
51
|
+
const.name.should == 'Classes::SimpleNamespace::Sub::ConstantFour'
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should return nil on LoadError exceptions" do
|
55
|
+
const = @module.require_const(:constant_not_found)
|
56
|
+
|
57
|
+
const.should be_nil
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should return nil on NameError exceptions" do
|
61
|
+
const = @module.require_const(:bad_constant)
|
62
|
+
|
63
|
+
const.should be_nil
|
64
|
+
end
|
65
|
+
|
66
|
+
it "should load constants transparently via const_missing" do
|
67
|
+
const = @module::ConstantTwo
|
68
|
+
|
69
|
+
const.class.should == Class
|
70
|
+
const.name.should == 'Classes::SimpleNamespace::ConstantTwo'
|
71
|
+
end
|
72
|
+
|
73
|
+
it "should raise a NameError exception const_missing fails" do
|
74
|
+
lambda {
|
75
|
+
@module::BadConstant
|
76
|
+
}.should raise_error(NameError)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
describe "custom namespace" do
|
81
|
+
before(:all) do
|
82
|
+
@module = Classes::CustomNamespace
|
83
|
+
end
|
84
|
+
|
85
|
+
it "should have the same namespace as the module name" do
|
86
|
+
@module.namespace.should == 'Classes::CustomNamespace::Custom'
|
87
|
+
end
|
88
|
+
|
89
|
+
it "should have the same namespace root as the module's directory" do
|
90
|
+
@module.namespace_root.should == File.join('classes','custom')
|
91
|
+
end
|
92
|
+
|
93
|
+
it "should load constants into the namespace" do
|
94
|
+
@module.require_const :constant_one
|
95
|
+
|
96
|
+
@module.should be_const_defined('Custom')
|
97
|
+
@custom = @module.const_get('Custom')
|
98
|
+
|
99
|
+
@custom.should be_const_defined('ConstantOne')
|
100
|
+
end
|
101
|
+
|
102
|
+
it "should find loaded constants in the namespace" do
|
103
|
+
const = @module.require_const(:constant_one)
|
104
|
+
|
105
|
+
const.class.should == Class
|
106
|
+
const.name.should == 'Classes::CustomNamespace::Custom::ConstantOne'
|
107
|
+
end
|
108
|
+
|
109
|
+
it "should load constants via sub-paths" do
|
110
|
+
@module.require_const File.join('sub','constant_four')
|
111
|
+
|
112
|
+
@module.should be_const_defined('Custom')
|
113
|
+
@custom = @module.const_get('Custom')
|
114
|
+
|
115
|
+
@custom.should be_const_defined('Sub')
|
116
|
+
@sub = @custom.const_get('Sub')
|
117
|
+
|
118
|
+
@sub.should be_const_defined('ConstantFour')
|
119
|
+
end
|
120
|
+
|
121
|
+
it "should find constants loaded via sub-paths" do
|
122
|
+
const = @module.require_const(File.join('sub','constant_four'))
|
123
|
+
|
124
|
+
const.class.should == Class
|
125
|
+
const.name.should == 'Classes::CustomNamespace::Custom::Sub::ConstantFour'
|
126
|
+
end
|
127
|
+
|
128
|
+
it "should return nil on LoadError exceptions" do
|
129
|
+
const = @module.require_const(:constant_not_found)
|
130
|
+
|
131
|
+
const.should be_nil
|
132
|
+
end
|
133
|
+
|
134
|
+
it "should return nil on NameError exceptions" do
|
135
|
+
const = @module.require_const(:bad_constant)
|
136
|
+
|
137
|
+
const.should be_nil
|
138
|
+
end
|
139
|
+
|
140
|
+
it "should load constants transparently via const_missing" do
|
141
|
+
const = @module::ConstantTwo
|
142
|
+
|
143
|
+
const.class.should == Class
|
144
|
+
const.name.should == 'Classes::CustomNamespace::Custom::ConstantTwo'
|
145
|
+
end
|
146
|
+
|
147
|
+
it "should raise a NameError exception const_missing fails" do
|
148
|
+
lambda {
|
149
|
+
@module::BadConstant
|
150
|
+
}.should raise_error(NameError)
|
151
|
+
end
|
152
|
+
end
|
153
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,139 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: open_namespace
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 2
|
8
|
+
- 0
|
9
|
+
version: 0.2.0
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Postmodern
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-04-13 00:00:00 -07:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: extlib
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 0
|
29
|
+
- 9
|
30
|
+
- 14
|
31
|
+
version: 0.9.14
|
32
|
+
type: :runtime
|
33
|
+
version_requirements: *id001
|
34
|
+
- !ruby/object:Gem::Dependency
|
35
|
+
name: rspec
|
36
|
+
prerelease: false
|
37
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
segments:
|
42
|
+
- 1
|
43
|
+
- 2
|
44
|
+
- 9
|
45
|
+
version: 1.2.9
|
46
|
+
type: :development
|
47
|
+
version_requirements: *id002
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: yard
|
50
|
+
prerelease: false
|
51
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
segments:
|
56
|
+
- 0
|
57
|
+
- 5
|
58
|
+
- 3
|
59
|
+
version: 0.5.3
|
60
|
+
type: :development
|
61
|
+
version_requirements: *id003
|
62
|
+
description: OpenNamespace allows namespaces to require and find classes and modules from other RubyGems.
|
63
|
+
email: postmodern.mod3@gmail.com
|
64
|
+
executables: []
|
65
|
+
|
66
|
+
extensions: []
|
67
|
+
|
68
|
+
extra_rdoc_files:
|
69
|
+
- ChangeLog.md
|
70
|
+
- LICENSE.txt
|
71
|
+
- README.md
|
72
|
+
files:
|
73
|
+
- .gitignore
|
74
|
+
- .specopts
|
75
|
+
- .yardopts
|
76
|
+
- ChangeLog.md
|
77
|
+
- LICENSE.txt
|
78
|
+
- README.md
|
79
|
+
- Rakefile
|
80
|
+
- lib/open_namespace.rb
|
81
|
+
- lib/open_namespace/class_methods.rb
|
82
|
+
- lib/open_namespace/open_namespace.rb
|
83
|
+
- lib/open_namespace/version.rb
|
84
|
+
- open_namespace.gemspec
|
85
|
+
- spec/classes/custom/bad_constant.rb
|
86
|
+
- spec/classes/custom/constant_one.rb
|
87
|
+
- spec/classes/custom/constant_two.rb
|
88
|
+
- spec/classes/custom/sub/constant_four.rb
|
89
|
+
- spec/classes/custom_namespace.rb
|
90
|
+
- spec/classes/simple_namespace.rb
|
91
|
+
- spec/classes/simple_namespace/bad_constant.rb
|
92
|
+
- spec/classes/simple_namespace/constant_one.rb
|
93
|
+
- spec/classes/simple_namespace/constant_two.rb
|
94
|
+
- spec/classes/simple_namespace/sub/constant_four.rb
|
95
|
+
- spec/open_namespace_spec.rb
|
96
|
+
- spec/spec_helper.rb
|
97
|
+
has_rdoc: yard
|
98
|
+
homepage: http://github.com/postmodern/open-namespace
|
99
|
+
licenses:
|
100
|
+
- MIT
|
101
|
+
post_install_message:
|
102
|
+
rdoc_options:
|
103
|
+
- --charset=UTF-8
|
104
|
+
require_paths:
|
105
|
+
- lib
|
106
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
segments:
|
111
|
+
- 0
|
112
|
+
version: "0"
|
113
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
segments:
|
118
|
+
- 0
|
119
|
+
version: "0"
|
120
|
+
requirements: []
|
121
|
+
|
122
|
+
rubyforge_project:
|
123
|
+
rubygems_version: 1.3.6
|
124
|
+
signing_key:
|
125
|
+
specification_version: 3
|
126
|
+
summary: Allows namespaces to load constants on-demand
|
127
|
+
test_files:
|
128
|
+
- spec/spec_helper.rb
|
129
|
+
- spec/open_namespace_spec.rb
|
130
|
+
- spec/classes/custom_namespace.rb
|
131
|
+
- spec/classes/custom/constant_two.rb
|
132
|
+
- spec/classes/custom/constant_one.rb
|
133
|
+
- spec/classes/custom/bad_constant.rb
|
134
|
+
- spec/classes/custom/sub/constant_four.rb
|
135
|
+
- spec/classes/simple_namespace.rb
|
136
|
+
- spec/classes/simple_namespace/constant_two.rb
|
137
|
+
- spec/classes/simple_namespace/constant_one.rb
|
138
|
+
- spec/classes/simple_namespace/bad_constant.rb
|
139
|
+
- spec/classes/simple_namespace/sub/constant_four.rb
|