expand 1.0.3 → 1.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +9 -0
- data/LICENSE.txt +1 -1
- data/README.md +22 -8
- data/Rakefile +2 -2
- data/lib/expand/version.rb +1 -1
- data/lib/expand.rb +37 -17
- metadata +4 -11
- data/.github/dependabot.yml +0 -8
- data/.github/workflows/test.yml +0 -37
- data/.gitignore +0 -9
- data/Gemfile +0 -8
- data/bin/console +0 -14
- data/bin/setup +0 -8
- data/expand.gemspec +0 -21
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1c749a422399f6bef2c67bd4ab1503cfd5d3ab99a912b2164c6930931d2861ad
|
4
|
+
data.tar.gz: e5639cd2f02dae004d3e7d60eac7a2a3eeace870eb2022ca778d785d451b5d20
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3fd15dae2380332348db1806ae0ec289ac57a936404df715d2cb0418cbafd009f213df5d958699510b0d4eed668355ffcba681feb8927adb5fa5e24f87dc0700
|
7
|
+
data.tar.gz: e4197b51d7e9c5c352492c418bae31e385efb17aac68ef0db5d5fe2fbcebe5b9e6397e227d3d0911a81f1fc9044b77412eaf2e3964c1785473bae8f35a00905b
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,12 @@
|
|
1
|
+
## 1.0.5
|
2
|
+
|
3
|
+
- use pattern matching in the `namespace` method
|
4
|
+
- add an `apply` method to eval blocks in the Manager object
|
5
|
+
|
6
|
+
## 1.0.4
|
7
|
+
|
8
|
+
- use a module function `Expand.namespace` so you don't need to extend
|
9
|
+
|
1
10
|
## 1.0.3
|
2
11
|
|
3
12
|
- allow the creation of a module or class in the namespace/expand method itself.
|
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -19,22 +19,19 @@ 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
|
-
extend Expand
|
27
26
|
|
28
|
-
namespace SomeGem::Thing do
|
29
|
-
|
30
|
-
# define methods here
|
31
|
-
end
|
27
|
+
Expand.namespace SomeGem::Thing, class: :NewThing do
|
28
|
+
# define methods for your class here
|
32
29
|
end
|
33
30
|
|
34
31
|
SomeGem::Thing::NewThing #=> SomeGem::Thing::NewThing
|
35
32
|
```
|
36
33
|
|
37
|
-
|
34
|
+
You can also extend an class or object to add the `namespace` method.
|
38
35
|
|
39
36
|
```ruby
|
40
37
|
require 'expand'
|
@@ -44,11 +41,28 @@ namespace SomeGem::Thing, class: :NewThing, parent: SomeExistingOtherClass do
|
|
44
41
|
# define methods here
|
45
42
|
end
|
46
43
|
|
47
|
-
namespace SomeGem::Thing,
|
44
|
+
namespace SomeGem::Thing, module: :NewModule do
|
48
45
|
# define methods here
|
49
46
|
end
|
50
47
|
```
|
51
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'
|
53
|
+
extend Expand
|
54
|
+
|
55
|
+
namespace SomeGem::Thing do
|
56
|
+
create_class :NewClass do
|
57
|
+
# define methods here
|
58
|
+
end
|
59
|
+
|
60
|
+
create_module :NewModule do
|
61
|
+
# define methods here
|
62
|
+
end
|
63
|
+
end
|
64
|
+
```
|
65
|
+
|
52
66
|
## Installation
|
53
67
|
|
54
68
|
Add this line to your application's Gemfile:
|
data/Rakefile
CHANGED
data/lib/expand/version.rb
CHANGED
data/lib/expand.rb
CHANGED
@@ -2,7 +2,6 @@ require "expand/version"
|
|
2
2
|
|
3
3
|
# Extend your classes or modules to use the Expand methods
|
4
4
|
module Expand
|
5
|
-
|
6
5
|
# The primary way to access Manager objects is to use the Expand namespace method.
|
7
6
|
# @see Expand#namespace
|
8
7
|
#
|
@@ -48,6 +47,20 @@ module Expand
|
|
48
47
|
@managed.const_set(name, klass)
|
49
48
|
klass
|
50
49
|
end
|
50
|
+
|
51
|
+
def apply(&block)
|
52
|
+
instance_eval(&block)
|
53
|
+
@managed
|
54
|
+
end
|
55
|
+
|
56
|
+
def self.for(context)
|
57
|
+
unless context.is_a?(Module)
|
58
|
+
context = context.to_s.split("::").inject(Object) do |base, mod|
|
59
|
+
base.const_get(mod)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
new(context)
|
63
|
+
end
|
51
64
|
end
|
52
65
|
|
53
66
|
# Allows you to open a module namespace to add constants
|
@@ -63,7 +76,17 @@ module Expand
|
|
63
76
|
# end
|
64
77
|
# end
|
65
78
|
#
|
79
|
+
# namespace SomeGem::Thing, class: :Other do
|
80
|
+
# # add methods here
|
81
|
+
# end
|
82
|
+
# namespace SomeGem::Thing, module: :Another do
|
83
|
+
# # add methods here
|
84
|
+
# end
|
85
|
+
#
|
66
86
|
# @param context [Module, String, or any object responding to to_s] representing a module namespace.
|
87
|
+
# @param module: module name to create
|
88
|
+
# @param class: class name to create
|
89
|
+
# @param parent: optional parent class for the created class, defaults to Object
|
67
90
|
# @yield the provided block is executed against an instance of Expand::Manager using instance_eval
|
68
91
|
#
|
69
92
|
# @return [Expand::Manager] instance which can allow you to create classes and modules in the given context.
|
@@ -72,28 +95,25 @@ module Expand
|
|
72
95
|
# @see Expand::Manager#create_module
|
73
96
|
#
|
74
97
|
def namespace(context, **class_or_module, &block)
|
75
|
-
|
76
|
-
context = context.to_s.split('::').inject(Object) do |base, mod|
|
77
|
-
base.const_get(mod)
|
78
|
-
end
|
79
|
-
end
|
80
|
-
manager = Manager.new(context)
|
98
|
+
manager = Manager.for(context)
|
81
99
|
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
when creating_class
|
100
|
+
case class_or_module
|
101
|
+
in { module: Symbol => _creating_module, class: Symbol => _creating_class }
|
102
|
+
raise ArgumentError, "You must choose either class: or module: but not both."
|
103
|
+
in { class: Symbol => creating_class, ** }
|
87
104
|
parent = class_or_module[:parent] || Object
|
105
|
+
|
88
106
|
manager.create_class(creating_class, parent: parent, &block)
|
89
|
-
|
90
|
-
if class_or_module[:parent]
|
91
|
-
warn "An option for :parent was provided as `#{
|
107
|
+
in { module: Symbol => creating_module, ** }
|
108
|
+
if parent = class_or_module[:parent]
|
109
|
+
warn "An option for :parent was provided as `#{parent}' but was ignored when creating the module: #{creating_module}"
|
92
110
|
end
|
111
|
+
|
93
112
|
manager.create_module(creating_module, &block)
|
94
113
|
else
|
95
|
-
manager.
|
114
|
+
manager.apply(&block)
|
96
115
|
end
|
97
116
|
end
|
98
|
-
|
117
|
+
alias_method :expand, :namespace
|
118
|
+
module_function :expand, :namespace
|
99
119
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
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.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
7
|
+
- Jim Gay
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-01-01 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Create classes and modules under an existing namespace
|
14
14
|
email:
|
@@ -17,18 +17,11 @@ executables: []
|
|
17
17
|
extensions: []
|
18
18
|
extra_rdoc_files: []
|
19
19
|
files:
|
20
|
-
- ".github/dependabot.yml"
|
21
|
-
- ".github/workflows/test.yml"
|
22
|
-
- ".gitignore"
|
23
20
|
- CHANGELOG.md
|
24
21
|
- CODE_OF_CONDUCT.md
|
25
|
-
- Gemfile
|
26
22
|
- LICENSE.txt
|
27
23
|
- README.md
|
28
24
|
- Rakefile
|
29
|
-
- bin/console
|
30
|
-
- bin/setup
|
31
|
-
- expand.gemspec
|
32
25
|
- lib/expand.rb
|
33
26
|
- lib/expand/version.rb
|
34
27
|
homepage: https://github.com/saturnflyer/expand
|
@@ -50,7 +43,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
50
43
|
- !ruby/object:Gem::Version
|
51
44
|
version: '0'
|
52
45
|
requirements: []
|
53
|
-
rubygems_version: 3.
|
46
|
+
rubygems_version: 3.4.1
|
54
47
|
signing_key:
|
55
48
|
specification_version: 4
|
56
49
|
summary: Create classes and modules under an existing namespace
|
data/.github/dependabot.yml
DELETED
data/.github/workflows/test.yml
DELETED
@@ -1,37 +0,0 @@
|
|
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/.gitignore
DELETED
data/Gemfile
DELETED
data/bin/console
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require "bundler/setup"
|
4
|
-
require "expand"
|
5
|
-
|
6
|
-
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
-
# with your gem easier. You can also use a different console, if you like.
|
8
|
-
|
9
|
-
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
-
# require "pry"
|
11
|
-
# Pry.start
|
12
|
-
|
13
|
-
require "irb"
|
14
|
-
IRB.start
|
data/bin/setup
DELETED
data/expand.gemspec
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
lib = File.expand_path('../lib', __FILE__)
|
3
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require 'expand/version'
|
5
|
-
|
6
|
-
Gem::Specification.new do |spec|
|
7
|
-
spec.name = "expand"
|
8
|
-
spec.version = Expand::VERSION
|
9
|
-
spec.authors = ["'Jim Gay'"]
|
10
|
-
spec.email = ["jim@saturnflyer.com"]
|
11
|
-
|
12
|
-
spec.summary = %q{Create classes and modules under an existing namespace}
|
13
|
-
spec.description = %q{Create classes and modules under an existing namespace}
|
14
|
-
spec.homepage = "https://github.com/saturnflyer/expand"
|
15
|
-
spec.license = "MIT"
|
16
|
-
|
17
|
-
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
-
spec.bindir = "exe"
|
19
|
-
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
-
spec.require_paths = ["lib"]
|
21
|
-
end
|