expand 1.0.1 → 1.0.4
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 +5 -5
- data/.github/dependabot.yml +8 -0
- data/.github/workflows/test.yml +37 -0
- data/CHANGELOG.md +17 -5
- data/Gemfile +4 -0
- data/README.md +34 -5
- data/expand.gemspec +0 -4
- data/lib/expand/version.rb +1 -1
- data/lib/expand.rb +82 -3
- metadata +9 -51
- data/.travis.yml +0 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: f98f240f7a6d7b3912beedba4414dd8488ab84a79c8da8e987ea76f624c862ef
|
4
|
+
data.tar.gz: 5ed64f4889cd305c8c131213613b5c7558ef1a5274989ae3822589ea75a77a61
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c08ae5d1c6d495364ee299c40565af87246fc37976d40bdb0f0bf02298e651206062a6ba4accfbce2d99575bc24b316a56e0bef7f3071233eed14bdedc65d14e
|
7
|
+
data.tar.gz: 5cdf7a8d3d945e8fb4b85ee9390b101fbc32d4f4cd7b5519a520fe8af5e1b67fa53c842b5026b496d10902da5af882d55a27b483df1c6e03fa2b2188abf84413
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# This workflow uses actions that are not certified by GitHub.
|
2
|
+
# They are provided by a third-party and are governed by
|
3
|
+
# separate terms of service, privacy policy, and support
|
4
|
+
# documentation.
|
5
|
+
# This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
|
6
|
+
# For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
|
7
|
+
|
8
|
+
name: Ruby
|
9
|
+
|
10
|
+
on:
|
11
|
+
push:
|
12
|
+
branches: [ "master" ]
|
13
|
+
pull_request:
|
14
|
+
branches: [ "master" ]
|
15
|
+
|
16
|
+
permissions:
|
17
|
+
contents: read
|
18
|
+
|
19
|
+
jobs:
|
20
|
+
test:
|
21
|
+
|
22
|
+
runs-on: ubuntu-latest
|
23
|
+
strategy:
|
24
|
+
matrix:
|
25
|
+
ruby-version: ['2.6', '2.7', '3.0', '3.1']
|
26
|
+
|
27
|
+
steps:
|
28
|
+
- uses: actions/checkout@v3
|
29
|
+
- name: Set up Ruby
|
30
|
+
# To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
|
31
|
+
# change this to (see https://github.com/ruby/setup-ruby#versioning):
|
32
|
+
uses: ruby/setup-ruby@v1
|
33
|
+
with:
|
34
|
+
ruby-version: ${{ matrix.ruby-version }}
|
35
|
+
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
|
36
|
+
- name: Run tests
|
37
|
+
run: bundle exec rake
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,18 @@
|
|
1
|
-
|
2
|
-
- allow specified namespace to be a module instead of a string
|
1
|
+
## 1.0.4
|
3
2
|
|
4
|
-
|
5
|
-
|
6
|
-
|
3
|
+
- use a module function `Expand.namespace` so you don't need to extend
|
4
|
+
|
5
|
+
## 1.0.3
|
6
|
+
|
7
|
+
- allow the creation of a module or class in the namespace/expand method itself.
|
8
|
+
|
9
|
+
## 1.0.2
|
10
|
+
|
11
|
+
- Add documentation
|
12
|
+
|
13
|
+
## 1.0.1
|
14
|
+
- allow specified namespace to be a module instead of a string
|
15
|
+
|
16
|
+
## 1.0.0 (2016-01-14)
|
17
|
+
Initial release.
|
18
|
+
- allow creation of classes and modules under a namespace
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -19,19 +19,48 @@ end
|
|
19
19
|
SomeGem::Thing::NewThing #=> warning: toplevel constant NewThing referenced by SomeGem::Thing::NewThing
|
20
20
|
```
|
21
21
|
|
22
|
-
To make this simpler, you can require `expand` and
|
22
|
+
To make this simpler, you can require `expand` and specify the namespace and the new class or module.
|
23
23
|
|
24
24
|
```ruby
|
25
|
-
|
25
|
+
require 'expand'
|
26
|
+
|
27
|
+
Expand.namespace SomeGem::Thing, class: :NewThing do
|
28
|
+
# define methods for your class here
|
29
|
+
end
|
30
|
+
|
31
|
+
SomeGem::Thing::NewThing #=> SomeGem::Thing::NewThing
|
32
|
+
```
|
33
|
+
|
34
|
+
You can also extend an class or object to add the `namespace` method.
|
35
|
+
|
36
|
+
```ruby
|
37
|
+
require 'expand'
|
38
|
+
extend Expand
|
39
|
+
|
40
|
+
namespace SomeGem::Thing, class: :NewThing, parent: SomeExistingOtherClass do
|
41
|
+
# define methods here
|
42
|
+
end
|
43
|
+
|
44
|
+
namespace SomeGem::Thing, module: :NewModule do
|
45
|
+
# define methods here
|
46
|
+
end
|
47
|
+
```
|
48
|
+
|
49
|
+
If you want more explicit code or to create multiple modules or classes under a sinngle namespace you can use `create_class` and `create_module`
|
50
|
+
|
51
|
+
```ruby
|
52
|
+
require 'expand'
|
26
53
|
extend Expand
|
27
54
|
|
28
55
|
namespace SomeGem::Thing do
|
29
|
-
create_class :
|
56
|
+
create_class :NewClass do
|
30
57
|
# define methods here
|
31
58
|
end
|
32
|
-
end
|
33
59
|
|
34
|
-
|
60
|
+
create_module :NewModule do
|
61
|
+
# define methods here
|
62
|
+
end
|
63
|
+
end
|
35
64
|
```
|
36
65
|
|
37
66
|
## Installation
|
data/expand.gemspec
CHANGED
@@ -18,8 +18,4 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.bindir = "exe"
|
19
19
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
20
|
spec.require_paths = ["lib"]
|
21
|
-
|
22
|
-
spec.add_development_dependency "bundler", "~> 1.11"
|
23
|
-
spec.add_development_dependency "rake", "~> 10.0"
|
24
|
-
spec.add_development_dependency "minitest", "~> 5.0"
|
25
21
|
end
|
data/lib/expand/version.rb
CHANGED
data/lib/expand.rb
CHANGED
@@ -1,17 +1,48 @@
|
|
1
1
|
require "expand/version"
|
2
2
|
|
3
|
+
# Extend your classes or modules to use the Expand methods
|
3
4
|
module Expand
|
5
|
+
|
6
|
+
# The primary way to access Manager objects is to use the Expand namespace method.
|
7
|
+
# @see Expand#namespace
|
8
|
+
#
|
4
9
|
class Manager
|
5
|
-
|
10
|
+
# @see Expand#namespace
|
11
|
+
def initialize(namespace, **class_or_module, &block)
|
6
12
|
@managed = namespace
|
7
13
|
end
|
8
14
|
|
15
|
+
# Create a module under the namespace for this object
|
16
|
+
# @example
|
17
|
+
# create_module 'Another' do
|
18
|
+
# def do_something
|
19
|
+
# end
|
20
|
+
# end
|
21
|
+
#
|
22
|
+
# @param name [String, Symbol] name to be used for the module
|
23
|
+
# @yield provide a block to be used when creating the module
|
24
|
+
#
|
25
|
+
# @return [Module] the named module you created
|
26
|
+
#
|
9
27
|
def create_module(name, &block)
|
10
28
|
mod = Module.new(&block)
|
11
29
|
@managed.const_set(name, mod)
|
12
30
|
mod
|
13
31
|
end
|
14
32
|
|
33
|
+
# Create a class under the namespace for this object
|
34
|
+
# @example
|
35
|
+
# create_class 'Other' do
|
36
|
+
# def do_something
|
37
|
+
# end
|
38
|
+
# end
|
39
|
+
#
|
40
|
+
# @param name [String, Symbol] name to be used for the class
|
41
|
+
# @param parent [Class] an optional class to be used as the direct ancestor of the class
|
42
|
+
# @yield provide a block to be used when creating the class
|
43
|
+
#
|
44
|
+
# @return [Class] the named class you created
|
45
|
+
#
|
15
46
|
def create_class(name, parent: Object, &block)
|
16
47
|
klass = Class.new(parent, &block)
|
17
48
|
@managed.const_set(name, klass)
|
@@ -19,13 +50,61 @@ module Expand
|
|
19
50
|
end
|
20
51
|
end
|
21
52
|
|
22
|
-
|
53
|
+
# Allows you to open a module namespace to add constants
|
54
|
+
# @example
|
55
|
+
# require 'expand'
|
56
|
+
# extend Expand
|
57
|
+
# namespace SomeGem::Thing do
|
58
|
+
# create_class 'Other' do
|
59
|
+
# # add your class code here
|
60
|
+
# end
|
61
|
+
# create_module 'Another' do
|
62
|
+
# # add your module code here
|
63
|
+
# end
|
64
|
+
# end
|
65
|
+
#
|
66
|
+
# namespace SomeGem::Thing, class: :Other do
|
67
|
+
# # add methods here
|
68
|
+
# end
|
69
|
+
# namespace SomeGem::Thing, module: :Another do
|
70
|
+
# # add methods here
|
71
|
+
# end
|
72
|
+
#
|
73
|
+
# @param context [Module, String, or any object responding to to_s] representing a module namespace.
|
74
|
+
# @param module: module name to create
|
75
|
+
# @param class: class name to create
|
76
|
+
# @param parent: optional parent class for the created class, defaults to Object
|
77
|
+
# @yield the provided block is executed against an instance of Expand::Manager using instance_eval
|
78
|
+
#
|
79
|
+
# @return [Expand::Manager] instance which can allow you to create classes and modules in the given context.
|
80
|
+
#
|
81
|
+
# @see Expand::Manager#create_class
|
82
|
+
# @see Expand::Manager#create_module
|
83
|
+
#
|
84
|
+
def namespace(context, **class_or_module, &block)
|
23
85
|
unless context.is_a?(Module)
|
24
86
|
context = context.to_s.split('::').inject(Object) do |base, mod|
|
25
87
|
base.const_get(mod)
|
26
88
|
end
|
27
89
|
end
|
28
|
-
Manager.new(context)
|
90
|
+
manager = Manager.new(context)
|
91
|
+
|
92
|
+
creating_class, creating_module = class_or_module[:class], class_or_module[:module]
|
93
|
+
raise ArgumentError, "You must choose either class: or module: but not both." if creating_class && creating_module
|
94
|
+
|
95
|
+
case
|
96
|
+
when creating_class
|
97
|
+
parent = class_or_module[:parent] || Object
|
98
|
+
manager.create_class(creating_class, parent: parent, &block)
|
99
|
+
when creating_module
|
100
|
+
if class_or_module[:parent]
|
101
|
+
warn "An option for :parent was provided as `#{class_or_module[:parent]}' but was ignored when creating the module: #{class_or_module[:module]}"
|
102
|
+
end
|
103
|
+
manager.create_module(creating_module, &block)
|
104
|
+
else
|
105
|
+
manager.instance_eval(&block)
|
106
|
+
end
|
29
107
|
end
|
30
108
|
alias expand namespace
|
109
|
+
module_function :expand, :namespace
|
31
110
|
end
|
metadata
CHANGED
@@ -1,57 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: expand
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- "'Jim Gay'"
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
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.11'
|
20
|
-
type: :development
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - "~>"
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '1.11'
|
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'
|
11
|
+
date: 2022-07-22 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
55
13
|
description: Create classes and modules under an existing namespace
|
56
14
|
email:
|
57
15
|
- jim@saturnflyer.com
|
@@ -59,8 +17,9 @@ executables: []
|
|
59
17
|
extensions: []
|
60
18
|
extra_rdoc_files: []
|
61
19
|
files:
|
20
|
+
- ".github/dependabot.yml"
|
21
|
+
- ".github/workflows/test.yml"
|
62
22
|
- ".gitignore"
|
63
|
-
- ".travis.yml"
|
64
23
|
- CHANGELOG.md
|
65
24
|
- CODE_OF_CONDUCT.md
|
66
25
|
- Gemfile
|
@@ -76,7 +35,7 @@ homepage: https://github.com/saturnflyer/expand
|
|
76
35
|
licenses:
|
77
36
|
- MIT
|
78
37
|
metadata: {}
|
79
|
-
post_install_message:
|
38
|
+
post_install_message:
|
80
39
|
rdoc_options: []
|
81
40
|
require_paths:
|
82
41
|
- lib
|
@@ -91,9 +50,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
91
50
|
- !ruby/object:Gem::Version
|
92
51
|
version: '0'
|
93
52
|
requirements: []
|
94
|
-
|
95
|
-
|
96
|
-
signing_key:
|
53
|
+
rubygems_version: 3.3.17
|
54
|
+
signing_key:
|
97
55
|
specification_version: 4
|
98
56
|
summary: Create classes and modules under an existing namespace
|
99
57
|
test_files: []
|
data/.travis.yml
DELETED