boost.rb 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.devcontainer/devcontainer.json +22 -0
- data/.rspec +3 -0
- data/.rubocop.yml +15 -0
- data/CHANGELOG.md +5 -0
- data/CODE_OF_CONDUCT.md +132 -0
- data/LICENSE.txt +21 -0
- data/README.md +39 -0
- data/Rakefile +12 -0
- data/lib/boost/binding_extension.rb +29 -0
- data/lib/boost/dependency_injector.rb +51 -0
- data/lib/boost/method/signaturable.rb +92 -0
- data/lib/boost/module/configurable.rb +63 -0
- data/lib/boost/module/customizable.rb +40 -0
- data/lib/boost/module/toggleable.rb +33 -0
- data/lib/boost/version.rb +5 -0
- data/lib/boost.rb +23 -0
- data/sig/boost.rbs +4 -0
- metadata +77 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: fc027f25f8a6c2cecd36620604fc36975d6cfc76b90d5f72a2ffaec14dcbda04
|
4
|
+
data.tar.gz: c4efe4259be6494a7d699f9be36fe08c5135ddc56022303cb09c0c3af5460132
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4883196d3910819788e12fc9bea1219c0ab5c7b40049adadf0c09852c28b8b5aae4d17d4aa9d2483dbfa772e0c6aa16abc806ce8f99c1191553e3a6bc3a7cc16
|
7
|
+
data.tar.gz: b44d2fa2032b935cc149232fa819dc12dd9f7c5378fb1d73dfdca4ee9606a83e094bffb5d4532821deb814fa19d1243660273f492cca10487794efdba6cdca3b
|
@@ -0,0 +1,22 @@
|
|
1
|
+
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
|
2
|
+
// README at: https://github.com/devcontainers/templates/tree/main/src/ruby
|
3
|
+
{
|
4
|
+
"name": "Boost",
|
5
|
+
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
|
6
|
+
"image": "mcr.microsoft.com/devcontainers/ruby:1-3.3-bullseye"
|
7
|
+
|
8
|
+
// Features to add to the dev container. More info: https://containers.dev/features.
|
9
|
+
// "features": {},
|
10
|
+
|
11
|
+
// Use 'forwardPorts' to make a list of ports inside the container available locally.
|
12
|
+
// "forwardPorts": [],
|
13
|
+
|
14
|
+
// Use 'postCreateCommand' to run commands after the container is created.
|
15
|
+
// "postCreateCommand": "ruby --version",
|
16
|
+
|
17
|
+
// Configure tool-specific properties.
|
18
|
+
// "customizations": {},
|
19
|
+
|
20
|
+
// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
|
21
|
+
// "remoteUser": "root"
|
22
|
+
}
|
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require:
|
2
|
+
- rubocop-rake
|
3
|
+
- rubocop-rspec
|
4
|
+
|
5
|
+
AllCops:
|
6
|
+
TargetRubyVersion: 3.2
|
7
|
+
|
8
|
+
Style/StringLiterals:
|
9
|
+
EnforcedStyle: double_quotes
|
10
|
+
|
11
|
+
Style/StringLiteralsInInterpolation:
|
12
|
+
EnforcedStyle: double_quotes
|
13
|
+
|
14
|
+
Style/CaseEquality:
|
15
|
+
Enabled: false
|
data/CHANGELOG.md
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,132 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
We as members, contributors, and leaders pledge to make participation in our
|
6
|
+
community a harassment-free experience for everyone, regardless of age, body
|
7
|
+
size, visible or invisible disability, ethnicity, sex characteristics, gender
|
8
|
+
identity and expression, level of experience, education, socio-economic status,
|
9
|
+
nationality, personal appearance, race, caste, color, religion, or sexual
|
10
|
+
identity and orientation.
|
11
|
+
|
12
|
+
We pledge to act and interact in ways that contribute to an open, welcoming,
|
13
|
+
diverse, inclusive, and healthy community.
|
14
|
+
|
15
|
+
## Our Standards
|
16
|
+
|
17
|
+
Examples of behavior that contributes to a positive environment for our
|
18
|
+
community include:
|
19
|
+
|
20
|
+
* Demonstrating empathy and kindness toward other people
|
21
|
+
* Being respectful of differing opinions, viewpoints, and experiences
|
22
|
+
* Giving and gracefully accepting constructive feedback
|
23
|
+
* Accepting responsibility and apologizing to those affected by our mistakes,
|
24
|
+
and learning from the experience
|
25
|
+
* Focusing on what is best not just for us as individuals, but for the overall
|
26
|
+
community
|
27
|
+
|
28
|
+
Examples of unacceptable behavior include:
|
29
|
+
|
30
|
+
* The use of sexualized language or imagery, and sexual attention or advances of
|
31
|
+
any kind
|
32
|
+
* Trolling, insulting or derogatory comments, and personal or political attacks
|
33
|
+
* Public or private harassment
|
34
|
+
* Publishing others' private information, such as a physical or email address,
|
35
|
+
without their explicit permission
|
36
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
37
|
+
professional setting
|
38
|
+
|
39
|
+
## Enforcement Responsibilities
|
40
|
+
|
41
|
+
Community leaders are responsible for clarifying and enforcing our standards of
|
42
|
+
acceptable behavior and will take appropriate and fair corrective action in
|
43
|
+
response to any behavior that they deem inappropriate, threatening, offensive,
|
44
|
+
or harmful.
|
45
|
+
|
46
|
+
Community leaders have the right and responsibility to remove, edit, or reject
|
47
|
+
comments, commits, code, wiki edits, issues, and other contributions that are
|
48
|
+
not aligned to this Code of Conduct, and will communicate reasons for moderation
|
49
|
+
decisions when appropriate.
|
50
|
+
|
51
|
+
## Scope
|
52
|
+
|
53
|
+
This Code of Conduct applies within all community spaces, and also applies when
|
54
|
+
an individual is officially representing the community in public spaces.
|
55
|
+
Examples of representing our community include using an official email address,
|
56
|
+
posting via an official social media account, or acting as an appointed
|
57
|
+
representative at an online or offline event.
|
58
|
+
|
59
|
+
## Enforcement
|
60
|
+
|
61
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
62
|
+
reported to the community leaders responsible for enforcement at
|
63
|
+
[INSERT CONTACT METHOD].
|
64
|
+
All complaints will be reviewed and investigated promptly and fairly.
|
65
|
+
|
66
|
+
All community leaders are obligated to respect the privacy and security of the
|
67
|
+
reporter of any incident.
|
68
|
+
|
69
|
+
## Enforcement Guidelines
|
70
|
+
|
71
|
+
Community leaders will follow these Community Impact Guidelines in determining
|
72
|
+
the consequences for any action they deem in violation of this Code of Conduct:
|
73
|
+
|
74
|
+
### 1. Correction
|
75
|
+
|
76
|
+
**Community Impact**: Use of inappropriate language or other behavior deemed
|
77
|
+
unprofessional or unwelcome in the community.
|
78
|
+
|
79
|
+
**Consequence**: A private, written warning from community leaders, providing
|
80
|
+
clarity around the nature of the violation and an explanation of why the
|
81
|
+
behavior was inappropriate. A public apology may be requested.
|
82
|
+
|
83
|
+
### 2. Warning
|
84
|
+
|
85
|
+
**Community Impact**: A violation through a single incident or series of
|
86
|
+
actions.
|
87
|
+
|
88
|
+
**Consequence**: A warning with consequences for continued behavior. No
|
89
|
+
interaction with the people involved, including unsolicited interaction with
|
90
|
+
those enforcing the Code of Conduct, for a specified period of time. This
|
91
|
+
includes avoiding interactions in community spaces as well as external channels
|
92
|
+
like social media. Violating these terms may lead to a temporary or permanent
|
93
|
+
ban.
|
94
|
+
|
95
|
+
### 3. Temporary Ban
|
96
|
+
|
97
|
+
**Community Impact**: A serious violation of community standards, including
|
98
|
+
sustained inappropriate behavior.
|
99
|
+
|
100
|
+
**Consequence**: A temporary ban from any sort of interaction or public
|
101
|
+
communication with the community for a specified period of time. No public or
|
102
|
+
private interaction with the people involved, including unsolicited interaction
|
103
|
+
with those enforcing the Code of Conduct, is allowed during this period.
|
104
|
+
Violating these terms may lead to a permanent ban.
|
105
|
+
|
106
|
+
### 4. Permanent Ban
|
107
|
+
|
108
|
+
**Community Impact**: Demonstrating a pattern of violation of community
|
109
|
+
standards, including sustained inappropriate behavior, harassment of an
|
110
|
+
individual, or aggression toward or disparagement of classes of individuals.
|
111
|
+
|
112
|
+
**Consequence**: A permanent ban from any sort of public interaction within the
|
113
|
+
community.
|
114
|
+
|
115
|
+
## Attribution
|
116
|
+
|
117
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
118
|
+
version 2.1, available at
|
119
|
+
[https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
|
120
|
+
|
121
|
+
Community Impact Guidelines were inspired by
|
122
|
+
[Mozilla's code of conduct enforcement ladder][Mozilla CoC].
|
123
|
+
|
124
|
+
For answers to common questions about this code of conduct, see the FAQ at
|
125
|
+
[https://www.contributor-covenant.org/faq][FAQ]. Translations are available at
|
126
|
+
[https://www.contributor-covenant.org/translations][translations].
|
127
|
+
|
128
|
+
[homepage]: https://www.contributor-covenant.org
|
129
|
+
[v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
|
130
|
+
[Mozilla CoC]: https://github.com/mozilla/diversity
|
131
|
+
[FAQ]: https://www.contributor-covenant.org/faq
|
132
|
+
[translations]: https://www.contributor-covenant.org/translations
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2024 lychee xing
|
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
|
13
|
+
all 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
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# Boost
|
2
|
+
|
3
|
+
TODO: Delete this and the text below, and describe your gem
|
4
|
+
|
5
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/boost`. To experiment with that code, run `bin/console` for an interactive prompt.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
|
10
|
+
|
11
|
+
Install the gem and add to the application's Gemfile by executing:
|
12
|
+
|
13
|
+
$ bundle add UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
|
14
|
+
|
15
|
+
If bundler is not being used to manage dependencies, install the gem by executing:
|
16
|
+
|
17
|
+
$ gem install UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Development
|
24
|
+
|
25
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
26
|
+
|
27
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
28
|
+
|
29
|
+
## Contributing
|
30
|
+
|
31
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/boost. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/boost/blob/master/CODE_OF_CONDUCT.md).
|
32
|
+
|
33
|
+
## License
|
34
|
+
|
35
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
36
|
+
|
37
|
+
## Code of Conduct
|
38
|
+
|
39
|
+
Everyone interacting in the Boost project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/boost/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Boost
|
4
|
+
module BindingExtension
|
5
|
+
def boost(*, **, &)
|
6
|
+
Boost.new(self, *, **).self_or_call(&)
|
7
|
+
end
|
8
|
+
|
9
|
+
class Boost
|
10
|
+
def initialize(binding)
|
11
|
+
@binding = binding
|
12
|
+
@nesting = binding.eval("Module.nesting")
|
13
|
+
end
|
14
|
+
|
15
|
+
module Callable
|
16
|
+
def self_or_call(&) = block_given? ? call(&) : self
|
17
|
+
def call(&) = yield
|
18
|
+
end
|
19
|
+
include Callable
|
20
|
+
|
21
|
+
module DependencyInjectable
|
22
|
+
def dependency_injector = @dependency_injector ||= DependencyInjector.new(@binding)
|
23
|
+
alias deps dependency_injector
|
24
|
+
def call(&) = super { dependency_injector.block_call(&) }
|
25
|
+
end
|
26
|
+
include DependencyInjectable
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "forwardable"
|
4
|
+
|
5
|
+
module Boost
|
6
|
+
class DependencyInjector
|
7
|
+
extend Forwardable
|
8
|
+
extend Enumerable
|
9
|
+
|
10
|
+
def_delegators :@deps, *%i[
|
11
|
+
key? keys values each empty? size length values_at fetch fetch_values []=
|
12
|
+
]
|
13
|
+
|
14
|
+
def initialize(binding, deps = {})
|
15
|
+
@binding = binding
|
16
|
+
@deps = deps
|
17
|
+
end
|
18
|
+
|
19
|
+
def [](name)
|
20
|
+
@deps[name].tap do |dep|
|
21
|
+
if dep.is_a?(::Proc)
|
22
|
+
return dep.call(*(dep.arity.zero? ? [] : [@binding.receiver]))
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def block_call(*args, **kwargs, &block)
|
28
|
+
block.parameters.each_with_index do |(type, name), i|
|
29
|
+
next unless key?(name)
|
30
|
+
|
31
|
+
case type
|
32
|
+
when :req, :opt then args[i] = self[name]
|
33
|
+
when :keyreq, :key then kwargs[name] = self[name]
|
34
|
+
end
|
35
|
+
end
|
36
|
+
yield(*args, **kwargs)
|
37
|
+
end
|
38
|
+
|
39
|
+
def method_call(method_name, *args, **kwargs)
|
40
|
+
@binding.receiver.method(method_name).parameters.each_with_index do |(type, name), i|
|
41
|
+
next unless key?(name)
|
42
|
+
|
43
|
+
case type
|
44
|
+
when :req, :opt then args[i] = self[name]
|
45
|
+
when :keyreq, :key then kwargs[name] = self[name]
|
46
|
+
end
|
47
|
+
end
|
48
|
+
@binding.receiver.send(method_name, *args, **kwargs)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,92 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Boost
|
4
|
+
module Method
|
5
|
+
module Signaturable
|
6
|
+
class Signature
|
7
|
+
def initialize(binding)
|
8
|
+
@binding = binding
|
9
|
+
@runtime_check = true
|
10
|
+
end
|
11
|
+
|
12
|
+
def runtime_check? = @runtime_check
|
13
|
+
|
14
|
+
def receives!(*types, **kwtypes)
|
15
|
+
@types = types.map { |type| required(type) }
|
16
|
+
@kwtypes = kwtypes.map do |name, type|
|
17
|
+
if name[-1] == "?"
|
18
|
+
[name[0..-2].to_sym, optional(type)]
|
19
|
+
else
|
20
|
+
[name, required(type)]
|
21
|
+
end
|
22
|
+
end.to_h
|
23
|
+
end
|
24
|
+
|
25
|
+
def returns!(type)
|
26
|
+
@returns_type = required(type)
|
27
|
+
end
|
28
|
+
|
29
|
+
def call(&)
|
30
|
+
return yield unless runtime_check?
|
31
|
+
|
32
|
+
check_arguments!
|
33
|
+
check_keywords!
|
34
|
+
check_returns!(yield)
|
35
|
+
end
|
36
|
+
|
37
|
+
protected
|
38
|
+
|
39
|
+
def check_arguments!
|
40
|
+
@types&.each_with_index do |type, i|
|
41
|
+
value = @binding.local_variable_get(@binding.local_variables[i])
|
42
|
+
raise TypeError, "Type Error: argument `#{name}` is not match #{type.inspect}" unless type === value
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def check_keywords!
|
47
|
+
@kwtypes&.each do |name, type|
|
48
|
+
value = @binding.local_variable_get(name)
|
49
|
+
raise TypeError, "Type Error: keyword `#{name}` is not match #{type.inspect}" unless type === value
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def check_returns!(value)
|
54
|
+
return value if !defined?(@returns_type) || @returns_type === value
|
55
|
+
|
56
|
+
raise TypeError, "Type Error: return value is not match #{type.inspect}"
|
57
|
+
end
|
58
|
+
|
59
|
+
def required(type) = any_of(type)
|
60
|
+
def optional(type) = any_of(nil, type)
|
61
|
+
|
62
|
+
def any_of(*types)
|
63
|
+
raise ArgumentError, "requires at least one argument" if types.empty?
|
64
|
+
|
65
|
+
->(value) { types.any? { |type| type === value } }
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
module BoostMethods
|
70
|
+
def receives(*, **, &)
|
71
|
+
signature.receives!(*, **)
|
72
|
+
self_or_call(&)
|
73
|
+
end
|
74
|
+
|
75
|
+
def returns(*, **, &)
|
76
|
+
signature.returns!(*, **)
|
77
|
+
self_or_call(&)
|
78
|
+
end
|
79
|
+
|
80
|
+
def call(&)
|
81
|
+
defined?(@signature) ? @signature.call { super(&) } : super
|
82
|
+
end
|
83
|
+
|
84
|
+
protected
|
85
|
+
|
86
|
+
def signature = @signature ||= Signature.new(@binding)
|
87
|
+
end
|
88
|
+
|
89
|
+
BindingExtension::Boost.include BoostMethods
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Boost
|
4
|
+
module Module
|
5
|
+
module Configurable
|
6
|
+
class Configurations < Hash
|
7
|
+
def respond_to_missing?(name, include_private = false)
|
8
|
+
key = name[-1] == "=" ? name[0..-2].to_sym : name.to_sym
|
9
|
+
key?(key) || super
|
10
|
+
end
|
11
|
+
|
12
|
+
def method_missing(name, *args, &)
|
13
|
+
if name[-1] == "="
|
14
|
+
key = name[0..-2].to_sym
|
15
|
+
value = self[key] = args.first
|
16
|
+
# self.class.class_eval <<~RUBY, __FILE__, __LINE__ + 1
|
17
|
+
# def #{name}(value)
|
18
|
+
# self[#{key.inspect}] = value
|
19
|
+
# end
|
20
|
+
# RUBY
|
21
|
+
else
|
22
|
+
key = name.to_sym
|
23
|
+
value = self[key]
|
24
|
+
# self.class.class_eval <<~RUBY, __FILE__, __LINE__ + 1
|
25
|
+
# def #{name} = self[#{key.inspect}]
|
26
|
+
# RUBY
|
27
|
+
end
|
28
|
+
value
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def config = @config ||= Configurations.new
|
33
|
+
def configure(**) = config.merge!(**)
|
34
|
+
|
35
|
+
def initialize_copy(source)
|
36
|
+
super
|
37
|
+
@config = Configurations.new { |_h, k| source.config[k] }
|
38
|
+
end
|
39
|
+
|
40
|
+
module ClassHookMethods
|
41
|
+
def inherited(subclass)
|
42
|
+
super
|
43
|
+
subclass.instance_variable_set(:@config, Configurations.new { |_h, k| config[k] })
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def self.extended(base)
|
48
|
+
base.extend ClassHookMethods if base.is_a?(::Class)
|
49
|
+
end
|
50
|
+
|
51
|
+
module BoostMethods
|
52
|
+
def call(&)
|
53
|
+
mod, = @nesting
|
54
|
+
deps[:module_config] = mod.config if mod.respond_to?(:config)
|
55
|
+
|
56
|
+
super
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
BindingExtension::Boost.include BoostMethods
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Boost
|
4
|
+
module Module
|
5
|
+
module Customizable
|
6
|
+
attr_reader :original
|
7
|
+
|
8
|
+
def initialize_copy(source)
|
9
|
+
super
|
10
|
+
set_temporary_name("#{source.name}[**customize**]")
|
11
|
+
|
12
|
+
@original ||= source
|
13
|
+
end
|
14
|
+
|
15
|
+
def initialize_customize(...) end
|
16
|
+
|
17
|
+
def customize(...)
|
18
|
+
clone.tap { |customized| customized.initialize_customize(...) }
|
19
|
+
end
|
20
|
+
alias [] customize
|
21
|
+
|
22
|
+
module WithConfigurable
|
23
|
+
def initialize_copy(source)
|
24
|
+
super
|
25
|
+
|
26
|
+
@config = @original.config.dup
|
27
|
+
end
|
28
|
+
|
29
|
+
def initialize_customize(*, **, &)
|
30
|
+
configure(**)
|
31
|
+
super
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.extended(base)
|
36
|
+
base.extend(WithConfigurable) if base.is_a?(Configurable)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Boost
|
4
|
+
module Module
|
5
|
+
module Toggleable
|
6
|
+
def on! = @disabled = false
|
7
|
+
def on? = !@disabled
|
8
|
+
def off! = @disabled = true
|
9
|
+
def off? = @disabled
|
10
|
+
|
11
|
+
module BoostMethods
|
12
|
+
def call(&)
|
13
|
+
mod, = @nesting
|
14
|
+
if mod.nil?
|
15
|
+
# boost.logger.warn "method defined in anonymous module or class, skipping"
|
16
|
+
return super
|
17
|
+
elsif !mod.singleton_class.include?(Toggleable) || mod.on?
|
18
|
+
return super
|
19
|
+
end
|
20
|
+
|
21
|
+
@binding.eval <<~RUBY
|
22
|
+
return super if defined?(super)
|
23
|
+
e = NoMethodError.new("undefined method `\#{__callee__}' for \#{self.inspect}")
|
24
|
+
e.set_backtrace(caller[3..-1])
|
25
|
+
raise(e)
|
26
|
+
RUBY
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
BindingExtension::Boost.include BoostMethods
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
data/lib/boost.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "zeitwerk"
|
4
|
+
require "logger"
|
5
|
+
|
6
|
+
module Boost
|
7
|
+
class << self
|
8
|
+
attr_writer :logger
|
9
|
+
|
10
|
+
def logger
|
11
|
+
@logger ||= Logger.new($stdout).tap do |log|
|
12
|
+
log.progname = name
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def loader
|
17
|
+
@loader ||= Zeitwerk::Loader.for_gem
|
18
|
+
end
|
19
|
+
end
|
20
|
+
loader.setup
|
21
|
+
|
22
|
+
::Binding.include(BindingExtension)
|
23
|
+
end
|
data/sig/boost.rbs
ADDED
metadata
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: boost.rb
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- lychee xing
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2024-11-05 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: zeitwerk
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 2.7.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 2.7.0
|
27
|
+
description:
|
28
|
+
email:
|
29
|
+
- lolychee@gmail.com
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- ".devcontainer/devcontainer.json"
|
35
|
+
- ".rspec"
|
36
|
+
- ".rubocop.yml"
|
37
|
+
- CHANGELOG.md
|
38
|
+
- CODE_OF_CONDUCT.md
|
39
|
+
- LICENSE.txt
|
40
|
+
- README.md
|
41
|
+
- Rakefile
|
42
|
+
- lib/boost.rb
|
43
|
+
- lib/boost/binding_extension.rb
|
44
|
+
- lib/boost/dependency_injector.rb
|
45
|
+
- lib/boost/method/signaturable.rb
|
46
|
+
- lib/boost/module/configurable.rb
|
47
|
+
- lib/boost/module/customizable.rb
|
48
|
+
- lib/boost/module/toggleable.rb
|
49
|
+
- lib/boost/version.rb
|
50
|
+
- sig/boost.rbs
|
51
|
+
homepage: https://github.com/lolychee/boost
|
52
|
+
licenses:
|
53
|
+
- MIT
|
54
|
+
metadata:
|
55
|
+
homepage_uri: https://github.com/lolychee/boost
|
56
|
+
source_code_uri: https://github.com/lolychee/boost
|
57
|
+
changelog_uri: https://github.com/lolychee/boost/blob/main/CHANGELOG.md
|
58
|
+
post_install_message:
|
59
|
+
rdoc_options: []
|
60
|
+
require_paths:
|
61
|
+
- lib
|
62
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: 3.2.0
|
67
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '0'
|
72
|
+
requirements: []
|
73
|
+
rubygems_version: 3.5.16
|
74
|
+
signing_key:
|
75
|
+
specification_version: 4
|
76
|
+
summary: Boost helps you write simpler, more modular, and flexible Ruby code.
|
77
|
+
test_files: []
|