lazy_names 0.2.0 → 2.0.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 +5 -5
- data/.github/dependabot.yml +11 -0
- data/.github/workflows/codecov.yml +24 -0
- data/.github/workflows/codeql.yml +98 -0
- data/.github/workflows/rake.yml +24 -0
- data/.gitignore +1 -0
- data/.lazy_names.tt.rb +5 -0
- data/.rubocop.yml +45 -10
- data/.ruby-version +1 -1
- data/Gemfile +11 -1
- data/Gemfile.lock +65 -19
- data/LICENSE.txt +1 -1
- data/MIGRATION_FROM_V1.md +276 -0
- data/README.md +101 -42
- data/Rakefile +8 -2
- data/bin/console +1 -0
- data/bin/convert_to_v2 +61 -0
- data/lazy_names.gemspec +7 -8
- data/lib/lazy_names/line_validator.rb +61 -0
- data/lib/lazy_names/ruby_loader.rb +73 -0
- data/lib/lazy_names/version.rb +3 -1
- data/lib/lazy_names.rb +6 -16
- metadata +19 -75
- data/.lazy_names.tt.project.yml +0 -3
- data/.lazy_names.tt.yml +0 -4
- data/.travis.yml +0 -7
- data/lib/lazy_names/config.rb +0 -40
- data/lib/lazy_names/config_loader.rb +0 -88
- data/lib/lazy_names/config_validator.rb +0 -59
- data/lib/lazy_names/definer.rb +0 -13
- data/lib/lazy_names/find_namespace.rb +0 -12
- data/lib/lazy_names/logger.rb +0 -48
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
|
-
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 4d4b509d7cf80a3a06d081c317071cd6fbe5108f86f4e5e3c73b6ad04919be47
|
|
4
|
+
data.tar.gz: c975ba3dba6e0c88ed1277e757284a1f98599b2387264285765451150efeb1b2
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 92841fbe989e3f7556d9dd1269f35bff70fc78b8f9b75762011f37d7510bda072f9d63e21fa23c427d968ae657acfb2241aeeef7cb29c8f0b7cc271447cb0ca6
|
|
7
|
+
data.tar.gz: d8d5b5031d35521f754bc9c27dd9db7af016a6a347bac8c0b777039094a33e6a9e76005879fb1806ae7e25c4c3a2cacccd2bdcfcd9b93c058ee523be31ca7dee
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# To get started with Dependabot version updates, you'll need to specify which
|
|
2
|
+
# package ecosystems to update and where the package manifests are located.
|
|
3
|
+
# Please see the documentation for all configuration options:
|
|
4
|
+
# https://docs.github.com/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file
|
|
5
|
+
|
|
6
|
+
version: 2
|
|
7
|
+
updates:
|
|
8
|
+
- package-ecosystem: "github-actions"
|
|
9
|
+
directory: "/" # Location of package manifests
|
|
10
|
+
schedule:
|
|
11
|
+
interval: "weekly"
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: codecov
|
|
3
|
+
'on':
|
|
4
|
+
push:
|
|
5
|
+
branches:
|
|
6
|
+
- master
|
|
7
|
+
jobs:
|
|
8
|
+
codecov:
|
|
9
|
+
timeout-minutes: 15
|
|
10
|
+
runs-on: ubuntu-24.04
|
|
11
|
+
steps:
|
|
12
|
+
- uses: actions/checkout@v6
|
|
13
|
+
- uses: ruby/setup-ruby@v1
|
|
14
|
+
with:
|
|
15
|
+
ruby-version: 3.1
|
|
16
|
+
bundler-cache: true
|
|
17
|
+
- run: bundle config set --global path "$(pwd)/vendor/bundle"
|
|
18
|
+
- run: bundle install --no-color
|
|
19
|
+
- run: bundle exec rake
|
|
20
|
+
- uses: codecov/codecov-action@v5
|
|
21
|
+
with:
|
|
22
|
+
token: ${{ secrets.CODECOV_TOKEN }}
|
|
23
|
+
files: coverage/.resultset.json
|
|
24
|
+
fail_ci_if_error: true
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
# For most projects, this workflow file will not need changing; you simply need
|
|
2
|
+
# to commit it to your repository.
|
|
3
|
+
#
|
|
4
|
+
# You may wish to alter this file to override the set of languages analyzed,
|
|
5
|
+
# or to provide custom queries or build logic.
|
|
6
|
+
#
|
|
7
|
+
# ******** NOTE ********
|
|
8
|
+
# We have attempted to detect the languages in your repository. Please check
|
|
9
|
+
# the `language` matrix defined below to confirm you have the correct set of
|
|
10
|
+
# supported CodeQL languages.
|
|
11
|
+
#
|
|
12
|
+
name: "CodeQL Advanced"
|
|
13
|
+
|
|
14
|
+
on:
|
|
15
|
+
push:
|
|
16
|
+
branches: [ "master" ]
|
|
17
|
+
pull_request:
|
|
18
|
+
branches: [ "master" ]
|
|
19
|
+
schedule:
|
|
20
|
+
- cron: '40 18 * * 3'
|
|
21
|
+
|
|
22
|
+
jobs:
|
|
23
|
+
analyze:
|
|
24
|
+
name: Analyze (${{ matrix.language }})
|
|
25
|
+
# Runner size impacts CodeQL analysis time. To learn more, please see:
|
|
26
|
+
# - https://gh.io/recommended-hardware-resources-for-running-codeql
|
|
27
|
+
# - https://gh.io/supported-runners-and-hardware-resources
|
|
28
|
+
# - https://gh.io/using-larger-runners (GitHub.com only)
|
|
29
|
+
# Consider using larger runners or machines with greater resources for possible analysis time improvements.
|
|
30
|
+
runs-on: ${{ (matrix.language == 'swift' && 'macos-latest') || 'ubuntu-latest' }}
|
|
31
|
+
permissions:
|
|
32
|
+
# required for all workflows
|
|
33
|
+
security-events: write
|
|
34
|
+
|
|
35
|
+
# required to fetch internal or private CodeQL packs
|
|
36
|
+
packages: read
|
|
37
|
+
|
|
38
|
+
# only required for workflows in private repositories
|
|
39
|
+
actions: read
|
|
40
|
+
contents: read
|
|
41
|
+
|
|
42
|
+
strategy:
|
|
43
|
+
fail-fast: false
|
|
44
|
+
matrix:
|
|
45
|
+
include:
|
|
46
|
+
- language: ruby
|
|
47
|
+
build-mode: none
|
|
48
|
+
# CodeQL supports the following values keywords for 'language': 'c-cpp', 'csharp', 'go', 'java-kotlin', 'javascript-typescript', 'python', 'ruby', 'swift'
|
|
49
|
+
# Use `c-cpp` to analyze code written in C, C++ or both
|
|
50
|
+
# Use 'java-kotlin' to analyze code written in Java, Kotlin or both
|
|
51
|
+
# Use 'javascript-typescript' to analyze code written in JavaScript, TypeScript or both
|
|
52
|
+
# To learn more about changing the languages that are analyzed or customizing the build mode for your analysis,
|
|
53
|
+
# see https://docs.github.com/en/code-security/code-scanning/creating-an-advanced-setup-for-code-scanning/customizing-your-advanced-setup-for-code-scanning.
|
|
54
|
+
# If you are analyzing a compiled language, you can modify the 'build-mode' for that language to customize how
|
|
55
|
+
# your codebase is analyzed, see https://docs.github.com/en/code-security/code-scanning/creating-an-advanced-setup-for-code-scanning/codeql-code-scanning-for-compiled-languages
|
|
56
|
+
steps:
|
|
57
|
+
- name: Checkout repository
|
|
58
|
+
uses: actions/checkout@v6
|
|
59
|
+
|
|
60
|
+
# Add any setup steps before running the `github/codeql-action/init` action.
|
|
61
|
+
# This includes steps like installing compilers or runtimes (`actions/setup-node`
|
|
62
|
+
# or others). This is typically only required for manual builds.
|
|
63
|
+
# - name: Setup runtime (example)
|
|
64
|
+
# uses: actions/setup-example@v1
|
|
65
|
+
|
|
66
|
+
# Initializes the CodeQL tools for scanning.
|
|
67
|
+
- name: Initialize CodeQL
|
|
68
|
+
uses: github/codeql-action/init@v4
|
|
69
|
+
with:
|
|
70
|
+
languages: ${{ matrix.language }}
|
|
71
|
+
build-mode: ${{ matrix.build-mode }}
|
|
72
|
+
# If you wish to specify custom queries, you can do so here or in a config file.
|
|
73
|
+
# By default, queries listed here will override any specified in a config file.
|
|
74
|
+
# Prefix the list here with "+" to use these queries and those in the config file.
|
|
75
|
+
|
|
76
|
+
# For more details on CodeQL's query packs, refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
|
|
77
|
+
# queries: security-extended,security-and-quality
|
|
78
|
+
|
|
79
|
+
# If the analyze step fails for one of the languages you are analyzing with
|
|
80
|
+
# "We were unable to automatically build your code", modify the matrix above
|
|
81
|
+
# to set the build mode to "manual" for that language. Then modify this step
|
|
82
|
+
# to build your code.
|
|
83
|
+
# ℹ️ Command-line programs to run using the OS shell.
|
|
84
|
+
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
|
|
85
|
+
- if: matrix.build-mode == 'manual'
|
|
86
|
+
shell: bash
|
|
87
|
+
run: |
|
|
88
|
+
echo 'If you are using a "manual" build mode for one or more of the' \
|
|
89
|
+
'languages you are analyzing, replace this with the commands to build' \
|
|
90
|
+
'your code, for example:'
|
|
91
|
+
echo ' make bootstrap'
|
|
92
|
+
echo ' make release'
|
|
93
|
+
exit 1
|
|
94
|
+
|
|
95
|
+
- name: Perform CodeQL Analysis
|
|
96
|
+
uses: github/codeql-action/analyze@v4
|
|
97
|
+
with:
|
|
98
|
+
category: "/language:${{matrix.language}}"
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: rake
|
|
3
|
+
'on':
|
|
4
|
+
push:
|
|
5
|
+
branches:
|
|
6
|
+
- master
|
|
7
|
+
pull_request:
|
|
8
|
+
branches:
|
|
9
|
+
- master
|
|
10
|
+
jobs:
|
|
11
|
+
rake:
|
|
12
|
+
strategy:
|
|
13
|
+
matrix:
|
|
14
|
+
os: [ ubuntu-latest, macos-latest, windows-latest ]
|
|
15
|
+
runs-on: ${{ matrix.os }}
|
|
16
|
+
steps:
|
|
17
|
+
- uses: actions/checkout@v6
|
|
18
|
+
- uses: ruby/setup-ruby@v1
|
|
19
|
+
with:
|
|
20
|
+
ruby-version: '3.1'
|
|
21
|
+
bundler-cache: true
|
|
22
|
+
- run: bundle config set --global path "$(pwd)/vendor/bundle"
|
|
23
|
+
- run: bundle install --no-color
|
|
24
|
+
- run: bundle exec rake
|
data/.gitignore
CHANGED
data/.lazy_names.tt.rb
ADDED
data/.rubocop.yml
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
plugins:
|
|
2
|
+
- rubocop-rake
|
|
3
|
+
- rubocop-rspec
|
|
4
|
+
|
|
5
|
+
AllCops:
|
|
6
|
+
TargetRubyVersion: 2.7
|
|
7
|
+
NewCops: enable
|
|
3
8
|
|
|
4
9
|
# Good documentation welcome, but not required
|
|
5
10
|
Style/Documentation:
|
|
@@ -17,9 +22,6 @@ Style/HashTransformKeys:
|
|
|
17
22
|
Style/HashTransformValues:
|
|
18
23
|
Enabled: false
|
|
19
24
|
|
|
20
|
-
Security/Eval:
|
|
21
|
-
Enabled: false
|
|
22
|
-
|
|
23
25
|
Style/LambdaCall:
|
|
24
26
|
Enabled:
|
|
25
27
|
EnforcedStyle: braces
|
|
@@ -27,10 +29,6 @@ Style/LambdaCall:
|
|
|
27
29
|
Style/RedundantSelf:
|
|
28
30
|
Enabled: false
|
|
29
31
|
|
|
30
|
-
Style/MultilineMethodCallIndentation:
|
|
31
|
-
Enabled:
|
|
32
|
-
EnforcedStyle: indented
|
|
33
|
-
|
|
34
32
|
Layout/LineLength:
|
|
35
33
|
Enabled:
|
|
36
34
|
max: 100
|
|
@@ -39,6 +37,43 @@ Metrics/BlockLength:
|
|
|
39
37
|
Exclude:
|
|
40
38
|
- spec/**/*.rb
|
|
41
39
|
|
|
40
|
+
Metrics/MethodLength:
|
|
41
|
+
Max: 15
|
|
42
|
+
|
|
42
43
|
Metrics/AbcSize:
|
|
44
|
+
Max: 20
|
|
45
|
+
|
|
46
|
+
RSpec/NestedGroups:
|
|
47
|
+
Enabled: false
|
|
48
|
+
|
|
49
|
+
RSpec/MultipleExpectations:
|
|
50
|
+
Max: 5
|
|
51
|
+
|
|
52
|
+
RSpec/ExampleLength:
|
|
53
|
+
Max: 20
|
|
54
|
+
|
|
55
|
+
RSpec/MessageSpies:
|
|
56
|
+
Enabled: false
|
|
57
|
+
|
|
58
|
+
RSpec/RemoveConst:
|
|
59
|
+
Enabled: false
|
|
60
|
+
|
|
61
|
+
RSpec/InstanceVariable:
|
|
62
|
+
Enabled: false
|
|
63
|
+
|
|
64
|
+
RSpec/DescribeClass:
|
|
65
|
+
Enabled: false
|
|
66
|
+
|
|
67
|
+
RSpec/ContextWording:
|
|
68
|
+
Enabled: false
|
|
69
|
+
|
|
70
|
+
RSpec/AnyInstance:
|
|
71
|
+
Enabled: false
|
|
72
|
+
|
|
73
|
+
Security/Eval:
|
|
74
|
+
Exclude:
|
|
75
|
+
- spec/**/*.rb
|
|
76
|
+
|
|
77
|
+
Style/FrozenStringLiteralComment:
|
|
43
78
|
Exclude:
|
|
44
|
-
-
|
|
79
|
+
- .lazy_names.tt.rb
|
data/.ruby-version
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
3.1.4
|
data/Gemfile
CHANGED
|
@@ -1,6 +1,16 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
source 'https://rubygems.org'
|
|
2
4
|
|
|
3
5
|
git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
|
|
4
6
|
|
|
5
|
-
# Specify your gem's dependencies in lazy_names.gemspec
|
|
6
7
|
gemspec
|
|
8
|
+
|
|
9
|
+
gem 'bundler', '~> 2.1', require: false
|
|
10
|
+
gem 'pry', '~> 0.13', require: false
|
|
11
|
+
gem 'rake', '~> 12.3', require: false
|
|
12
|
+
gem 'rspec', '~> 3.0', require: false
|
|
13
|
+
gem 'rubocop', '~> 1.72', require: false
|
|
14
|
+
gem 'rubocop-rake', require: false
|
|
15
|
+
gem 'rubocop-rspec', require: false
|
|
16
|
+
gem 'simplecov', '0.22.0', require: false
|
data/Gemfile.lock
CHANGED
|
@@ -1,41 +1,87 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
lazy_names (
|
|
4
|
+
lazy_names (2.0.0)
|
|
5
5
|
|
|
6
6
|
GEM
|
|
7
7
|
remote: https://rubygems.org/
|
|
8
8
|
specs:
|
|
9
|
+
ast (2.4.2)
|
|
9
10
|
coderay (1.1.3)
|
|
10
|
-
diff-lcs (1.
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
diff-lcs (1.5.1)
|
|
12
|
+
docile (1.4.1)
|
|
13
|
+
json (2.10.2)
|
|
14
|
+
language_server-protocol (3.17.0.4)
|
|
15
|
+
lint_roller (1.1.0)
|
|
16
|
+
method_source (1.1.0)
|
|
17
|
+
parallel (1.26.3)
|
|
18
|
+
parser (3.3.7.1)
|
|
19
|
+
ast (~> 2.4.1)
|
|
20
|
+
racc
|
|
21
|
+
pry (0.14.2)
|
|
13
22
|
coderay (~> 1.1)
|
|
14
23
|
method_source (~> 1.0)
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
rspec-
|
|
22
|
-
|
|
24
|
+
racc (1.8.1)
|
|
25
|
+
rainbow (3.1.1)
|
|
26
|
+
rake (12.3.3)
|
|
27
|
+
regexp_parser (2.10.0)
|
|
28
|
+
rspec (3.12.0)
|
|
29
|
+
rspec-core (~> 3.12.0)
|
|
30
|
+
rspec-expectations (~> 3.12.0)
|
|
31
|
+
rspec-mocks (~> 3.12.0)
|
|
32
|
+
rspec-core (3.12.0)
|
|
33
|
+
rspec-support (~> 3.12.0)
|
|
34
|
+
rspec-expectations (3.12.2)
|
|
23
35
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
24
|
-
rspec-support (~> 3.
|
|
25
|
-
rspec-mocks (3.
|
|
36
|
+
rspec-support (~> 3.12.0)
|
|
37
|
+
rspec-mocks (3.12.3)
|
|
26
38
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
27
|
-
rspec-support (~> 3.
|
|
28
|
-
rspec-support (3.
|
|
39
|
+
rspec-support (~> 3.12.0)
|
|
40
|
+
rspec-support (3.12.0)
|
|
41
|
+
rubocop (1.72.2)
|
|
42
|
+
json (~> 2.3)
|
|
43
|
+
language_server-protocol (~> 3.17.0.2)
|
|
44
|
+
lint_roller (~> 1.1.0)
|
|
45
|
+
parallel (~> 1.10)
|
|
46
|
+
parser (>= 3.3.0.2)
|
|
47
|
+
rainbow (>= 2.2.2, < 4.0)
|
|
48
|
+
regexp_parser (>= 2.9.3, < 3.0)
|
|
49
|
+
rubocop-ast (>= 1.38.0, < 2.0)
|
|
50
|
+
ruby-progressbar (~> 1.7)
|
|
51
|
+
unicode-display_width (>= 2.4.0, < 4.0)
|
|
52
|
+
rubocop-ast (1.38.0)
|
|
53
|
+
parser (>= 3.3.1.0)
|
|
54
|
+
rubocop-rake (0.7.1)
|
|
55
|
+
lint_roller (~> 1.1)
|
|
56
|
+
rubocop (>= 1.72.1)
|
|
57
|
+
rubocop-rspec (3.5.0)
|
|
58
|
+
lint_roller (~> 1.1)
|
|
59
|
+
rubocop (~> 1.72, >= 1.72.1)
|
|
60
|
+
ruby-progressbar (1.13.0)
|
|
61
|
+
simplecov (0.22.0)
|
|
62
|
+
docile (~> 1.1)
|
|
63
|
+
simplecov-html (~> 0.11)
|
|
64
|
+
simplecov_json_formatter (~> 0.1)
|
|
65
|
+
simplecov-html (0.13.1)
|
|
66
|
+
simplecov_json_formatter (0.1.4)
|
|
67
|
+
unicode-display_width (3.1.4)
|
|
68
|
+
unicode-emoji (~> 4.0, >= 4.0.4)
|
|
69
|
+
unicode-emoji (4.0.4)
|
|
29
70
|
|
|
30
71
|
PLATFORMS
|
|
72
|
+
arm64-darwin-23
|
|
31
73
|
ruby
|
|
32
74
|
|
|
33
75
|
DEPENDENCIES
|
|
34
|
-
bundler (~> 1
|
|
76
|
+
bundler (~> 2.1)
|
|
35
77
|
lazy_names!
|
|
36
78
|
pry (~> 0.13)
|
|
37
|
-
rake (~>
|
|
79
|
+
rake (~> 12.3)
|
|
38
80
|
rspec (~> 3.0)
|
|
81
|
+
rubocop (~> 1.72)
|
|
82
|
+
rubocop-rake
|
|
83
|
+
rubocop-rspec
|
|
84
|
+
simplecov (= 0.22.0)
|
|
39
85
|
|
|
40
86
|
BUNDLED WITH
|
|
41
|
-
|
|
87
|
+
2.6.5
|
data/LICENSE.txt
CHANGED
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
# Migration Guide: v1.x to v2.0
|
|
2
|
+
|
|
3
|
+
This guide will help you migrate from LazyNames v1.x (YAML configuration) to v2.0 (Ruby configuration).
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
LazyNames v2.0 removes YAML support in favor of plain Ruby configuration files. This change makes the gem more intuitive and Ruby-native.
|
|
8
|
+
|
|
9
|
+
## Why the Change?
|
|
10
|
+
|
|
11
|
+
As discussed in the original issue, `.irbrc` and `.pryrc` already support plain Ruby. The YAML abstraction was unnecessary when you can simply write:
|
|
12
|
+
|
|
13
|
+
```ruby
|
|
14
|
+
MUCC = Models::Users::CreditCard
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
Instead of:
|
|
18
|
+
|
|
19
|
+
```yaml
|
|
20
|
+
---
|
|
21
|
+
definitions:
|
|
22
|
+
'Models::Users::CreditCard': 'MUCC'
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Breaking Changes
|
|
26
|
+
|
|
27
|
+
- ❌ `.lazy_names.yml` is no longer supported
|
|
28
|
+
- ✅ You must use `.lazy_names.rb` instead
|
|
29
|
+
- ✅ Constants are validated at load time (mandatory)
|
|
30
|
+
|
|
31
|
+
## Quick Conversion
|
|
32
|
+
|
|
33
|
+
### Before (v1.x)
|
|
34
|
+
|
|
35
|
+
**.lazy_names.yml**:
|
|
36
|
+
```yaml
|
|
37
|
+
---
|
|
38
|
+
definitions:
|
|
39
|
+
'Models::User': 'MU'
|
|
40
|
+
'Services::EmailSender': 'SES'
|
|
41
|
+
'Controllers::API::V1::UsersController': 'CAVUC'
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### After (v2.0)
|
|
45
|
+
|
|
46
|
+
**.lazy_names.rb**:
|
|
47
|
+
```ruby
|
|
48
|
+
MU = Models::User
|
|
49
|
+
SES = Services::EmailSender
|
|
50
|
+
CAVUC = Controllers::API::V1::UsersController
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## Automated Conversion Script
|
|
54
|
+
|
|
55
|
+
Save this as `convert_to_v2.rb` and run it in your project directory:
|
|
56
|
+
|
|
57
|
+
```ruby
|
|
58
|
+
#!/usr/bin/env ruby
|
|
59
|
+
require 'yaml'
|
|
60
|
+
|
|
61
|
+
yaml = YAML.load_file('.lazy_names.yml')
|
|
62
|
+
definitions = yaml['definitions'] || yaml.values.first['definitions']
|
|
63
|
+
|
|
64
|
+
File.open('.lazy_names.rb', 'w') do |f|
|
|
65
|
+
f.puts "# Converted from .lazy_names.yml"
|
|
66
|
+
definitions.each do |full, short|
|
|
67
|
+
f.puts "#{short} = #{full}"
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
puts "✓ Converted to .lazy_names.rb"
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### Using the Conversion Script
|
|
75
|
+
|
|
76
|
+
1. Run the script in your project directory:
|
|
77
|
+
```bash
|
|
78
|
+
ruby convert_to_v2.rb
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
2. Review the generated `.lazy_names.rb`:
|
|
82
|
+
```bash
|
|
83
|
+
cat .lazy_names.rb
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
3. Test it in your console:
|
|
87
|
+
```bash
|
|
88
|
+
bundle exec rails c
|
|
89
|
+
# or
|
|
90
|
+
bin/console
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
4. Once verified, delete the old YAML file:
|
|
94
|
+
```bash
|
|
95
|
+
rm .lazy_names.yml
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
## Global Configuration Migration
|
|
99
|
+
|
|
100
|
+
If you have a global configuration in `~/.lazy_names.yml` with namespace/project scoping:
|
|
101
|
+
|
|
102
|
+
### Before
|
|
103
|
+
|
|
104
|
+
**~/.lazy_names.yml**:
|
|
105
|
+
```yaml
|
|
106
|
+
---
|
|
107
|
+
my_project:
|
|
108
|
+
definitions:
|
|
109
|
+
'Models::User': 'MU'
|
|
110
|
+
another_project:
|
|
111
|
+
definitions:
|
|
112
|
+
'API::Client': 'AC'
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
### Namespace Scoping Is Intentionally Removed
|
|
116
|
+
|
|
117
|
+
v2.0 **does not support** namespace/project scoping in global config files. This was a deliberate decision:
|
|
118
|
+
|
|
119
|
+
- **It was YAML-induced complexity.** YAML encourages nested structures, but Ruby doesn't need this abstraction.
|
|
120
|
+
- **Project detection is fragile.** Matching project names to directories adds magic that can break.
|
|
121
|
+
- **Project-specific files are better.** Each project having its own `.lazy_names.rb` is more explicit and maintainable.
|
|
122
|
+
|
|
123
|
+
### After: Use Project-Specific Files (Recommended)
|
|
124
|
+
|
|
125
|
+
**This is the preferred migration path.** Create `.lazy_names.rb` in each project directory:
|
|
126
|
+
|
|
127
|
+
```ruby
|
|
128
|
+
# my_project/.lazy_names.rb
|
|
129
|
+
MU = Models::User
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
```ruby
|
|
133
|
+
# another_project/.lazy_names.rb
|
|
134
|
+
AC = API::Client
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
Benefits:
|
|
138
|
+
- Version controlled with each project
|
|
139
|
+
- Explicit about what's loaded
|
|
140
|
+
- No surprises or magic detection
|
|
141
|
+
- Easy to understand and maintain
|
|
142
|
+
|
|
143
|
+
### Alternative: Global File with Guards
|
|
144
|
+
|
|
145
|
+
If you prefer a single global file, use `if defined?()` guards:
|
|
146
|
+
|
|
147
|
+
**~/.lazy_names.rb**:
|
|
148
|
+
```ruby
|
|
149
|
+
# Only defined if the constant exists in the current project
|
|
150
|
+
MU = Models::User if defined?(Models::User)
|
|
151
|
+
AC = API::Client if defined?(API::Client)
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
This achieves the same result as namespace scoping but is simpler and more transparent.
|
|
155
|
+
|
|
156
|
+
## New Features in v2.0
|
|
157
|
+
|
|
158
|
+
### Validation
|
|
159
|
+
|
|
160
|
+
All constants are now validated before being defined:
|
|
161
|
+
|
|
162
|
+
```ruby
|
|
163
|
+
# Valid - will be defined
|
|
164
|
+
MU = Models::User
|
|
165
|
+
|
|
166
|
+
# Invalid - will show warning and skip
|
|
167
|
+
INVALID = NonExistent::Class
|
|
168
|
+
# Warning: Line 4: Constant NonExistent::Class not found - INVALID = NonExistent::Class
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
### Comments and Formatting
|
|
172
|
+
|
|
173
|
+
```ruby
|
|
174
|
+
# You can add comments to document your shortcuts
|
|
175
|
+
MU = Models::User
|
|
176
|
+
|
|
177
|
+
# Blank lines are allowed for organization
|
|
178
|
+
|
|
179
|
+
SES = Services::EmailSender
|
|
180
|
+
|
|
181
|
+
# Underscores and numbers work too
|
|
182
|
+
API_V1 = API::V1
|
|
183
|
+
CACHE2 = Cache::RedisCache
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
### Better Error Messages
|
|
187
|
+
|
|
188
|
+
v2.0 provides detailed error messages with line numbers:
|
|
189
|
+
|
|
190
|
+
```
|
|
191
|
+
Loading definitions from /path/to/.lazy_names.rb
|
|
192
|
+
Line 5: Constant Foo::Bar not found - FB = Foo::Bar
|
|
193
|
+
Loaded 10 definitions
|
|
194
|
+
Skipped 1 invalid lines
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
## Troubleshooting
|
|
198
|
+
|
|
199
|
+
### "Constant not found" warnings
|
|
200
|
+
|
|
201
|
+
If you see warnings about constants not being found:
|
|
202
|
+
|
|
203
|
+
1. **Make sure the constant exists** in your application
|
|
204
|
+
2. **Check the spelling** - constant names are case-sensitive
|
|
205
|
+
3. **Ensure the constant is loaded** before LazyNames runs
|
|
206
|
+
|
|
207
|
+
Example:
|
|
208
|
+
```ruby
|
|
209
|
+
# This will fail if Models isn't loaded yet
|
|
210
|
+
MU = Models::User
|
|
211
|
+
|
|
212
|
+
# This is safer - only define if it exists
|
|
213
|
+
MU = Models::User if defined?(Models::User)
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
### Constants not defined in console
|
|
217
|
+
|
|
218
|
+
If constants aren't showing up in your console:
|
|
219
|
+
|
|
220
|
+
1. Check that `.lazy_names.rb` is in the right location:
|
|
221
|
+
- Project root: `./.lazy_names.rb`
|
|
222
|
+
- Home directory: `~/.lazy_names.rb`
|
|
223
|
+
|
|
224
|
+
2. Verify your IRB/Pry configuration is correct:
|
|
225
|
+
|
|
226
|
+
**For Pry** (`~/.pryrc` or `.pryrc`):
|
|
227
|
+
```ruby
|
|
228
|
+
if defined?(LazyNames)
|
|
229
|
+
Pry.config.hooks.add_hook(:when_started, :lazy_names) do
|
|
230
|
+
LazyNames.load_definitions!
|
|
231
|
+
end
|
|
232
|
+
end
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
**For IRB** (`~/.irbrc` or `.irbrc`):
|
|
236
|
+
```ruby
|
|
237
|
+
if defined?(LazyNames)
|
|
238
|
+
LazyNames.load_definitions!
|
|
239
|
+
end
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
3. Make sure you've updated to v2.0:
|
|
243
|
+
```bash
|
|
244
|
+
bundle update lazy_names
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
### Migration script errors
|
|
248
|
+
|
|
249
|
+
If the conversion script fails:
|
|
250
|
+
|
|
251
|
+
**Error: No .lazy_names.yml found**
|
|
252
|
+
- Make sure you're in the correct directory
|
|
253
|
+
- Check if the file is named exactly `.lazy_names.yml`
|
|
254
|
+
|
|
255
|
+
**Error: .lazy_names.rb already exists**
|
|
256
|
+
- Review the existing file
|
|
257
|
+
- Delete it if you want to regenerate: `rm .lazy_names.rb`
|
|
258
|
+
- Or merge manually
|
|
259
|
+
|
|
260
|
+
## Need Help?
|
|
261
|
+
|
|
262
|
+
If you encounter issues during migration:
|
|
263
|
+
|
|
264
|
+
1. Check the [README](README.md) for configuration examples
|
|
265
|
+
2. Review the [implementation plan](MIGRATION_PLAN_V2.md) for technical details
|
|
266
|
+
3. Open an issue on [GitHub](https://github.com/zhisme/lazy_names/issues)
|
|
267
|
+
|
|
268
|
+
## Benefits of v2.0
|
|
269
|
+
|
|
270
|
+
After migrating, you'll enjoy:
|
|
271
|
+
|
|
272
|
+
- ✅ **More intuitive** - Same syntax as `.irbrc`/`.pryrc`
|
|
273
|
+
- ✅ **Better IDE support** - Syntax highlighting and autocomplete
|
|
274
|
+
- ✅ **Mandatory validation** - Know immediately if a constant doesn't exist
|
|
275
|
+
- ✅ **Simpler** - No YAML parsing overhead
|
|
276
|
+
- ✅ **Ruby-native** - Write Ruby to configure Ruby
|