open_namespace 0.4.1 → 0.4.2
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/.github/workflows/ruby.yml +28 -0
- data/.gitignore +3 -2
- data/ChangeLog.md +10 -0
- data/Gemfile +13 -0
- data/LICENSE.txt +1 -1
- data/README.md +50 -33
- data/Rakefile +6 -30
- data/gemspec.yml +9 -4
- data/lib/open_namespace/class_methods.rb +2 -0
- data/lib/open_namespace/open_namespace.rb +3 -1
- data/lib/open_namespace/version.rb +3 -1
- data/lib/open_namespace.rb +4 -2
- data/open_namespace.gemspec +42 -89
- data/spec/open_namespace_spec.rb +64 -63
- data/spec/spec_helper.rb +0 -2
- metadata +52 -95
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 27c14527e862b51cac2728bd23be2d39d840cc296dd7cf62cf39428a3fbc6c60
|
4
|
+
data.tar.gz: f186567025a8c9b3d91b2d1719d9f6c814bc85d5fd152b9335c04c4a4aa8258a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ec0f07fb897e17be72e11db13395d7568327b43509a4a78ac0a3f8358874736ccac4553c933f29bd02777bcb9d139548d912a25b823c20641ba4faf13809d791
|
7
|
+
data.tar.gz: d6328b3f3da9a744e462eaeb0e812bd01348a0c3ff0353bae32c9854869833d2920bba6806fd82af56e23b54bc7de57f5a8ab4d68436e27ffd823ff2dda38b69
|
@@ -0,0 +1,28 @@
|
|
1
|
+
name: CI
|
2
|
+
|
3
|
+
on: [ push, pull_request ]
|
4
|
+
|
5
|
+
jobs:
|
6
|
+
tests:
|
7
|
+
runs-on: ubuntu-latest
|
8
|
+
strategy:
|
9
|
+
fail-fast: false
|
10
|
+
matrix:
|
11
|
+
ruby:
|
12
|
+
- "3.0"
|
13
|
+
- "3.1"
|
14
|
+
- "3.2"
|
15
|
+
- "3.3"
|
16
|
+
- jruby
|
17
|
+
- truffleruby
|
18
|
+
name: Ruby ${{ matrix.ruby }}
|
19
|
+
steps:
|
20
|
+
- uses: actions/checkout@v4
|
21
|
+
- name: Set up Ruby
|
22
|
+
uses: ruby/setup-ruby@v1
|
23
|
+
with:
|
24
|
+
ruby-version: ${{ matrix.ruby }}
|
25
|
+
- name: Install dependencies
|
26
|
+
run: bundle install --jobs 4 --retry 3
|
27
|
+
- name: Run tests
|
28
|
+
run: bundle exec rake test
|
data/.gitignore
CHANGED
data/ChangeLog.md
CHANGED
@@ -1,3 +1,13 @@
|
|
1
|
+
### 0.4.2 / 2024-01-24
|
2
|
+
|
3
|
+
* Switched to using `require_relative` to improve load-times.
|
4
|
+
* Added `# frozen_string_literal: true` to all files.
|
5
|
+
|
6
|
+
### 0.4.1 / 2012-05-27
|
7
|
+
|
8
|
+
* Replaced ore-tasks with
|
9
|
+
[rubygems-tasks](https://github.com/postmodern/rubygems-tasks#readme).
|
10
|
+
|
1
11
|
### 0.4.0 / 2011-11-19
|
2
12
|
|
3
13
|
* Added {OpenNamespace.const_lookup}.
|
data/Gemfile
ADDED
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -3,7 +3,6 @@
|
|
3
3
|
* [Source](https://github.com/postmodern/open_namespace)
|
4
4
|
* [Issues](https://github.com/postmodern/open_namespace/issues)
|
5
5
|
* [Documentation](http://rubydoc.info/gems/open_namespace/frames)
|
6
|
-
* [Email](mailto:postmodern.mod3 at gmail.com)
|
7
6
|
|
8
7
|
## Description
|
9
8
|
|
@@ -16,58 +15,76 @@ load plugin modules/classes from other gems.
|
|
16
15
|
* Provides implicit loading of constants via `const_defined?`.
|
17
16
|
* Provides implicit loading of constants via `const_missing`.
|
18
17
|
* Provides explicit loading of constants via `require_const`.
|
18
|
+
* Can auto-load other sub-gems (ex: `foo-bar`) from the main gem's namespace
|
19
|
+
(ex: `Foo`).
|
19
20
|
|
20
21
|
## Examples
|
21
22
|
|
22
|
-
|
23
|
+
Include it into a namespace:
|
23
24
|
|
24
|
-
|
25
|
+
```ruby
|
26
|
+
require 'open_namespace'
|
25
27
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
28
|
+
module Project
|
29
|
+
module Plugins
|
30
|
+
include OpenNamespace
|
31
|
+
end
|
32
|
+
end
|
33
|
+
```
|
34
|
+
|
35
|
+
Explicitly load constants via their file name:
|
36
|
+
|
37
|
+
```ruby
|
38
|
+
Project::Plugins.require_const :foo_bar
|
39
|
+
# => Project::Plugins::FooBar
|
40
|
+
```
|
31
41
|
|
32
|
-
|
33
|
-
Project::Plguins.require_const :foo_bar
|
34
|
-
# => Project::Plugins::FooBar
|
42
|
+
Explicitly load constants containing uppercase acronyms:
|
35
43
|
|
36
|
-
|
37
|
-
|
38
|
-
|
44
|
+
```ruby
|
45
|
+
Project::Plugins.require_const :tcp_session
|
46
|
+
# => Project::Plugins::TCPSession
|
47
|
+
```
|
39
48
|
|
40
|
-
|
41
|
-
Project::Plguins.require_const 'templates/erb'
|
42
|
-
# => Project::Plugins::Templates::Erb
|
49
|
+
Explicitly load constants from nested directories:
|
43
50
|
|
44
|
-
|
45
|
-
|
46
|
-
|
51
|
+
```ruby
|
52
|
+
Project::Plugins.require_const 'templates/erb'
|
53
|
+
# => Project::Plugins::Templates::Erb
|
54
|
+
```
|
55
|
+
|
56
|
+
Implicitly load constants via `const_missing`:
|
57
|
+
|
58
|
+
```ruby
|
59
|
+
Project::Plugins::Other
|
60
|
+
# => Project::Plugins::Other
|
61
|
+
```
|
47
62
|
|
48
63
|
Loading constants from alternate namespace root directories:
|
49
64
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
65
|
+
```ruby
|
66
|
+
module Project
|
67
|
+
module UI
|
68
|
+
module CommandLine
|
69
|
+
module Commands
|
70
|
+
include OpenNamespace
|
55
71
|
|
56
|
-
|
57
|
-
end
|
58
|
-
end
|
72
|
+
self.namespace_root = File.join(__dir__,'commands')
|
59
73
|
end
|
60
74
|
end
|
75
|
+
end
|
76
|
+
end
|
61
77
|
|
62
|
-
|
63
|
-
|
78
|
+
Project::UI::CommandLine::Commands.require_const :help
|
79
|
+
# => Project::UI::CommandLine::Commands::Help
|
80
|
+
```
|
64
81
|
|
65
82
|
## Install
|
66
83
|
|
67
|
-
|
84
|
+
```shell
|
85
|
+
$ gem install open_namespace
|
86
|
+
```
|
68
87
|
|
69
88
|
## License
|
70
89
|
|
71
|
-
Copyright (c) 2010-2012 Hal Brodigan
|
72
|
-
|
73
90
|
See {file:LICENSE.txt} for license information.
|
data/Rakefile
CHANGED
@@ -1,36 +1,12 @@
|
|
1
1
|
require 'rubygems'
|
2
|
-
require 'rake'
|
3
2
|
|
4
|
-
|
5
|
-
|
6
|
-
require 'rubygems/tasks'
|
3
|
+
require 'rubygems/tasks'
|
4
|
+
Gem::Tasks.new
|
7
5
|
|
8
|
-
|
9
|
-
|
10
|
-
warn e.message
|
11
|
-
warn "Run `gem install rubygems-tasks` to install 'rubygems/tasks'."
|
12
|
-
end
|
13
|
-
|
14
|
-
begin
|
15
|
-
gem 'rspec', '~> 2.4'
|
16
|
-
require 'rspec/core/rake_task'
|
17
|
-
|
18
|
-
RSpec::Core::RakeTask.new
|
19
|
-
rescue LoadError => e
|
20
|
-
task :spec do
|
21
|
-
abort "Please run `gem install rspec` to install RSpec."
|
22
|
-
end
|
23
|
-
end
|
6
|
+
require 'rspec/core/rake_task'
|
7
|
+
RSpec::Core::RakeTask.new
|
24
8
|
task :test => :spec
|
25
9
|
task :default => :spec
|
26
10
|
|
27
|
-
|
28
|
-
|
29
|
-
require 'yard'
|
30
|
-
|
31
|
-
YARD::Rake::YardocTask.new
|
32
|
-
rescue LoadError => e
|
33
|
-
task :yard do
|
34
|
-
abort "Please run `gem install yard` to install YARD."
|
35
|
-
end
|
36
|
-
end
|
11
|
+
require 'yard'
|
12
|
+
YARD::Rake::YardocTask.new
|
data/gemspec.yml
CHANGED
@@ -7,10 +7,15 @@ description:
|
|
7
7
|
license: MIT
|
8
8
|
authors: Postmodern
|
9
9
|
email: postmodern.mod3@gmail.com
|
10
|
-
homepage: https://github.com/postmodern/open_namespace
|
10
|
+
homepage: https://github.com/postmodern/open_namespace#readme
|
11
11
|
has_yard: true
|
12
12
|
|
13
|
+
metadata:
|
14
|
+
documentation_uri: https://rubydoc.info/gems/open_namespace
|
15
|
+
source_code_uri: https://github.com/postmodern/open_namespace
|
16
|
+
bug_tracker_uri: https://github.com/postmodern/open_namespace/issues
|
17
|
+
changelog_uri: https://github.com/postmodern/open_namespace/blob/main/ChangeLog.md
|
18
|
+
rubygems_mfa_required: 'true'
|
19
|
+
|
13
20
|
development_dependencies:
|
14
|
-
|
15
|
-
rspec: ~> 2.4
|
16
|
-
yard: ~> 0.7
|
21
|
+
bundler: ~> 2.0
|
data/lib/open_namespace.rb
CHANGED
data/open_namespace.gemspec
CHANGED
@@ -2,104 +2,57 @@
|
|
2
2
|
|
3
3
|
require 'yaml'
|
4
4
|
|
5
|
-
Gem::Specification.new do |
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
}
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
'test_files' => filter_files['{test/{**/}*_test.rb,spec/{**/}*_spec.rb}'],
|
30
|
-
'doc_files' => filter_files['*.{txt,rdoc,md,markdown,tt,textile}'],
|
31
|
-
'extra_doc_files' => filter_files['*.{txt,rdoc,md,markdown,tt,textile}']
|
32
|
-
}
|
33
|
-
|
34
|
-
metadata = defaults.merge(YAML.load_file('gemspec.yml'))
|
35
|
-
|
36
|
-
gemspec.name = metadata['name']
|
37
|
-
gemspec.version = if metadata['version']
|
38
|
-
metadata['version']
|
39
|
-
else
|
40
|
-
$LOAD_PATH << lib_dir unless $LOAD_PATH.include?(lib_dir)
|
41
|
-
|
42
|
-
require version[:file]
|
43
|
-
eval(version[:constant])
|
44
|
-
end
|
45
|
-
|
46
|
-
gemspec.summary = metadata.fetch('summary',metadata['description'])
|
47
|
-
gemspec.description = metadata.fetch('description',metadata['summary'])
|
48
|
-
|
49
|
-
gemspec.licenses = Array(metadata['license'])
|
50
|
-
gemspec.authors = Array(metadata['authors'])
|
51
|
-
|
52
|
-
gemspec.email = metadata['email']
|
53
|
-
gemspec.homepage = metadata['homepage']
|
54
|
-
|
55
|
-
gemspec.require_paths = Array(metadata['require_paths'])
|
56
|
-
gemspec.files = filter_files[metadata['files']]
|
57
|
-
gemspec.files += Array(metadata['generated_files'])
|
58
|
-
gemspec.executables = metadata['executables']
|
59
|
-
gemspec.extensions = metadata['extensions']
|
60
|
-
|
61
|
-
if Gem::VERSION < '1.7.'
|
62
|
-
gemspec.default_executable = gemspec.executables.first
|
5
|
+
Gem::Specification.new do |gem|
|
6
|
+
gemspec = YAML.load_file('gemspec.yml')
|
7
|
+
|
8
|
+
gem.name = gemspec.fetch('name')
|
9
|
+
gem.version = gemspec.fetch('version') do
|
10
|
+
require_relative 'lib/open_namespace/version'
|
11
|
+
OpenNamespace::VERSION
|
12
|
+
end
|
13
|
+
|
14
|
+
gem.summary = gemspec['summary']
|
15
|
+
gem.description = gemspec['description']
|
16
|
+
gem.licenses = Array(gemspec['license'])
|
17
|
+
gem.authors = Array(gemspec['authors'])
|
18
|
+
gem.email = gemspec['email']
|
19
|
+
gem.homepage = gemspec['homepage']
|
20
|
+
gem.metadata = gemspec['metadata'] if gemspec['metadata']
|
21
|
+
|
22
|
+
glob = lambda { |patterns| gem.files & Dir[*patterns] }
|
23
|
+
|
24
|
+
gem.files = `git ls-files`.split($/)
|
25
|
+
gem.files = glob[gemspec['files']] if gemspec['files']
|
26
|
+
|
27
|
+
gem.executables = gemspec.fetch('executables') do
|
28
|
+
glob['bin/*'].map { |path| File.basename(path) }
|
63
29
|
end
|
30
|
+
gem.default_executable = gem.executables.first if Gem::VERSION < '1.7.'
|
64
31
|
|
65
|
-
|
66
|
-
|
32
|
+
gem.extensions = glob[gemspec['extensions'] || 'ext/**/extconf.rb']
|
33
|
+
gem.test_files = glob[gemspec['test_files'] || '{test/{**/}*_test.rb']
|
34
|
+
gem.extra_rdoc_files = glob[gemspec['extra_doc_files'] || '*.{txt,md}']
|
67
35
|
|
68
|
-
|
69
|
-
|
36
|
+
gem.require_paths = Array(gemspec.fetch('require_paths') {
|
37
|
+
%w[ext lib].select { |dir| File.directory?(dir) }
|
38
|
+
})
|
70
39
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
if gemspec.respond_to?(:required_rubygems_version=)
|
76
|
-
gemspec.required_rubygems_version = metadata['required_ruby_version']
|
77
|
-
end
|
40
|
+
gem.requirements = gemspec['requirements']
|
41
|
+
gem.required_ruby_version = gemspec['required_ruby_version']
|
42
|
+
gem.required_rubygems_version = gemspec['required_rubygems_version']
|
43
|
+
gem.post_install_message = gemspec['post_install_message']
|
78
44
|
|
79
|
-
|
80
|
-
case versions
|
81
|
-
when Array
|
82
|
-
versions.map { |v| v.to_s }
|
83
|
-
when String
|
84
|
-
versions.split(/,\s*/)
|
85
|
-
end
|
86
|
-
}
|
87
|
-
|
88
|
-
if metadata['dependencies']
|
89
|
-
metadata['dependencies'].each do |name,versions|
|
90
|
-
gemspec.add_dependency(name,parse_versions[versions])
|
91
|
-
end
|
92
|
-
end
|
45
|
+
split = lambda { |string| string.split(/,\s*/) }
|
93
46
|
|
94
|
-
if
|
95
|
-
|
96
|
-
|
47
|
+
if gemspec['dependencies']
|
48
|
+
gemspec['dependencies'].each do |name,versions|
|
49
|
+
gem.add_dependency(name,split[versions])
|
97
50
|
end
|
98
51
|
end
|
99
52
|
|
100
|
-
if
|
101
|
-
|
102
|
-
|
53
|
+
if gemspec['development_dependencies']
|
54
|
+
gemspec['development_dependencies'].each do |name,versions|
|
55
|
+
gem.add_development_dependency(name,split[versions])
|
103
56
|
end
|
104
57
|
end
|
105
58
|
end
|
data/spec/open_namespace_spec.rb
CHANGED
@@ -1,160 +1,161 @@
|
|
1
|
-
require 'open_namespace/version'
|
2
|
-
|
3
1
|
require 'spec_helper'
|
2
|
+
require 'open_namespace'
|
3
|
+
|
4
4
|
require 'classes/simple_namespace'
|
5
5
|
require 'classes/custom_namespace'
|
6
6
|
|
7
7
|
describe OpenNamespace do
|
8
8
|
it "should have a VERSION constant" do
|
9
|
-
OpenNamespace.const_defined?('VERSION').
|
9
|
+
expect(OpenNamespace.const_defined?('VERSION')).to be(true)
|
10
10
|
end
|
11
11
|
|
12
12
|
context "default namespace" do
|
13
|
-
|
14
|
-
@module = Classes::SimpleNamespace
|
15
|
-
end
|
13
|
+
subject { Classes::SimpleNamespace }
|
16
14
|
|
17
15
|
it "should have the same namespace root as the module's directory" do
|
18
|
-
|
16
|
+
expect(subject.namespace_root).to eq(
|
17
|
+
File.join('classes','simple_namespace')
|
18
|
+
)
|
19
19
|
end
|
20
20
|
|
21
21
|
it "should load constants into the namespace" do
|
22
|
-
|
22
|
+
subject.require_const :constant_one
|
23
23
|
|
24
|
-
|
24
|
+
expect(subject).to be_const_defined('ConstantOne')
|
25
25
|
end
|
26
26
|
|
27
27
|
it "should find loaded constants in the namespace" do
|
28
|
-
const =
|
28
|
+
const = subject.require_const(:constant_one)
|
29
29
|
|
30
|
-
const.class.
|
31
|
-
const.name.
|
30
|
+
expect(const.class).to be(Class)
|
31
|
+
expect(const.name).to eq('Classes::SimpleNamespace::ConstantOne')
|
32
32
|
end
|
33
33
|
|
34
34
|
it "should find constants with odd capitalization" do
|
35
|
-
const =
|
35
|
+
const = subject.require_const(:odd_constant)
|
36
36
|
|
37
|
-
const.class.
|
38
|
-
const.name.
|
37
|
+
expect(const.class).to be(Class)
|
38
|
+
expect(const.name).to eq('Classes::SimpleNamespace::ODDConstant')
|
39
39
|
end
|
40
40
|
|
41
41
|
it "should load constants via sub-paths" do
|
42
|
-
|
42
|
+
subject.require_const(File.join('sub','constant_four'))
|
43
|
+
|
44
|
+
expect(subject).to be_const_defined('Sub')
|
43
45
|
|
44
|
-
|
45
|
-
@sub = @module.const_get('Sub')
|
46
|
+
sub = subject.const_get('Sub')
|
46
47
|
|
47
|
-
|
48
|
+
expect(sub).to be_const_defined('ConstantFour')
|
48
49
|
end
|
49
50
|
|
50
51
|
it "should find constants loaded via sub-paths" do
|
51
|
-
const =
|
52
|
+
const = subject.require_const(File.join('sub','constant_four'))
|
52
53
|
|
53
|
-
const.class.
|
54
|
-
const.name.
|
54
|
+
expect(const.class).to be(Class)
|
55
|
+
expect(const.name).to eq('Classes::SimpleNamespace::Sub::ConstantFour')
|
55
56
|
end
|
56
57
|
|
57
58
|
it "should return nil on LoadError exceptions" do
|
58
|
-
const =
|
59
|
+
const = subject.require_const(:constant_not_found)
|
59
60
|
|
60
|
-
const.
|
61
|
+
expect(const).to be(nil)
|
61
62
|
end
|
62
63
|
|
63
64
|
it "should return nil on NameError exceptions" do
|
64
|
-
const =
|
65
|
+
const = subject.require_const(:bad_constant)
|
65
66
|
|
66
|
-
const.
|
67
|
+
expect(const).to be(nil)
|
67
68
|
end
|
68
69
|
|
69
70
|
it "should attempt loading the constant when calling const_defined?" do
|
70
|
-
|
71
|
+
expect(subject.const_defined?('ConstantThree')).to be(true)
|
71
72
|
end
|
72
73
|
|
73
74
|
it "should load constants transparently via const_missing" do
|
74
|
-
const =
|
75
|
+
const = subject::ConstantTwo
|
75
76
|
|
76
|
-
const.class.
|
77
|
-
const.name.
|
77
|
+
expect(const.class).to be(Class)
|
78
|
+
expect(const.name).to eq('Classes::SimpleNamespace::ConstantTwo')
|
78
79
|
end
|
79
80
|
|
80
81
|
it "should raise a NameError exception const_missing fails" do
|
81
|
-
|
82
|
-
|
83
|
-
}.
|
82
|
+
expect {
|
83
|
+
subject::BadConstant
|
84
|
+
}.to raise_error(NameError)
|
84
85
|
end
|
85
86
|
end
|
86
87
|
|
87
88
|
context "custom namespace" do
|
88
|
-
|
89
|
-
@module = Classes::CustomNamespace
|
90
|
-
end
|
89
|
+
subject { Classes::CustomNamespace }
|
91
90
|
|
92
91
|
it "should have the same namespace root as the module's directory" do
|
93
|
-
|
92
|
+
expect(subject.namespace_root).to eq(File.join('classes','custom'))
|
94
93
|
end
|
95
94
|
|
96
95
|
it "should load constants into the namespace" do
|
97
|
-
|
98
|
-
|
96
|
+
subject.require_const(:constant_one)
|
97
|
+
|
98
|
+
expect(subject).to be_const_defined('ConstantOne')
|
99
99
|
end
|
100
100
|
|
101
101
|
it "should find loaded constants in the namespace" do
|
102
|
-
const =
|
102
|
+
const = subject.require_const(:constant_one)
|
103
103
|
|
104
|
-
const.class.
|
105
|
-
const.name.
|
104
|
+
expect(const.class).to be(Class)
|
105
|
+
expect(const.name).to eq('Classes::CustomNamespace::ConstantOne')
|
106
106
|
end
|
107
107
|
|
108
108
|
it "should find constants with odd capitalization" do
|
109
|
-
const =
|
109
|
+
const = subject.require_const(:odd_constant)
|
110
110
|
|
111
|
-
const.class.
|
112
|
-
const.name.
|
111
|
+
expect(const.class).to be(Class)
|
112
|
+
expect(const.name).to eq('Classes::CustomNamespace::ODDConstant')
|
113
113
|
end
|
114
114
|
|
115
115
|
it "should load constants via sub-paths" do
|
116
|
-
|
116
|
+
subject.require_const File.join('sub','constant_four')
|
117
|
+
|
118
|
+
expect(subject).to be_const_defined('Sub')
|
117
119
|
|
118
|
-
|
119
|
-
@sub = @module.const_get('Sub')
|
120
|
+
sub = subject.const_get('Sub')
|
120
121
|
|
121
|
-
|
122
|
+
expect(sub).to be_const_defined('ConstantFour')
|
122
123
|
end
|
123
124
|
|
124
125
|
it "should find constants loaded via sub-paths" do
|
125
|
-
const =
|
126
|
+
const = subject.require_const(File.join('sub','constant_four'))
|
126
127
|
|
127
|
-
const.class.
|
128
|
-
const.name.
|
128
|
+
expect(const.class).to be(Class)
|
129
|
+
expect(const.name).to eq('Classes::CustomNamespace::Sub::ConstantFour')
|
129
130
|
end
|
130
131
|
|
131
132
|
it "should return nil on LoadError exceptions" do
|
132
|
-
const =
|
133
|
+
const = subject.require_const(:constant_not_found)
|
133
134
|
|
134
|
-
const.
|
135
|
+
expect(const).to be_nil
|
135
136
|
end
|
136
137
|
|
137
138
|
it "should return nil on NameError exceptions" do
|
138
|
-
const =
|
139
|
+
const = subject.require_const(:bad_constant)
|
139
140
|
|
140
|
-
const.
|
141
|
+
expect(const).to be_nil
|
141
142
|
end
|
142
143
|
|
143
144
|
it "should attempt loading the constant when calling const_defined?" do
|
144
|
-
|
145
|
+
expect(subject.const_defined?('ConstantThree')).to be(true)
|
145
146
|
end
|
146
147
|
|
147
148
|
it "should load constants transparently via const_missing" do
|
148
|
-
const =
|
149
|
+
const = subject::ConstantTwo
|
149
150
|
|
150
|
-
const.class.
|
151
|
-
const.name.
|
151
|
+
expect(const.class).to be(Class)
|
152
|
+
expect(const.name).to eq('Classes::CustomNamespace::ConstantTwo')
|
152
153
|
end
|
153
154
|
|
154
155
|
it "should raise a NameError exception const_missing fails" do
|
155
|
-
|
156
|
-
|
157
|
-
}.
|
156
|
+
expect {
|
157
|
+
subject::BadConstant
|
158
|
+
}.to raise_error(NameError)
|
158
159
|
end
|
159
160
|
end
|
160
161
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,84 +1,47 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: open_namespace
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 4
|
9
|
-
- 1
|
10
|
-
version: 0.4.1
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.4.2
|
11
5
|
platform: ruby
|
12
|
-
authors:
|
6
|
+
authors:
|
13
7
|
- Postmodern
|
14
|
-
autorequire:
|
8
|
+
autorequire:
|
15
9
|
bindir: bin
|
16
10
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
- - ~>
|
27
|
-
- !ruby/object:Gem::Version
|
28
|
-
hash: 5
|
29
|
-
segments:
|
30
|
-
- 0
|
31
|
-
- 7
|
32
|
-
version: "0.7"
|
33
|
-
type: :development
|
34
|
-
version_requirements: *id001
|
35
|
-
- !ruby/object:Gem::Dependency
|
36
|
-
name: rubygems-tasks
|
37
|
-
prerelease: false
|
38
|
-
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
-
none: false
|
40
|
-
requirements:
|
41
|
-
- - ~>
|
42
|
-
- !ruby/object:Gem::Version
|
43
|
-
hash: 9
|
44
|
-
segments:
|
45
|
-
- 0
|
46
|
-
- 1
|
47
|
-
version: "0.1"
|
11
|
+
date: 2024-01-25 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: '2.0'
|
48
20
|
type: :development
|
49
|
-
version_requirements: *id002
|
50
|
-
- !ruby/object:Gem::Dependency
|
51
|
-
name: rspec
|
52
21
|
prerelease: false
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
- 2
|
61
|
-
- 4
|
62
|
-
version: "2.4"
|
63
|
-
type: :development
|
64
|
-
version_requirements: *id003
|
65
|
-
description: OpenNamespace allows namespaces to require and find classes and modules from other RubyGems.
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.0'
|
27
|
+
description: OpenNamespace allows namespaces to require and find classes and modules
|
28
|
+
from other RubyGems.
|
66
29
|
email: postmodern.mod3@gmail.com
|
67
30
|
executables: []
|
68
|
-
|
69
31
|
extensions: []
|
70
|
-
|
71
|
-
extra_rdoc_files:
|
32
|
+
extra_rdoc_files:
|
72
33
|
- ChangeLog.md
|
73
34
|
- LICENSE.txt
|
74
35
|
- README.md
|
75
|
-
files:
|
76
|
-
- .document
|
77
|
-
- .gemtest
|
78
|
-
- .
|
79
|
-
- .
|
80
|
-
- .
|
36
|
+
files:
|
37
|
+
- ".document"
|
38
|
+
- ".gemtest"
|
39
|
+
- ".github/workflows/ruby.yml"
|
40
|
+
- ".gitignore"
|
41
|
+
- ".rspec"
|
42
|
+
- ".yardopts"
|
81
43
|
- ChangeLog.md
|
44
|
+
- Gemfile
|
82
45
|
- LICENSE.txt
|
83
46
|
- README.md
|
84
47
|
- Rakefile
|
@@ -104,38 +67,32 @@ files:
|
|
104
67
|
- spec/classes/simple_namespace/sub/constant_four.rb
|
105
68
|
- spec/open_namespace_spec.rb
|
106
69
|
- spec/spec_helper.rb
|
107
|
-
homepage: https://github.com/postmodern/open_namespace
|
108
|
-
licenses:
|
70
|
+
homepage: https://github.com/postmodern/open_namespace#readme
|
71
|
+
licenses:
|
109
72
|
- MIT
|
110
|
-
|
73
|
+
metadata:
|
74
|
+
documentation_uri: https://rubydoc.info/gems/open_namespace
|
75
|
+
source_code_uri: https://github.com/postmodern/open_namespace
|
76
|
+
bug_tracker_uri: https://github.com/postmodern/open_namespace/issues
|
77
|
+
changelog_uri: https://github.com/postmodern/open_namespace/blob/main/ChangeLog.md
|
78
|
+
rubygems_mfa_required: 'true'
|
79
|
+
post_install_message:
|
111
80
|
rdoc_options: []
|
112
|
-
|
113
|
-
require_paths:
|
81
|
+
require_paths:
|
114
82
|
- lib
|
115
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
116
|
-
|
117
|
-
requirements:
|
83
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
118
85
|
- - ">="
|
119
|
-
- !ruby/object:Gem::Version
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
version: "0"
|
124
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
125
|
-
none: false
|
126
|
-
requirements:
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
89
|
+
requirements:
|
127
90
|
- - ">="
|
128
|
-
- !ruby/object:Gem::Version
|
129
|
-
|
130
|
-
segments:
|
131
|
-
- 0
|
132
|
-
version: "0"
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: '0'
|
133
93
|
requirements: []
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
signing_key:
|
138
|
-
specification_version: 3
|
94
|
+
rubygems_version: 3.4.10
|
95
|
+
signing_key:
|
96
|
+
specification_version: 4
|
139
97
|
summary: Allows namespaces to load constants on-demand
|
140
|
-
test_files:
|
141
|
-
- spec/open_namespace_spec.rb
|
98
|
+
test_files: []
|