expand 1.0.0 → 1.0.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: b8eefdf8421d88d75e752a92262a63aa0ab5b66d
4
- data.tar.gz: 765b248f040050472314a7a41f47112c46b02e16
2
+ SHA256:
3
+ metadata.gz: 2ea9a1efdd9f3eb0013dcf094347e32d3c48aeb6d819d95d76a368c14de20862
4
+ data.tar.gz: d21f446e4e5a1d793da4cc23c9017d6e15ba80066905cd302e9be33e25cfff2f
5
5
  SHA512:
6
- metadata.gz: fcc95af895dc067897c1bb317ac648a64b6ec78d35e91cdfc6d490bbf72e369304dc5c68251b0defe9437abfb49052364f9536f1e7c233fd899eb34c7470eebe
7
- data.tar.gz: 313b4e3b52652337c358c2c043d1a7461f5b0cdf18c26c430dd0bdf6e0ea8bfecbc97d04ffbf9119133b086329414f38470b205b5d5e0315a3200c0502cc4b28
6
+ metadata.gz: 0660ff8939459c77f34920c14d5b678ed5a8703bc3dfab0b2a523afd75a07b516e9d25596b0ca333ad3c3f52ae1fd623047bb4033961a68e306fef25970f8401
7
+ data.tar.gz: 3e51316a7a7a0b7c5ca31de138b6c09ebba2446f450166ce1a43ec4a1912b86f1cce7baf3c3e063bd05bd55c34513b67304a8ac99ddeb068b830102afde4d0ad
@@ -0,0 +1,8 @@
1
+ version: 2
2
+ updates:
3
+ - package-ecosystem: bundler
4
+ directory: "/"
5
+ schedule:
6
+ interval: daily
7
+ time: "10:00"
8
+ open-pull-requests-limit: 10
@@ -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 ADDED
@@ -0,0 +1,14 @@
1
+ ## 1.0.3
2
+
3
+ - allow the creation of a module or class in the namespace/expand method itself.
4
+
5
+ ## 1.0.2
6
+
7
+ - Add documentation
8
+
9
+ ## 1.0.1
10
+ - allow specified namespace to be a module instead of a string
11
+
12
+ ## 1.0.0 (2016-01-14)
13
+ Initial release.
14
+ - allow creation of classes and modules under a namespace
data/Gemfile CHANGED
@@ -2,3 +2,7 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in expand.gemspec
4
4
  gemspec
5
+
6
+ gem "minitest"
7
+ gem "simplecov"
8
+ gem "rake"
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Epand
1
+ # Expand
2
2
 
3
3
  Use Expand to create classes or modules under an existing namespace.
4
4
 
@@ -22,10 +22,10 @@ SomeGem::Thing::NewThing #=> warning: toplevel constant NewThing referenced by S
22
22
  To make this simpler, you can require `expand` and extend your current context with Expand.
23
23
 
24
24
  ```ruby
25
- reuire 'expand'
25
+ require 'expand'
26
26
  extend Expand
27
27
 
28
- namespace 'SomeGem::Thing' do
28
+ namespace SomeGem::Thing do
29
29
  create_class :NewThing do
30
30
  # define methods here
31
31
  end
@@ -34,6 +34,21 @@ end
34
34
  SomeGem::Thing::NewThing #=> SomeGem::Thing::NewThing
35
35
  ```
36
36
 
37
+ And even simpler, you can do it all in one line:
38
+
39
+ ```ruby
40
+ require 'expand'
41
+ extend Expand
42
+
43
+ namespace SomeGem::Thing, class: :NewThing, parent: SomeExistingOtherClass do
44
+ # define methods here
45
+ end
46
+
47
+ namespace SomeGem::Thing, class: :NewModule do
48
+ # define methods here
49
+ end
50
+ ```
51
+
37
52
  ## Installation
38
53
 
39
54
  Add this line to your application's Gemfile:
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
@@ -1,3 +1,3 @@
1
1
  module Expand
2
- VERSION = "1.0.0"
2
+ VERSION = "1.0.3"
3
3
  end
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
- def initialize(namespace)
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,11 +50,50 @@ module Expand
19
50
  end
20
51
  end
21
52
 
22
- def namespace(string, &block)
23
- namespace = string.split('::').inject(Object) do |base, mod|
24
- base.const_get(mod)
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
+ # @param context [Module, String, or any object responding to to_s] representing a module namespace.
67
+ # @yield the provided block is executed against an instance of Expand::Manager using instance_eval
68
+ #
69
+ # @return [Expand::Manager] instance which can allow you to create classes and modules in the given context.
70
+ #
71
+ # @see Expand::Manager#create_class
72
+ # @see Expand::Manager#create_module
73
+ #
74
+ def namespace(context, **class_or_module, &block)
75
+ unless context.is_a?(Module)
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)
81
+
82
+ creating_class, creating_module = class_or_module[:class], class_or_module[:module]
83
+ raise ArgumentError, "You must choose either class: or module: but not both." if creating_class && creating_module
84
+
85
+ case
86
+ when creating_class
87
+ parent = class_or_module[:parent] || Object
88
+ manager.create_class(creating_class, parent: parent, &block)
89
+ when creating_module
90
+ if class_or_module[:parent]
91
+ warn "An option for :parent was provided as `#{class_or_module[:parent]}' but was ignored when creating the module: #{class_or_module[:module]}"
92
+ end
93
+ manager.create_module(creating_module, &block)
94
+ else
95
+ manager.instance_eval(&block)
25
96
  end
26
- Manager.new(namespace).instance_eval(&block)
27
97
  end
28
98
  alias expand namespace
29
99
  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.0
4
+ version: 1.0.3
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: 2016-01-14 00:00:00.000000000 Z
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-20 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,10 @@ 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"
23
+ - CHANGELOG.md
64
24
  - CODE_OF_CONDUCT.md
65
25
  - Gemfile
66
26
  - LICENSE.txt
@@ -75,7 +35,7 @@ homepage: https://github.com/saturnflyer/expand
75
35
  licenses:
76
36
  - MIT
77
37
  metadata: {}
78
- post_install_message:
38
+ post_install_message:
79
39
  rdoc_options: []
80
40
  require_paths:
81
41
  - lib
@@ -90,9 +50,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
90
50
  - !ruby/object:Gem::Version
91
51
  version: '0'
92
52
  requirements: []
93
- rubyforge_project:
94
- rubygems_version: 2.5.1
95
- signing_key:
53
+ rubygems_version: 3.3.17
54
+ signing_key:
96
55
  specification_version: 4
97
56
  summary: Create classes and modules under an existing namespace
98
57
  test_files: []
data/.travis.yml DELETED
@@ -1,4 +0,0 @@
1
- language: ruby
2
- rvm:
3
- - 2.3.0
4
- before_install: gem install bundler -v 1.11.2