expand 1.0.3 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2ea9a1efdd9f3eb0013dcf094347e32d3c48aeb6d819d95d76a368c14de20862
4
- data.tar.gz: d21f446e4e5a1d793da4cc23c9017d6e15ba80066905cd302e9be33e25cfff2f
3
+ metadata.gz: f98f240f7a6d7b3912beedba4414dd8488ab84a79c8da8e987ea76f624c862ef
4
+ data.tar.gz: 5ed64f4889cd305c8c131213613b5c7558ef1a5274989ae3822589ea75a77a61
5
5
  SHA512:
6
- metadata.gz: 0660ff8939459c77f34920c14d5b678ed5a8703bc3dfab0b2a523afd75a07b516e9d25596b0ca333ad3c3f52ae1fd623047bb4033961a68e306fef25970f8401
7
- data.tar.gz: 3e51316a7a7a0b7c5ca31de138b6c09ebba2446f450166ce1a43ec4a1912b86f1cce7baf3c3e063bd05bd55c34513b67304a8ac99ddeb068b830102afde4d0ad
6
+ metadata.gz: c08ae5d1c6d495364ee299c40565af87246fc37976d40bdb0f0bf02298e651206062a6ba4accfbce2d99575bc24b316a56e0bef7f3071233eed14bdedc65d14e
7
+ data.tar.gz: 5cdf7a8d3d945e8fb4b85ee9390b101fbc32d4f4cd7b5519a520fe8af5e1b67fa53c842b5026b496d10902da5af882d55a27b483df1c6e03fa2b2188abf84413
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 1.0.4
2
+
3
+ - use a module function `Expand.namespace` so you don't need to extend
4
+
1
5
  ## 1.0.3
2
6
 
3
7
  - allow the creation of a module or class in the namespace/expand method itself.
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 extend your current context with Expand.
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
- create_class :NewThing do
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
- And even simpler, you can do it all in one line:
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, class: :NewModule do
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:
@@ -1,3 +1,3 @@
1
1
  module Expand
2
- VERSION = "1.0.3"
2
+ VERSION = "1.0.4"
3
3
  end
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.3
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-20 00:00:00.000000000 Z
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: