alias2 0.0.1
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/.gitignore +110 -0
- data/.travis.yml +18 -0
- data/Gemfile +6 -0
- data/README.md +87 -0
- data/Rakefile +5 -0
- data/alias2.gemspec +28 -0
- data/lib/alias2.rb +57 -0
- metadata +93 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 2ca79b58531d2f43d184204d979e460be1132e27
|
4
|
+
data.tar.gz: 414e6aedd76c1b46a7ceb0c6dedfe264003d8769
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 513da498fe3e3e4c61ef3702eae7ff711790d9a0e4d6802560c08595205eb8ab7270119e2bdc489f23f8cd9bd32f3fd766e5f9001ab54abb39695e893b027cd0
|
7
|
+
data.tar.gz: 648985efa3ef7b101f03b9f4c80a1b8f0a9781148ba3d3d9d64b0cc9906ffddbdb37920dae89e89d1bddfbbcf9defb45c4758147d2fa74f9bf8f63968ce81302
|
data/.gitignore
ADDED
@@ -0,0 +1,110 @@
|
|
1
|
+
|
2
|
+
# Created by https://www.gitignore.io/api/ruby,emacs
|
3
|
+
# Edit at https://www.gitignore.io/?templates=ruby,emacs
|
4
|
+
|
5
|
+
### Emacs ###
|
6
|
+
# -*- mode: gitignore; -*-
|
7
|
+
*~
|
8
|
+
\#*\#
|
9
|
+
/.emacs.desktop
|
10
|
+
/.emacs.desktop.lock
|
11
|
+
*.elc
|
12
|
+
auto-save-list
|
13
|
+
tramp
|
14
|
+
.\#*
|
15
|
+
|
16
|
+
# Org-mode
|
17
|
+
.org-id-locations
|
18
|
+
*_archive
|
19
|
+
|
20
|
+
# flymake-mode
|
21
|
+
*_flymake.*
|
22
|
+
|
23
|
+
# eshell files
|
24
|
+
/eshell/history
|
25
|
+
/eshell/lastdir
|
26
|
+
|
27
|
+
# elpa packages
|
28
|
+
/elpa/
|
29
|
+
|
30
|
+
# reftex files
|
31
|
+
*.rel
|
32
|
+
|
33
|
+
# AUCTeX auto folder
|
34
|
+
/auto/
|
35
|
+
|
36
|
+
# cask packages
|
37
|
+
.cask/
|
38
|
+
dist/
|
39
|
+
|
40
|
+
# Flycheck
|
41
|
+
flycheck_*.el
|
42
|
+
|
43
|
+
# server auth directory
|
44
|
+
/server/
|
45
|
+
|
46
|
+
# projectiles files
|
47
|
+
.projectile
|
48
|
+
|
49
|
+
# directory configuration
|
50
|
+
.dir-locals.el
|
51
|
+
|
52
|
+
# network security
|
53
|
+
/network-security.data
|
54
|
+
|
55
|
+
|
56
|
+
### Ruby ###
|
57
|
+
*.gem
|
58
|
+
*.rbc
|
59
|
+
/.config
|
60
|
+
/coverage/
|
61
|
+
/InstalledFiles
|
62
|
+
/pkg/
|
63
|
+
/spec/reports/
|
64
|
+
/spec/examples.txt
|
65
|
+
/test/tmp/
|
66
|
+
/test/version_tmp/
|
67
|
+
/tmp/
|
68
|
+
|
69
|
+
# Used by dotenv library to load environment variables.
|
70
|
+
# .env
|
71
|
+
|
72
|
+
# Ignore Byebug command history file.
|
73
|
+
.byebug_history
|
74
|
+
|
75
|
+
## Specific to RubyMotion:
|
76
|
+
.dat*
|
77
|
+
.repl_history
|
78
|
+
build/
|
79
|
+
*.bridgesupport
|
80
|
+
build-iPhoneOS/
|
81
|
+
build-iPhoneSimulator/
|
82
|
+
|
83
|
+
## Specific to RubyMotion (use of CocoaPods):
|
84
|
+
#
|
85
|
+
# We recommend against adding the Pods directory to your .gitignore. However
|
86
|
+
# you should judge for yourself, the pros and cons are mentioned at:
|
87
|
+
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
|
88
|
+
# vendor/Pods/
|
89
|
+
|
90
|
+
## Documentation cache and generated files:
|
91
|
+
/.yardoc/
|
92
|
+
/_yardoc/
|
93
|
+
/doc/
|
94
|
+
/rdoc/
|
95
|
+
|
96
|
+
## Environment normalization:
|
97
|
+
/.bundle/
|
98
|
+
/vendor/bundle
|
99
|
+
/lib/bundler/man/
|
100
|
+
|
101
|
+
# for a library or gem, you might want to ignore these files since the code is
|
102
|
+
# intended to run in multiple environments; otherwise, check them in:
|
103
|
+
Gemfile.lock
|
104
|
+
# .ruby-version
|
105
|
+
# .ruby-gemset
|
106
|
+
|
107
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
108
|
+
.rvmrc
|
109
|
+
|
110
|
+
# End of https://www.gitignore.io/api/ruby,emacs
|
data/.travis.yml
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
sudo: false
|
2
|
+
language: ruby
|
3
|
+
cache: bundler
|
4
|
+
rvm:
|
5
|
+
- 2.1
|
6
|
+
- 2.2
|
7
|
+
- 2.3
|
8
|
+
- 2.4
|
9
|
+
- 2.5
|
10
|
+
- 2.6
|
11
|
+
|
12
|
+
# https://docs.travis-ci.com/user/languages/ruby/#bundler-20
|
13
|
+
before_install:
|
14
|
+
- gem uninstall -v '>= 2' -i $(rvm gemdir)@global -ax bundler || true
|
15
|
+
- gem install bundler -v '1.16.4'
|
16
|
+
|
17
|
+
notifications:
|
18
|
+
email: false
|
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
# alias2
|
2
|
+
|
3
|
+
Make classes, modules, and constants accessible via a different namespace.
|
4
|
+
|
5
|
+
[](https://travis-ci.org/sshaw/alias2)
|
6
|
+
|
7
|
+
## Usage
|
8
|
+
|
9
|
+
```rb
|
10
|
+
require "alias2"
|
11
|
+
require "some/very/long/name/here" # If not already loaded (or autoloaded)
|
12
|
+
```
|
13
|
+
|
14
|
+
An `Array` of constant names to alias can be provided:
|
15
|
+
```rb
|
16
|
+
alias2 Some::Very::Long::Name::Here, %w[Foo Bar Baz]
|
17
|
+
```
|
18
|
+
|
19
|
+
This is the same as:
|
20
|
+
```rb
|
21
|
+
Foo = Some::Very::Long::Name::Here::Foo
|
22
|
+
Bar = Some::Very::Long::Name::Here::Bar
|
23
|
+
Baz = Some::Very::Long::Name::Here::Baz
|
24
|
+
```
|
25
|
+
|
26
|
+
The namespace can also be a `String`.
|
27
|
+
|
28
|
+
If you'd like to alias them using a different name you can:
|
29
|
+
```rb
|
30
|
+
alias2 Some::Very::Long::Name::Here, :Foo => "FooHoo", :Bar => "BarHar", :Baz => "Bazzzz"
|
31
|
+
```
|
32
|
+
|
33
|
+
Same as:
|
34
|
+
```rb
|
35
|
+
FooHoo = Some::Very::Long::Name::Here::Foo
|
36
|
+
BarHar = Some::Very::Long::Name::Here::Bar
|
37
|
+
Bazzzz = Some::Very::Long::Name::Here::Bar
|
38
|
+
```
|
39
|
+
|
40
|
+
Keys can also be `String`s.
|
41
|
+
|
42
|
+
The target can be a namespace you want created:
|
43
|
+
```rb
|
44
|
+
alias2 Some::Very::Long::Name::Here, :Foo => "New::Namespace::SameFoo", :Bar => "BarHar"
|
45
|
+
```
|
46
|
+
|
47
|
+
Same as:
|
48
|
+
```rb
|
49
|
+
module New
|
50
|
+
module Namespace
|
51
|
+
SameFoo = Some::Very::Long::Name::Here::Foo
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
BarHar = Some::Very::Long::Name::Here::Bar
|
56
|
+
```
|
57
|
+
|
58
|
+
Or it can be an existing namespace:
|
59
|
+
```rb
|
60
|
+
alias2 Some::Very::Long::Name::Here, :Foo => "Existing::Namespace::Foo", :Bar => "BarHar"
|
61
|
+
```
|
62
|
+
|
63
|
+
Same as:
|
64
|
+
```rb
|
65
|
+
Existing::Namespace::Foo = Some::Very::Long::Name::Here::Foo
|
66
|
+
BarHar = Some::Very::Long::Name::Here::Bar
|
67
|
+
```
|
68
|
+
|
69
|
+
In all cases the original namespace is not modified and remains in scope.
|
70
|
+
|
71
|
+
### Errors
|
72
|
+
|
73
|
+
A `NameError` is raised when a constant cannot be found or when a constant is already defined.
|
74
|
+
|
75
|
+
## See Also
|
76
|
+
|
77
|
+
* [aliased](https://metacpan.org/pod/aliased) - The Perl module that served as inspiration
|
78
|
+
* [require2](https://github.com/sshaw/require2) - `Kernel#require` something and make it accessible via a different namespace
|
79
|
+
* [class2](https://github.com/sshaw/class2) - Easily create hierarchies that support nested attributes, type conversion, serialization and more
|
80
|
+
|
81
|
+
## Author
|
82
|
+
|
83
|
+
Skye Shaw [skye.shaw AT gmail]
|
84
|
+
|
85
|
+
## License
|
86
|
+
|
87
|
+
Released under the MIT License: http://www.opensource.org/licenses/MIT
|
data/Rakefile
ADDED
data/alias2.gemspec
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "alias2"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "alias2"
|
8
|
+
spec.version = Alias2::VERSION
|
9
|
+
spec.authors = ["Skye Shaw"]
|
10
|
+
spec.email = ["skye.shaw@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Make classes, modules, and constants accessible via a different namespace}
|
13
|
+
spec.homepage = "https://github.com/sshaw/alias2"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
# Specify which files should be added to the gem when it is released.
|
17
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
18
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
19
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
20
|
+
end
|
21
|
+
spec.bindir = "exe"
|
22
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
23
|
+
spec.require_paths = ["lib"]
|
24
|
+
|
25
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
26
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
27
|
+
spec.add_development_dependency "minitest", "~> 5.0"
|
28
|
+
end
|
data/lib/alias2.rb
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
module Alias2
|
2
|
+
VERSION = "0.0.1".freeze
|
3
|
+
|
4
|
+
class << self
|
5
|
+
def alias(namespace, aliases)
|
6
|
+
namespace = constant(namespace)
|
7
|
+
if aliases.is_a?(String)
|
8
|
+
set(namespace, aliases)
|
9
|
+
else
|
10
|
+
aliases.each { |target, alias_as| set(namespace.const_get(target), (alias_as || target).to_s) }
|
11
|
+
end
|
12
|
+
|
13
|
+
nil
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def constant(namespace)
|
19
|
+
return namespace if namespace.is_a?(Module)
|
20
|
+
Object.const_get(namespace)
|
21
|
+
end
|
22
|
+
|
23
|
+
# Stolen from class2: https://github.com/sshaw/class2
|
24
|
+
def find_and_or_create_namespace(str)
|
25
|
+
parts = str.split("::")
|
26
|
+
namespace = parts[0..-2].inject(Object) do |parent, child|
|
27
|
+
# empty? to handle "::Namespace"
|
28
|
+
child.empty? ? parent : parent.const_defined?(child) ?
|
29
|
+
# With 2.1 we can just say Object.const_defined?(str) but keep this around for now.
|
30
|
+
parent.const_get(child) : parent.const_set(child, Module.new)
|
31
|
+
end
|
32
|
+
|
33
|
+
[ namespace, parts[-1] ]
|
34
|
+
end
|
35
|
+
|
36
|
+
def set(target, alias_as)
|
37
|
+
namespace = Object
|
38
|
+
|
39
|
+
if alias_as.include?("::")
|
40
|
+
namespace, alias_as = find_and_or_create_namespace(alias_as)
|
41
|
+
end
|
42
|
+
|
43
|
+
if namespace.const_defined?(alias_as)
|
44
|
+
const = namespace != Object ? "#{namespace}::#{alias_as}" : alias_as
|
45
|
+
raise NameError, "constant #{const} is already defined"
|
46
|
+
end
|
47
|
+
|
48
|
+
namespace.const_set(alias_as, target)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
unless %w[true 1].include?(ENV["ALIAS2_NO_EXPORT"])
|
54
|
+
def alias2(target, alias_as)
|
55
|
+
Alias2.alias(target, alias_as)
|
56
|
+
end
|
57
|
+
end
|
metadata
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: alias2
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Skye Shaw
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-03-03 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.16'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.16'
|
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: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '5.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '5.0'
|
55
|
+
description:
|
56
|
+
email:
|
57
|
+
- skye.shaw@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- ".travis.yml"
|
64
|
+
- Gemfile
|
65
|
+
- README.md
|
66
|
+
- Rakefile
|
67
|
+
- alias2.gemspec
|
68
|
+
- lib/alias2.rb
|
69
|
+
homepage: https://github.com/sshaw/alias2
|
70
|
+
licenses:
|
71
|
+
- MIT
|
72
|
+
metadata: {}
|
73
|
+
post_install_message:
|
74
|
+
rdoc_options: []
|
75
|
+
require_paths:
|
76
|
+
- lib
|
77
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
82
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
83
|
+
requirements:
|
84
|
+
- - ">="
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: '0'
|
87
|
+
requirements: []
|
88
|
+
rubyforge_project:
|
89
|
+
rubygems_version: 2.6.14
|
90
|
+
signing_key:
|
91
|
+
specification_version: 4
|
92
|
+
summary: Make classes, modules, and constants accessible via a different namespace
|
93
|
+
test_files: []
|