expand 1.0.4 → 1.0.6
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 +12 -0
- data/Rakefile +2 -2
- data/lib/expand/version.rb +1 -1
- data/lib/expand.rb +27 -18
- 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: 2f6ea4357fdc4411d7c50e3254b7dafc2fa805a5dabdcee9797c371e1a0c3061
|
4
|
+
data.tar.gz: cda6a8448977b174723223ad38dd9af7709d2ff6d20f2fb5d6ec5a90dbd8203a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8d2d514212cd0907017e548a3726e2f8a2bab2fbaee0f60c537762ed1592fca4b70167bc39b34b00abd6674d100e9040ab39253aa4aec21a87137318a6f18466
|
7
|
+
data.tar.gz: 8b99003304539699643196d8108ec7023fe544a6a271442fe832d0547f9972cfc8e0e67d5a76cbf6f1a4d5e8df4e8b10401c2e18eb0ad3fa513f9902b7599829
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,12 @@
|
|
1
|
+
## 1.0.6
|
2
|
+
|
3
|
+
- pass the managed namespace to the `namespace` method as an argument
|
4
|
+
|
5
|
+
## 1.0.5
|
6
|
+
|
7
|
+
- use pattern matching in the `namespace` method
|
8
|
+
- add an `apply` method to eval blocks in the Manager object
|
9
|
+
|
1
10
|
## 1.0.4
|
2
11
|
|
3
12
|
- use a module function `Expand.namespace` so you don't need to extend
|
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -63,6 +63,18 @@ namespace SomeGem::Thing do
|
|
63
63
|
end
|
64
64
|
```
|
65
65
|
|
66
|
+
## Gotchas
|
67
|
+
|
68
|
+
Unfortunately, due to the scoping of the blocks passed to the main `namespace` or `expand` methods, you are unable to directly reference classes nested in your namespace.
|
69
|
+
|
70
|
+
You can, however, pass an argument to the block to use as a reference:
|
71
|
+
|
72
|
+
```ruby
|
73
|
+
namespace SomeGem::Thing do |klass|
|
74
|
+
puts klass #=> yields "SomeGem::Thing"
|
75
|
+
end
|
76
|
+
```
|
77
|
+
|
66
78
|
## Installation
|
67
79
|
|
68
80
|
Add this line to your application's Gemfile:
|
data/Rakefile
CHANGED
data/lib/expand/version.rb
CHANGED
data/lib/expand.rb
CHANGED
@@ -2,13 +2,12 @@ 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
|
#
|
9
8
|
class Manager
|
10
9
|
# @see Expand#namespace
|
11
|
-
def initialize(namespace
|
10
|
+
def initialize(namespace)
|
12
11
|
@managed = namespace
|
13
12
|
end
|
14
13
|
|
@@ -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_exec(@managed, &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
|
@@ -82,29 +95,25 @@ module Expand
|
|
82
95
|
# @see Expand::Manager#create_module
|
83
96
|
#
|
84
97
|
def namespace(context, **class_or_module, &block)
|
85
|
-
|
86
|
-
context = context.to_s.split('::').inject(Object) do |base, mod|
|
87
|
-
base.const_get(mod)
|
88
|
-
end
|
89
|
-
end
|
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
|
98
|
+
manager = Manager.for(context)
|
94
99
|
|
95
|
-
case
|
96
|
-
|
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, ** }
|
97
104
|
parent = class_or_module[:parent] || Object
|
105
|
+
|
98
106
|
manager.create_class(creating_class, parent: parent, &block)
|
99
|
-
|
100
|
-
if class_or_module[:parent]
|
101
|
-
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}"
|
102
110
|
end
|
111
|
+
|
103
112
|
manager.create_module(creating_module, &block)
|
104
113
|
else
|
105
|
-
manager.
|
114
|
+
manager.apply(&block)
|
106
115
|
end
|
107
116
|
end
|
108
|
-
|
117
|
+
alias_method :expand, :namespace
|
109
118
|
module_function :expand, :namespace
|
110
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.6
|
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-03 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
|