expand 1.0.3 → 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 +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +22 -8
- data/lib/expand/version.rb +1 -1
- data/lib/expand.rb +11 -0
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
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
|
data/CHANGELOG.md
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/lib/expand/version.rb
CHANGED
data/lib/expand.rb
CHANGED
|
@@ -63,7 +63,17 @@ module Expand
|
|
|
63
63
|
# end
|
|
64
64
|
# end
|
|
65
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
|
+
#
|
|
66
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
|
|
67
77
|
# @yield the provided block is executed against an instance of Expand::Manager using instance_eval
|
|
68
78
|
#
|
|
69
79
|
# @return [Expand::Manager] instance which can allow you to create classes and modules in the given context.
|
|
@@ -96,4 +106,5 @@ module Expand
|
|
|
96
106
|
end
|
|
97
107
|
end
|
|
98
108
|
alias expand namespace
|
|
109
|
+
module_function :expand, :namespace
|
|
99
110
|
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.4
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- "'Jim Gay'"
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2022-07-
|
|
11
|
+
date: 2022-07-22 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
|
13
13
|
description: Create classes and modules under an existing namespace
|
|
14
14
|
email:
|