expand 1.0.4 → 1.0.5

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
2
  SHA256:
3
- metadata.gz: f98f240f7a6d7b3912beedba4414dd8488ab84a79c8da8e987ea76f624c862ef
4
- data.tar.gz: 5ed64f4889cd305c8c131213613b5c7558ef1a5274989ae3822589ea75a77a61
3
+ metadata.gz: 1c749a422399f6bef2c67bd4ab1503cfd5d3ab99a912b2164c6930931d2861ad
4
+ data.tar.gz: e5639cd2f02dae004d3e7d60eac7a2a3eeace870eb2022ca778d785d451b5d20
5
5
  SHA512:
6
- metadata.gz: c08ae5d1c6d495364ee299c40565af87246fc37976d40bdb0f0bf02298e651206062a6ba4accfbce2d99575bc24b316a56e0bef7f3071233eed14bdedc65d14e
7
- data.tar.gz: 5cdf7a8d3d945e8fb4b85ee9390b101fbc32d4f4cd7b5519a520fe8af5e1b67fa53c842b5026b496d10902da5af882d55a27b483df1c6e03fa2b2188abf84413
6
+ metadata.gz: 3fd15dae2380332348db1806ae0ec289ac57a936404df715d2cb0418cbafd009f213df5d958699510b0d4eed668355ffcba681feb8927adb5fa5e24f87dc0700
7
+ data.tar.gz: e4197b51d7e9c5c352492c418bae31e385efb17aac68ef0db5d5fe2fbcebe5b9e6397e227d3d0911a81f1fc9044b77412eaf2e3964c1785473bae8f35a00905b
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
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
+
1
6
  ## 1.0.4
2
7
 
3
8
  - use a module function `Expand.namespace` so you don't need to extend
data/LICENSE.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2016 'Jim Gay'
3
+ Copyright (c) 2016-2023 'Jim Gay'
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
data/Rakefile CHANGED
@@ -4,7 +4,7 @@ require "rake/testtask"
4
4
  Rake::TestTask.new(:test) do |t|
5
5
  t.libs << "test"
6
6
  t.libs << "lib"
7
- t.test_files = FileList['test/**/*_test.rb']
7
+ t.test_files = FileList["test/**/*_test.rb"]
8
8
  end
9
9
 
10
- task :default => :test
10
+ task default: :test
@@ -1,3 +1,3 @@
1
1
  module Expand
2
- VERSION = "1.0.4"
2
+ VERSION = "1.0.5"
3
3
  end
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
@@ -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
- unless context.is_a?(Module)
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
- 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, ** }
97
104
  parent = class_or_module[:parent] || Object
105
+
98
106
  manager.create_class(creating_class, parent: parent, &block)
99
- when creating_module
100
- if class_or_module[:parent]
101
- warn "An option for :parent was provided as `#{class_or_module[:parent]}' but was ignored when creating the module: #{class_or_module[:module]}"
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.instance_eval(&block)
114
+ manager.apply(&block)
106
115
  end
107
116
  end
108
- alias expand namespace
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
4
+ version: 1.0.5
5
5
  platform: ruby
6
6
  authors:
7
- - "'Jim Gay'"
7
+ - Jim Gay
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-07-22 00:00:00.000000000 Z
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.3.17
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
@@ -1,8 +0,0 @@
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
@@ -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
@@ -1,9 +0,0 @@
1
- /.bundle/
2
- /.yardoc
3
- /Gemfile.lock
4
- /_yardoc/
5
- /coverage/
6
- /doc/
7
- /pkg/
8
- /spec/reports/
9
- /tmp/
data/Gemfile DELETED
@@ -1,8 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- # Specify your gem's dependencies in expand.gemspec
4
- gemspec
5
-
6
- gem "minitest"
7
- gem "simplecov"
8
- gem "rake"
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
@@ -1,8 +0,0 @@
1
- #!/usr/bin/env bash
2
- set -euo pipefail
3
- IFS=$'\n\t'
4
- set -vx
5
-
6
- bundle install
7
-
8
- # Do any other automated setup that you need to do here
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