const_set_p 0.1.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 874772c1885f6181df8fb3e295d1585bc4449f019db8956929d06bd27df40d2d
4
+ data.tar.gz: b194088ef1196ad87771c165a71caabf2060101fe6f622d5eb2b985f5db3747f
5
+ SHA512:
6
+ metadata.gz: cece658f04b564c7ab8eeac5aa7f28433c37ad2a99bfd98eea39a714b326cf58442b306e2efa5ba5ca3204eaf3ebd869a24450c3c7b1d915215fd59481cbdcd6
7
+ data.tar.gz: '087434ffaa3471398f32cf69f300c6bc3fc1c4bc02975a0975fb7cb4a47c1239649252db3d89f2cf9538f9fa1f7098fbf1fbaa2c13a28de013dd811535560a70'
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,22 @@
1
+ inherit_from: .rubocop_todo.yml
2
+
3
+ plugins:
4
+ - rubocop-performance
5
+ - rubocop-rake
6
+ - rubocop-rspec
7
+
8
+ AllCops:
9
+ NewCops: enable
10
+ TargetRubyVersion: 2.7
11
+
12
+ Style/StringLiterals:
13
+ EnforcedStyle: double_quotes
14
+
15
+ Style/StringLiteralsInInterpolation:
16
+ EnforcedStyle: double_quotes
17
+
18
+ RSpec/NamedSubject:
19
+ Enabled: false
20
+
21
+ RSpec/NestedGroups:
22
+ Max: 5
data/.rubocop_todo.yml ADDED
@@ -0,0 +1,15 @@
1
+ # This configuration was generated by
2
+ # `rubocop --auto-gen-config`
3
+ # on 2026-03-18 02:18:05 UTC using RuboCop version 1.85.1.
4
+ # The point is for the user to remove these configuration records
5
+ # one by one as the offenses are removed from the code base.
6
+ # Note that changes in the inspected code, or installation of new
7
+ # versions of RuboCop, may require this file to be generated again.
8
+
9
+ # Offense count: 1
10
+ # Configuration parameters: AllowedConstants.
11
+ Style/Documentation:
12
+ Exclude:
13
+ - 'spec/**/*'
14
+ - 'test/**/*'
15
+ - 'lib/const_set_p/core_ext/module.rb'
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2026-03-17
4
+
5
+ - Initial release
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 epaew
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,51 @@
1
+ # const_set_p.rb
2
+
3
+ Provides `Module#const_set_p`, which is a wrapper method for `Module#const_set`, it acts like `mkdir -p` does for `mkdir`.
4
+
5
+ ## Installation
6
+
7
+ Install the gem and add to the application's Gemfile by executing:
8
+
9
+ ```bash
10
+ bundle add const_set_p
11
+ ```
12
+
13
+ If bundler is not being used to manage dependencies, install the gem by executing:
14
+
15
+ ```bash
16
+ gem install const_set_p
17
+ ```
18
+
19
+ ## Usage
20
+
21
+ ```ruby
22
+ require "const_set_p"
23
+
24
+ module M
25
+ C = Class.new
26
+ S = "str"
27
+
28
+ # Ruby's `Module#const_set` raises NameError if the name contains `::`.
29
+ const_set("N::O", Class.new)
30
+ const_set("C::D", Class.new)
31
+
32
+ # `Module#const_set_p` automatically defines all intermediate modules.
33
+ # i.e. The code below defines `M::N`, `M::N::O` and `M::N::O::P`.
34
+ const_set_p("N::O::P", Class.new)
35
+
36
+ # Respects pre-defined classes and modules.
37
+ # i.e. The code below does not replace the pre-defined `M::C` class.
38
+ const_set_p("C::D", Class.new)
39
+
40
+ # Raises NameError if the specified intermediate constant is pre-defined, and is neither a Class nor a Module.
41
+ const_set_p("S::T", Class.new)
42
+ end
43
+ ```
44
+
45
+ ## Development
46
+
47
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
48
+
49
+ ## Contributing
50
+
51
+ Bug reports and pull requests are welcome on GitHub at https://github.com/epaew/const_set_p.rb.
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+ require "rubocop/rake_task"
6
+ require "steep/rake_task"
7
+
8
+ RSpec::Core::RakeTask.new(:rspec)
9
+ RuboCop::RakeTask.new
10
+ Steep::RakeTask.new
11
+
12
+ task default: %i[rubocop steep rspec]
data/Steepfile ADDED
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ # D = Steep::Diagnostic
4
+ #
5
+ # target :lib do
6
+ # signature "sig"
7
+ #
8
+ # check "lib" # Directory name
9
+ # check "Gemfile" # File name
10
+ # check "app/models/**/*.rb" # Glob
11
+ # # ignore "lib/templates/*.rb"
12
+ #
13
+ # # library "pathname" # Standard libraries
14
+ # # library "strong_json" # Gems
15
+ #
16
+ # # configure_code_diagnostics(D::Ruby.default) # `default` diagnostics setting (applies by default)
17
+ # # configure_code_diagnostics(D::Ruby.strict) # `strict` diagnostics setting
18
+ # # configure_code_diagnostics(D::Ruby.lenient) # `lenient` diagnostics setting
19
+ # # configure_code_diagnostics(D::Ruby.silent) # `silent` diagnostics setting
20
+ # # configure_code_diagnostics do |hash| # You can setup everything yourself
21
+ # # hash[D::Ruby::NoMethod] = :information
22
+ # # end
23
+ # end
24
+
25
+ # target :test do
26
+ # signature "sig", "sig-private"
27
+ #
28
+ # check "test"
29
+ #
30
+ # # library "pathname" # Standard libraries
31
+ # end
32
+
33
+ target :lib do
34
+ check "lib"
35
+ signature "sig"
36
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Module
4
+ def const_set_p(name, value)
5
+ first, rest = name.to_s.split("::", 2)
6
+ raise NameError, "wrong constant name " unless first
7
+ return const_set(first, value) unless rest
8
+
9
+ submod =
10
+ const_defined?(first, false) ? const_get(first, false) : const_set(first, Module.new)
11
+ raise NameError, "#{self.name}::#{first} is not a Module or Class" unless submod.is_a?(Module)
12
+
13
+ submod.const_set_p(rest, value)
14
+ end
15
+ end
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "core_ext/module"
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ConstSetP
4
+ VERSION = "0.1.0"
5
+ end
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "const_set_p/core_ext"
4
+ require_relative "const_set_p/version"
@@ -0,0 +1,3 @@
1
+ module ConstSetP
2
+ VERSION: String
3
+ end
data/sig/module.rbs ADDED
@@ -0,0 +1,3 @@
1
+ class Module
2
+ def const_set_p: (String | Symbol name, untyped value) -> untyped
3
+ end
metadata ADDED
@@ -0,0 +1,64 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: const_set_p
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - epaew
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2026-03-18 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Provides `Module#const_set_p`, a wrapper method for `Module#const_set`,
14
+ it acts like `mkdir -p` does for `mkdir`.
15
+ email:
16
+ - epaew.333@gmail.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - ".rspec"
22
+ - ".rubocop.yml"
23
+ - ".rubocop_todo.yml"
24
+ - CHANGELOG.md
25
+ - LICENSE
26
+ - README.md
27
+ - Rakefile
28
+ - Steepfile
29
+ - lib/const_set_p.rb
30
+ - lib/const_set_p/core_ext.rb
31
+ - lib/const_set_p/core_ext/module.rb
32
+ - lib/const_set_p/version.rb
33
+ - sig/const_set_p.rbs
34
+ - sig/module.rbs
35
+ homepage: https://github.com/epaew/const_set_p.rb
36
+ licenses:
37
+ - MIT
38
+ metadata:
39
+ allowed_push_host: https://rubygems.org
40
+ homepage_uri: https://github.com/epaew/const_set_p.rb
41
+ source_code_uri: https://github.com/epaew/const_set_p.rb
42
+ changelog_uri: https://github.com/epaew/const_set_p.rb/blob/master/CHANGELOG.md
43
+ rubygems_mfa_required: 'true'
44
+ post_install_message:
45
+ rdoc_options: []
46
+ require_paths:
47
+ - lib
48
+ required_ruby_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: 2.7.0
53
+ required_rubygems_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
58
+ requirements: []
59
+ rubygems_version: 3.2.33
60
+ signing_key:
61
+ specification_version: 4
62
+ summary: Provides `Module#const_set_p`, a wrapper method for `Module#const_set`, it
63
+ acts like `mkdir -p` does for `mkdir`.
64
+ test_files: []