import_from 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 +7 -0
- data/.claude/commands/document.md +105 -0
- data/.claude/commands/gemfile/update.md +52 -0
- data/.claude/commands/test.md +561 -0
- data/.claude/docs/yard.md +602 -0
- data/.claude/settings.local.json +16 -0
- data/.editorconfig +11 -0
- data/.env +1 -0
- data/.overcommit.yml +31 -0
- data/.rspec +3 -0
- data/.rubocop.yml +77 -0
- data/.yardstick.yml +22 -0
- data/AGENTS.md +157 -0
- data/CHANGELOG.md +14 -0
- data/CLAUDE.md +1 -0
- data/CODE_OF_CONDUCT.md +10 -0
- data/Guardfile +23 -0
- data/LICENSE.txt +21 -0
- data/README.md +129 -0
- data/Rakefile +97 -0
- data/Steepfile +7 -0
- data/docs/ruby-box.md +361 -0
- data/docs/todo.md +42 -0
- data/examples/Gemfile +5 -0
- data/examples/Gemfile.lock +26 -0
- data/examples/README.md +15 -0
- data/examples/from_x_import_star.rb +11 -0
- data/examples/from_x_import_star_as_y.rb +11 -0
- data/examples/from_x_import_y.rb +11 -0
- data/examples/from_x_import_y_as_z.rb +11 -0
- data/examples/from_x_y_import_a.rb +11 -0
- data/examples/from_x_y_import_a_as_b.rb +11 -0
- data/examples/import_x.rb +11 -0
- data/examples/import_x_as_y.rb +11 -0
- data/examples/import_x_as_y_scoped.rb +13 -0
- data/examples/import_x_y_z.rb +11 -0
- data/lib/import_from/core_ext/kernel.rb +114 -0
- data/lib/import_from/version.rb +5 -0
- data/lib/import_from.rb +10 -0
- data/mise.toml +2 -0
- data/sig/import_from.rbs +4 -0
- metadata +86 -0
data/.rubocop.yml
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
plugins:
|
|
2
|
+
- rubocop-performance
|
|
3
|
+
- rubocop-rake
|
|
4
|
+
- rubocop-rspec
|
|
5
|
+
|
|
6
|
+
AllCops:
|
|
7
|
+
TargetRubyVersion: 4.0
|
|
8
|
+
DisplayCopNames: true
|
|
9
|
+
NewCops: enable
|
|
10
|
+
|
|
11
|
+
# ----------------------- Gemspec -----------------------
|
|
12
|
+
|
|
13
|
+
Gemspec/DevelopmentDependencies:
|
|
14
|
+
Enabled: false
|
|
15
|
+
|
|
16
|
+
# ----------------------- Style -----------------------
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
Style/DocumentDynamicEvalDefinition:
|
|
20
|
+
Exclude:
|
|
21
|
+
- lib/import_from/core_ext/kernel.rb
|
|
22
|
+
|
|
23
|
+
Style/MixinUsage:
|
|
24
|
+
Exclude:
|
|
25
|
+
- bin/console
|
|
26
|
+
|
|
27
|
+
Style/StringLiterals:
|
|
28
|
+
Enabled: true
|
|
29
|
+
EnforcedStyle: single_quotes
|
|
30
|
+
|
|
31
|
+
Style/StringLiteralsInInterpolation:
|
|
32
|
+
Enabled: true
|
|
33
|
+
EnforcedStyle: double_quotes
|
|
34
|
+
|
|
35
|
+
# ----------------------- Layout ----------------------
|
|
36
|
+
|
|
37
|
+
Layout/LineLength:
|
|
38
|
+
Max: 120
|
|
39
|
+
Exclude:
|
|
40
|
+
- import_from.gemspec
|
|
41
|
+
|
|
42
|
+
# ---------------------- Metrics ----------------------
|
|
43
|
+
|
|
44
|
+
Metrics/AbcSize:
|
|
45
|
+
Enabled: false
|
|
46
|
+
|
|
47
|
+
Metrics/BlockLength:
|
|
48
|
+
Enabled: false
|
|
49
|
+
|
|
50
|
+
Metrics/CyclomaticComplexity:
|
|
51
|
+
Enabled: false
|
|
52
|
+
|
|
53
|
+
Metrics/ClassLength:
|
|
54
|
+
Enabled: false
|
|
55
|
+
|
|
56
|
+
Metrics/MethodLength:
|
|
57
|
+
Enabled: false
|
|
58
|
+
|
|
59
|
+
Metrics/ParameterLists:
|
|
60
|
+
CountKeywordArgs: false
|
|
61
|
+
|
|
62
|
+
Metrics/PerceivedComplexity:
|
|
63
|
+
Enabled: false
|
|
64
|
+
|
|
65
|
+
# ----------------------- RSpec -----------------------
|
|
66
|
+
|
|
67
|
+
RSpec/ExampleLength:
|
|
68
|
+
Enabled: false
|
|
69
|
+
|
|
70
|
+
RSpec/NestedGroups:
|
|
71
|
+
Enabled: false
|
|
72
|
+
|
|
73
|
+
RSpec/MultipleMemoizedHelpers:
|
|
74
|
+
Enabled: false
|
|
75
|
+
|
|
76
|
+
RSpec/MultipleExpectations:
|
|
77
|
+
Enabled: false
|
data/.yardstick.yml
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
threshold: 100
|
|
2
|
+
rules:
|
|
3
|
+
ApiTag::Presence:
|
|
4
|
+
enabled: true
|
|
5
|
+
ApiTag::Inclusion:
|
|
6
|
+
enabled: true
|
|
7
|
+
ApiTag::ProtectedMethod:
|
|
8
|
+
enabled: true
|
|
9
|
+
ApiTag::PrivateMethod:
|
|
10
|
+
enabled: true
|
|
11
|
+
ExampleTag:
|
|
12
|
+
enabled: true
|
|
13
|
+
ReturnTag:
|
|
14
|
+
enabled: true
|
|
15
|
+
Summary::Presence:
|
|
16
|
+
enabled: true
|
|
17
|
+
Summary::Length:
|
|
18
|
+
enabled: false
|
|
19
|
+
Summary::Delimiter:
|
|
20
|
+
enabled: true
|
|
21
|
+
Summary::SingleLine:
|
|
22
|
+
enabled: false
|
data/AGENTS.md
ADDED
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
# AGENTS.md
|
|
2
|
+
|
|
3
|
+
This file provides guidance to WARP (warp.dev), Gemini CLI and Claude Code when working with code in this repository.
|
|
4
|
+
|
|
5
|
+
## Project Overview
|
|
6
|
+
|
|
7
|
+
`import_from` is a Ruby gem that provides Python-like import syntax for Ruby modules and classes. It leverages Ruby::Box (Ruby 4.0+ feature) to create isolated namespaces, preventing conflicts between different versions of gems and their dependencies.
|
|
8
|
+
|
|
9
|
+
**Critical requirement**: All code execution requires Ruby 4.0+ with `RUBY_BOX=1` environment variable set.
|
|
10
|
+
|
|
11
|
+
## Common Commands
|
|
12
|
+
|
|
13
|
+
### Running Code
|
|
14
|
+
All Ruby code must be executed with Ruby::Box enabled:
|
|
15
|
+
```bash
|
|
16
|
+
RUBY_BOX=1 ruby -W:no-experimental <file.rb>
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
The `-W:no-experimental` flag suppresses the experimental feature warning.
|
|
20
|
+
|
|
21
|
+
### Development Setup
|
|
22
|
+
```bash
|
|
23
|
+
bin/setup # Install dependencies
|
|
24
|
+
bin/console # Interactive console with gem loaded
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
### Testing
|
|
28
|
+
```bash
|
|
29
|
+
bundle exec rake spec # Run all tests
|
|
30
|
+
bundle exec rake coverage # Run tests with coverage report
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
### Code Quality
|
|
34
|
+
```bash
|
|
35
|
+
bundle exec rake # Run default task (spec + rubocop)
|
|
36
|
+
bundle exec rake qa # Full quality audit (rspec, rubocop, yard:junk, verify_measurements, bundle:audit)
|
|
37
|
+
bundle exec rake rubocop # Run RuboCop linter
|
|
38
|
+
bundle exec rake rubocop:autocorrect # Auto-fix safe RuboCop offenses
|
|
39
|
+
bundle exec rake rubocop:autocorrect_all # Auto-fix all RuboCop offenses
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### Type Checking
|
|
43
|
+
```bash
|
|
44
|
+
bundle exec steep check # Validate RBS type definitions
|
|
45
|
+
bundle exec typeprof <file> # Generate RBS definition for a Ruby file
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### Documentation
|
|
49
|
+
```bash
|
|
50
|
+
bundle exec rake yard # Generate YARD documentation
|
|
51
|
+
bundle exec rake yard:format # Format YARD documentation tags
|
|
52
|
+
bundle exec rake yard:junk # Check for documentation issues
|
|
53
|
+
bundle exec rake yardstick_measure # Measure documentation coverage
|
|
54
|
+
bundle exec rake verify_measurements # Verify 100% documentation coverage
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
### Security & Dependencies
|
|
58
|
+
```bash
|
|
59
|
+
bundle exec rake bundle:audit:check # Check for security vulnerabilities
|
|
60
|
+
bundle exec rake bundle:audit:update # Update vulnerability database
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### Release
|
|
64
|
+
```bash
|
|
65
|
+
bundle exec rake release # Create tag, build gem, push to rubygems.org
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## Architecture
|
|
69
|
+
|
|
70
|
+
### Core Components
|
|
71
|
+
|
|
72
|
+
**Ruby::Box Integration** (`lib/import_from.rb`)
|
|
73
|
+
- Entry point that enforces `RUBY_BOX=1` is set
|
|
74
|
+
- Raises an error immediately if Ruby::Box is not enabled
|
|
75
|
+
- Loads the Kernel extensions that provide import syntax
|
|
76
|
+
|
|
77
|
+
**Kernel Extensions** (`lib/import_from/core_ext/kernel.rb`)
|
|
78
|
+
- Defines two main methods: `from()` and `import()`
|
|
79
|
+
- Creates isolated Ruby::Box instances to load gems/modules
|
|
80
|
+
- Handles constant extraction and namespace injection
|
|
81
|
+
|
|
82
|
+
### How It Works
|
|
83
|
+
|
|
84
|
+
The gem extends Ruby's `Kernel` module with two methods that mimic Python's import patterns:
|
|
85
|
+
|
|
86
|
+
1. **`from(gem_name, import:, as:)`** - Import specific constants from a gem
|
|
87
|
+
- Creates a new isolated Ruby::Box
|
|
88
|
+
- Copies `$LOAD_PATH` into the box
|
|
89
|
+
- Requires the gem inside the box
|
|
90
|
+
- Extracts requested constants and injects them into `Object`
|
|
91
|
+
- Supports wildcard imports with `import: '*'`
|
|
92
|
+
|
|
93
|
+
2. **`import(imports, from:, as:)`** - Flexible import with optional aliasing
|
|
94
|
+
- Wrapper around `from()` with more Pythonic parameter order
|
|
95
|
+
- When `from:` is nil, imports entire gem namespace
|
|
96
|
+
- Allows aliasing the box itself with `as:`
|
|
97
|
+
|
|
98
|
+
### Ruby::Box Isolation
|
|
99
|
+
|
|
100
|
+
Ruby::Box (experimental Ruby 4.0 feature) provides process-level namespace isolation:
|
|
101
|
+
- Each box has its own set of constants, class variables, and global variables
|
|
102
|
+
- Built-in classes can be monkey-patched within a box without affecting other boxes
|
|
103
|
+
- Changes made in one box don't leak to other boxes or the main namespace
|
|
104
|
+
- All code in a single `.rb` file runs in the same box
|
|
105
|
+
|
|
106
|
+
Key limitations to be aware of:
|
|
107
|
+
- Experimental feature requiring `RUBY_BOX=1` at Ruby process startup
|
|
108
|
+
- Native extension installation may fail (stack level too deep)
|
|
109
|
+
- `require 'active_support/core_ext'` may fail under Ruby::Box
|
|
110
|
+
- Built-in methods won't see monkey-patched methods from user boxes
|
|
111
|
+
|
|
112
|
+
## Code Style Guidelines
|
|
113
|
+
|
|
114
|
+
### RuboCop Configuration
|
|
115
|
+
- Target Ruby version: 4.0
|
|
116
|
+
- String literals: Single quotes (enforced)
|
|
117
|
+
- String interpolation: Double quotes (enforced)
|
|
118
|
+
- Line length: 120 characters max
|
|
119
|
+
- Most Metrics cops disabled (AbcSize, BlockLength, CyclomaticComplexity, MethodLength, etc.)
|
|
120
|
+
|
|
121
|
+
### Documentation Standards
|
|
122
|
+
- YARD documentation required for all public APIs
|
|
123
|
+
- Project enforces 100% documentation coverage via yardstick
|
|
124
|
+
- Use `bundle exec rake yard:format` to auto-format YARD tags
|
|
125
|
+
- YARD tags are grouped (e.g., `@param` tags together with no blank lines between them)
|
|
126
|
+
- Blank lines separate different tag types
|
|
127
|
+
|
|
128
|
+
## Testing Approach
|
|
129
|
+
|
|
130
|
+
### Framework
|
|
131
|
+
- RSpec 3.13+
|
|
132
|
+
- Monkey patching disabled (`config.disable_monkey_patching!`)
|
|
133
|
+
- Expect syntax only (no `should`)
|
|
134
|
+
- Example status persistence enabled (`.rspec_status`)
|
|
135
|
+
|
|
136
|
+
### Running Single Tests
|
|
137
|
+
```bash
|
|
138
|
+
bundle exec rspec spec/specific_spec.rb
|
|
139
|
+
bundle exec rspec spec/specific_spec.rb:42 # Run specific line
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
### Coverage
|
|
143
|
+
SimpleCov is configured to generate coverage reports. Run `bundle exec rake coverage` to generate and automatically open the HTML report.
|
|
144
|
+
|
|
145
|
+
## Project Constraints
|
|
146
|
+
|
|
147
|
+
### Ruby Version
|
|
148
|
+
Requires Ruby 4.0.0+ due to dependency on Ruby::Box. This is an experimental feature and may have breaking changes.
|
|
149
|
+
|
|
150
|
+
### Runtime Environment
|
|
151
|
+
Must run with `RUBY_BOX=1` environment variable set at process startup. Setting it after Ruby starts has no effect.
|
|
152
|
+
|
|
153
|
+
### Known Issues with Ruby::Box
|
|
154
|
+
- Stack overflow issues when installing native extensions
|
|
155
|
+
- Compatibility problems with Active Support's core extensions
|
|
156
|
+
- Built-in Ruby methods may not call overridden methods in boxes
|
|
157
|
+
- No way to expose top-level methods defined in boxes to other boxes
|
data/CHANGELOG.md
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [0.1.0] - 2025-12-28
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
- `import 'x'`
|
|
12
|
+
- `from 'x', import: '*'`
|
|
13
|
+
|
|
14
|
+
[0.1.0]: https://github.com/wilsonsilva/import_from/compare/27b35d...v0.1.0
|
data/CLAUDE.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
AGENTS.md
|
data/CODE_OF_CONDUCT.md
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# Code of Conduct
|
|
2
|
+
|
|
3
|
+
"import_from" follows [The Ruby Community Conduct Guideline](https://www.ruby-lang.org/en/conduct) in all "collaborative space", which is defined as community communications channels (such as mailing lists, submitted patches, commit comments, etc.):
|
|
4
|
+
|
|
5
|
+
* Participants will be tolerant of opposing views.
|
|
6
|
+
* Participants must ensure that their language and actions are free of personal attacks and disparaging personal remarks.
|
|
7
|
+
* When interpreting the words and actions of others, participants should always assume good intentions.
|
|
8
|
+
* Behaviour which can be reasonably considered harassment will not be tolerated.
|
|
9
|
+
|
|
10
|
+
If you have any concerns about behaviour within this project, please contact us at ["wilson.dsigns@gmail.com"](mailto:"wilson.dsigns@gmail.com").
|
data/Guardfile
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
guard 'bundler' do
|
|
4
|
+
watch('import_from.gemspec')
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
guard 'bundler_audit', run_on_start: true do
|
|
8
|
+
watch('Gemfile.lock')
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
group 'tests' do
|
|
12
|
+
guard 'rspec', all_on_start: true, failed_mode: :focus,
|
|
13
|
+
cmd: 'RUBY_BOX=1 COVERAGE=false bundle exec rspec --format progress' do
|
|
14
|
+
watch(%r{^spec/.+_spec\.rb$})
|
|
15
|
+
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
|
|
16
|
+
watch('spec/spec_helper.rb') { 'spec' }
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
guard 'rubocop' do
|
|
21
|
+
watch(/.+\.rb$/)
|
|
22
|
+
watch(%r{(?:.+/)?\.rubocop\.yml$}) { |m| File.dirname(m[0]) }
|
|
23
|
+
end
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Wilson Silva
|
|
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,129 @@
|
|
|
1
|
+
# ImportFrom
|
|
2
|
+
|
|
3
|
+
<div align="center">
|
|
4
|
+
|
|
5
|
+
[](https://badge.fury.io/rb/import_from)
|
|
6
|
+

|
|
7
|
+
[](https://qlty.sh/gh/wilsonsilva/projects/import_from)
|
|
8
|
+
[](https://qlty.sh/gh/wilsonsilva/projects/import_from)
|
|
9
|
+
|
|
10
|
+
</div>
|
|
11
|
+
|
|
12
|
+
Provides a Python-like syntax for importing modules and from Ruby gems and files.
|
|
13
|
+
|
|
14
|
+
## Table of contents
|
|
15
|
+
|
|
16
|
+
- [Key features](#-key-features)
|
|
17
|
+
- [Installation](#-installation)
|
|
18
|
+
- [Quickstart](#-quickstart)
|
|
19
|
+
- [Examples](#-examples)
|
|
20
|
+
- [Documentation](#-documentation)
|
|
21
|
+
- [Development](#-development)
|
|
22
|
+
* [Type checking](#-type-checking)
|
|
23
|
+
- [Contributing](#-contributing)
|
|
24
|
+
- [License](#-license)
|
|
25
|
+
- [Code of Conduct](#-code-of-conduct)
|
|
26
|
+
|
|
27
|
+
## ๐ Key features
|
|
28
|
+
|
|
29
|
+
- **TODO**: TODO
|
|
30
|
+
|
|
31
|
+
## ๐ฆ Installation
|
|
32
|
+
|
|
33
|
+
Install the gem and add to the application's Gemfile by executing:
|
|
34
|
+
|
|
35
|
+
$ bundle add import_from
|
|
36
|
+
|
|
37
|
+
If bundler is not being used to manage dependencies, install the gem by executing:
|
|
38
|
+
|
|
39
|
+
$ gem install import_from
|
|
40
|
+
|
|
41
|
+
## โก๏ธ Quickstart
|
|
42
|
+
|
|
43
|
+
Create a file called `main.rb` and run it with `RUBY_BOX=1 ruby -W:no-experimental main.rb`:
|
|
44
|
+
|
|
45
|
+
```ruby
|
|
46
|
+
# frozen_string_literal: true
|
|
47
|
+
|
|
48
|
+
require 'bundler/setup'
|
|
49
|
+
require 'import_from'
|
|
50
|
+
|
|
51
|
+
# Simple import
|
|
52
|
+
import 'money'
|
|
53
|
+
|
|
54
|
+
# Import with alias
|
|
55
|
+
import 'money', as: 'Mon'
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## ๐ Documentation
|
|
59
|
+
|
|
60
|
+
- [YARD documentation](https://rubydoc.info/gems/import_from)
|
|
61
|
+
|
|
62
|
+
## ๐ Examples
|
|
63
|
+
|
|
64
|
+
All examples can be found [here](https://github.com/wilsonsilva/import_from/blob/main/examples/README.md)
|
|
65
|
+
|
|
66
|
+
## ๐จ Development
|
|
67
|
+
|
|
68
|
+
After checking out the repo, run `bin/setup` to install dependencies.
|
|
69
|
+
|
|
70
|
+
To install this gem onto your local machine, run `bundle exec rake install`.
|
|
71
|
+
|
|
72
|
+
You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
|
73
|
+
|
|
74
|
+
To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`,
|
|
75
|
+
which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file
|
|
76
|
+
to [rubygems.org](https://rubygems.org).
|
|
77
|
+
|
|
78
|
+
The health and maintainability of the codebase is ensured through a set of
|
|
79
|
+
Rake tasks to test, lint and audit the gem for security vulnerabilities and documentation:
|
|
80
|
+
|
|
81
|
+
```
|
|
82
|
+
rake build # Build import_from.gem into the pkg directory
|
|
83
|
+
rake build:checksum # Generate SHA512 checksum of import_from.gem into the checksums directory
|
|
84
|
+
rake bundle:audit:check # Checks the Gemfile.lock for insecure dependencies
|
|
85
|
+
rake bundle:audit:update # Updates the bundler-audit vulnerability database
|
|
86
|
+
rake clean # Remove any temporary products
|
|
87
|
+
rake clobber # Remove any generated files
|
|
88
|
+
rake coverage # Run spec with coverage
|
|
89
|
+
rake install # Build and install import_from.gem into system gems
|
|
90
|
+
rake install:local # Build and install import_from.gem into system gems without network access
|
|
91
|
+
rake qa # Test, lint and perform security and documentation audits
|
|
92
|
+
rake release[remote] # Create tag and build and push import_from.gem to rubygems.org
|
|
93
|
+
rake rubocop # Run RuboCop
|
|
94
|
+
rake rubocop:autocorrect # Autocorrect RuboCop offenses (only when it's safe)
|
|
95
|
+
rake rubocop:autocorrect_all # Autocorrect RuboCop offenses (safe and unsafe)
|
|
96
|
+
rake spec # Run RSpec code examples
|
|
97
|
+
rake verify_measurements # Verify that yardstick coverage is at least 100%
|
|
98
|
+
rake yard # Generate YARD Documentation
|
|
99
|
+
rake yard:format # Format YARD documentation
|
|
100
|
+
rake yard:junk # Check the junk in your YARD Documentation
|
|
101
|
+
rake yardstick_measure # Measure docs in lib/**/*.rb with yardstick
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
### ๐งช Type checking
|
|
105
|
+
|
|
106
|
+
This gem leverages [RBS](https://github.com/ruby/rbs), a language to describe the structure of Ruby programs. It is
|
|
107
|
+
used to provide type checking and autocompletion in your editor. Run `bundle exec typeprof FILENAME` to generate
|
|
108
|
+
an RBS definition for the given Ruby file. And validate all definitions using [Steep](https://github.com/soutaro/steep)
|
|
109
|
+
with the command `bundle exec steep check`.
|
|
110
|
+
|
|
111
|
+
## ๐ Issues & Bugs
|
|
112
|
+
|
|
113
|
+
If you find any issues or bugs, please report them [here](https://github.com/wilsonsilva/import_from/issues), I will be happy
|
|
114
|
+
to have a look at them and fix them as soon as possible.
|
|
115
|
+
|
|
116
|
+
## ๐ค Contributing
|
|
117
|
+
|
|
118
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/wilsonsilva/import_from.
|
|
119
|
+
This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere
|
|
120
|
+
to the [code of conduct](https://github.com/wilsonsilva/import_from/blob/main/CODE_OF_CONDUCT.md).
|
|
121
|
+
|
|
122
|
+
## ๐ License
|
|
123
|
+
|
|
124
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
|
125
|
+
|
|
126
|
+
## ๐ Code of Conduct
|
|
127
|
+
|
|
128
|
+
Everyone interacting in the ImportFrom Ruby project's codebases, issue trackers, chat rooms and mailing lists is expected
|
|
129
|
+
to follow the [code of conduct](https://github.com/wilsonsilva/import_from/blob/main/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'bundler/audit/task'
|
|
4
|
+
require 'bundler/gem_tasks'
|
|
5
|
+
require 'rspec/core/rake_task'
|
|
6
|
+
require 'rubocop/rake_task'
|
|
7
|
+
require 'yaml'
|
|
8
|
+
require 'yard/rake/yardoc_task'
|
|
9
|
+
require 'yard-junk/rake'
|
|
10
|
+
require 'yardstick/rake/measurement'
|
|
11
|
+
require 'yardstick/rake/verify'
|
|
12
|
+
|
|
13
|
+
yardstick_options = YAML.load_file('.yardstick.yml')
|
|
14
|
+
|
|
15
|
+
Bundler::Audit::Task.new
|
|
16
|
+
RSpec::Core::RakeTask.new(:spec)
|
|
17
|
+
RuboCop::RakeTask.new
|
|
18
|
+
YARD::Rake::YardocTask.new
|
|
19
|
+
YardJunk::Rake.define_task
|
|
20
|
+
Yardstick::Rake::Measurement.new(:yardstick_measure, yardstick_options)
|
|
21
|
+
Yardstick::Rake::Verify.new(:verify_measurements, yardstick_options)
|
|
22
|
+
|
|
23
|
+
task default: %i[spec rubocop]
|
|
24
|
+
|
|
25
|
+
# Remove the report on rake clobber
|
|
26
|
+
CLEAN.include('measurements', 'doc', '.yardoc', 'tmp')
|
|
27
|
+
|
|
28
|
+
# Delete these files and folders when running rake clobber.
|
|
29
|
+
CLOBBER.include('coverage', '.rspec_status')
|
|
30
|
+
|
|
31
|
+
desc 'Run spec with coverage'
|
|
32
|
+
task :coverage do
|
|
33
|
+
ENV['COVERAGE'] = 'true'
|
|
34
|
+
Rake::Task['spec'].execute
|
|
35
|
+
`open coverage/index.html`
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
desc 'Test, lint and perform security and documentation audits'
|
|
39
|
+
task qa: %w[spec rubocop yard:junk verify_measurements bundle:audit]
|
|
40
|
+
|
|
41
|
+
namespace :yard do
|
|
42
|
+
desc 'Format YARD documentation'
|
|
43
|
+
task :format do
|
|
44
|
+
require 'fileutils'
|
|
45
|
+
|
|
46
|
+
ruby_files = Dir.glob(File.join(Dir.pwd, 'lib', '**', '*.rb'))
|
|
47
|
+
|
|
48
|
+
puts "Found #{ruby_files.length} Ruby files in lib directory"
|
|
49
|
+
puts
|
|
50
|
+
|
|
51
|
+
ruby_files.each do |file_path|
|
|
52
|
+
puts "Processing #{file_path}..."
|
|
53
|
+
|
|
54
|
+
content = File.read(file_path)
|
|
55
|
+
lines = content.split("\n")
|
|
56
|
+
result = []
|
|
57
|
+
|
|
58
|
+
lines.each_with_index do |line, index|
|
|
59
|
+
result << line
|
|
60
|
+
|
|
61
|
+
current_is_yard = line.strip.match?(/^\s*#\s*@\w+/)
|
|
62
|
+
next_line_exists = index + 1 < lines.length
|
|
63
|
+
|
|
64
|
+
# Process YARD tag spacing
|
|
65
|
+
next unless current_is_yard && next_line_exists
|
|
66
|
+
|
|
67
|
+
next_line = lines[index + 1]
|
|
68
|
+
|
|
69
|
+
next unless next_line.strip.match?(/^\s*#\s*@\w+/)
|
|
70
|
+
|
|
71
|
+
current_tag = line.strip.match(/^\s*#\s*@(\w+)/)[1]
|
|
72
|
+
next_tag = next_line.strip.match(/^\s*#\s*@(\w+)/)[1]
|
|
73
|
+
|
|
74
|
+
groupable = %w[param option]
|
|
75
|
+
should_group = groupable.include?(current_tag) && groupable.include?(next_tag)
|
|
76
|
+
|
|
77
|
+
# Add blank line between different tag types
|
|
78
|
+
unless should_group
|
|
79
|
+
indentation = line.match(/^(\s*)/)[1]
|
|
80
|
+
result << "#{indentation}#"
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
formatted_content = "#{result.join("\n")}\n"
|
|
85
|
+
|
|
86
|
+
if content == formatted_content
|
|
87
|
+
puts ' - No changes needed'
|
|
88
|
+
else
|
|
89
|
+
File.write(file_path, formatted_content)
|
|
90
|
+
puts ' โ Updated'
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
puts
|
|
95
|
+
puts 'Done!'
|
|
96
|
+
end
|
|
97
|
+
end
|