lazy_names 0.1.1 → 1.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 +4 -4
- 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.project.yml +3 -0
- data/.rubocop.yml +9 -12
- data/.ruby-version +1 -1
- data/Gemfile +11 -1
- data/Gemfile.lock +65 -21
- data/LICENSE.txt +1 -1
- data/README.md +40 -13
- data/Rakefile +8 -2
- data/bin/console +1 -0
- data/lazy_names.gemspec +4 -5
- data/lib/lazy_names/config.rb +2 -0
- data/lib/lazy_names/config_loader.rb +27 -9
- data/lib/lazy_names/config_validator.rb +5 -5
- data/lib/lazy_names/definer.rb +4 -2
- data/lib/lazy_names/find_namespace.rb +2 -0
- data/lib/lazy_names/logger.rb +2 -0
- data/lib/lazy_names/version.rb +3 -1
- data/lib/lazy_names.rb +4 -2
- metadata +12 -62
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d0507f34b2f1f59a72734ddeb41c5b867f5114fd117ba73baa33293b46773d05
|
4
|
+
data.tar.gz: 3d9e34b1beeba0a4ef3ac8b87e3faf295614efcee1da770d40ee5f5619c9752e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 26231616eaa3a461ff281553300503d678952a3e4957593473b7db00fa00454848a6fa1cf4071de52d2e04b4afd4030ccd27c5988e69b17606ef3a027973481c
|
7
|
+
data.tar.gz: 81f910b280c65f62d9316a34b67d932950d991ba13a4dea3df18dcf78b8459d5745581d9422b1078eed624336e3a88985a4741710785530ee50aa9e79934f067
|
@@ -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@v4
|
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@v4
|
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@v3
|
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@v3
|
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@v4
|
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/.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,5 @@ Metrics/BlockLength:
|
|
39
37
|
Exclude:
|
40
38
|
- spec/**/*.rb
|
41
39
|
|
42
|
-
|
43
|
-
|
44
|
-
- lib/lazy_names.rb
|
40
|
+
RSpec/NestedGroups:
|
41
|
+
Enabled: false
|
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,43 +1,87 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
lazy_names (0.0
|
4
|
+
lazy_names (1.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
|
-
|
13
|
-
|
11
|
+
diff-lcs (1.5.1)
|
12
|
+
docile (1.4.1)
|
13
|
+
json (2.10.1)
|
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)
|
14
22
|
coderay (~> 1.1)
|
15
23
|
method_source (~> 1.0)
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
rspec-
|
23
|
-
|
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)
|
24
35
|
diff-lcs (>= 1.2.0, < 2.0)
|
25
|
-
rspec-support (~> 3.
|
26
|
-
rspec-mocks (3.
|
36
|
+
rspec-support (~> 3.12.0)
|
37
|
+
rspec-mocks (3.12.3)
|
27
38
|
diff-lcs (>= 1.2.0, < 2.0)
|
28
|
-
rspec-support (~> 3.
|
29
|
-
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)
|
30
70
|
|
31
71
|
PLATFORMS
|
72
|
+
arm64-darwin-23
|
32
73
|
ruby
|
33
74
|
|
34
75
|
DEPENDENCIES
|
35
|
-
bundler (~> 1
|
36
|
-
fakefs (~> 1.2)
|
76
|
+
bundler (~> 2.1)
|
37
77
|
lazy_names!
|
38
78
|
pry (~> 0.13)
|
39
|
-
rake (~>
|
79
|
+
rake (~> 12.3)
|
40
80
|
rspec (~> 3.0)
|
81
|
+
rubocop (~> 1.72)
|
82
|
+
rubocop-rake
|
83
|
+
rubocop-rspec
|
84
|
+
simplecov (= 0.22.0)
|
41
85
|
|
42
86
|
BUNDLED WITH
|
43
|
-
|
87
|
+
2.6.5
|
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -1,13 +1,22 @@
|
|
1
|
+
[](https://github.com/zhisme/lazy_names/actions/workflows/rake.yml)
|
2
|
+
[](https://badge.fury.io/rb/lazy_names)
|
3
|
+

|
4
|
+
[](https://hitsofcode.com/github/zhisme/lazy_names/view?branch=master)
|
5
|
+
[](https://codecov.io/gh/zhisme/lazy_names)
|
6
|
+

|
7
|
+
|
1
8
|
# lazy_names
|
2
9
|
|
3
|
-
|
4
|
-
If you are lazy like me typing many times a day in console long
|
10
|
+
lazy_names helps programmer to type faster very-long class names constants by defining them on a shorter version.
|
11
|
+
If you are lazy like me typing many times a day in console long constants then this gem will ease your development process.
|
5
12
|
|
6
13
|
## Why
|
7
14
|
|
8
15
|
Consider this example from pry terminal session.
|
9
16
|

|
10
17
|
|
18
|
+
The idea is to reduce typing of long namespaced constants to shorter versions. It's very useful when you have a lot of nested namespaces and you need to access them frequently. This gem will take your responsibility to redefine constants to shorter versions and making constant/classes validations.
|
19
|
+
|
11
20
|
## Installation
|
12
21
|
|
13
22
|
1. Add this line to your application's Gemfile:
|
@@ -54,6 +63,9 @@ $ bundle exec rails c # or bin/console
|
|
54
63
|
```
|
55
64
|
|
56
65
|
## Configuration
|
66
|
+
|
67
|
+
### Global definition
|
68
|
+
|
57
69
|
Take a look onto `lazy_names.tt.yml` it has very basic template for you to start.
|
58
70
|
|
59
71
|
```yml
|
@@ -69,14 +81,14 @@ So consider this example:
|
|
69
81
|
$ pwd
|
70
82
|
/Users/name/my_awesome_project
|
71
83
|
```
|
72
|
-
The last folder name of you ruby project must match the same one in your configuration.
|
73
|
-
After **definitions** sections you can actually redefine your long constants.
|
74
|
-
So in this example `Models::Users::CreditCard` is your real project constant and
|
75
|
-
`MUCC` will be your short variant of it, so you can access `Models::Users::CreditCard`
|
76
|
-
from `MUCC`. `MUCC` and any other right hand side can be any value, you define the best-suitable names.
|
77
|
-
|
78
|
-
You can define as many constants as you want. The same rule applies for projects.
|
79
|
-
Your config can have multiple constant definitions per namespace.
|
84
|
+
The last folder name of you ruby project must match the same one in your configuration.
|
85
|
+
After **definitions** sections you can actually redefine your long constants.
|
86
|
+
So in this example `Models::Users::CreditCard` is your real project constant and
|
87
|
+
`MUCC` will be your short variant of it, so you can access `Models::Users::CreditCard`
|
88
|
+
from `MUCC`. `MUCC` and any other right hand side can be any value, you define the best-suitable names.
|
89
|
+
|
90
|
+
You can define as many constants as you want. The same rule applies for projects.
|
91
|
+
Your config can have multiple constant definitions per namespace.
|
80
92
|
```yml
|
81
93
|
---
|
82
94
|
my_awesome_project:
|
@@ -87,19 +99,34 @@ my_another_project:
|
|
87
99
|
'OtherLongConst': 'Short'
|
88
100
|
```
|
89
101
|
|
90
|
-
|
91
|
-
|
92
|
-
|
102
|
+
### Project definitions
|
103
|
+
|
104
|
+
In the meantime you can put your `.lazy_names.yml` config directly to project folder, it will be looked up firstly from project.
|
105
|
+
Just do not forget to put in your `.gitignore`. I believe every developer defines shorter versions of constants by his own opinion.
|
106
|
+
```sh
|
107
|
+
echo '.lazy_names.yml' >> .gitignore
|
108
|
+
```
|
109
|
+
If project folder doesn't contain any `.lazy_names.yml`, it will fallback to home directory.
|
110
|
+
|
111
|
+
Configuration per project a bit different: you don't need to specify global scope `my_awesome_project`, you can skip forward to definitions
|
112
|
+
```yml
|
113
|
+
---
|
114
|
+
definitions:
|
115
|
+
'Models::Users::CreditCard: 'MUCC'
|
116
|
+
```
|
117
|
+
Example config can be found in `.lazy_names.tt.project.yml`
|
93
118
|
|
94
119
|
## Development
|
95
120
|
|
96
121
|
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.
|
122
|
+
After you make changes ensure to run `rake rubocop` to check if your code meets linter standards.
|
97
123
|
|
98
124
|
To install this gem onto your local machine, run `bundle exec rake install`.
|
99
125
|
|
100
126
|
## Contributing
|
101
127
|
|
102
128
|
Bug reports and pull requests are welcome on GitHub at https://github.com/zhisme/lazy_names.
|
129
|
+
Ensure the CI build is green by validating tests are passing and coverage is not decreased.
|
103
130
|
|
104
131
|
## License
|
105
132
|
|
data/Rakefile
CHANGED
@@ -1,6 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'bundler/gem_tasks'
|
2
4
|
require 'rspec/core/rake_task'
|
5
|
+
require 'rubocop/rake_task'
|
3
6
|
|
4
|
-
|
7
|
+
task default: %i[clean rubocop spec]
|
5
8
|
|
6
|
-
|
9
|
+
desc 'Run RuboCop'
|
10
|
+
RuboCop::RakeTask.new(:rubocop)
|
11
|
+
|
12
|
+
RSpec::Core::RakeTask.new(:spec)
|
data/bin/console
CHANGED
data/lazy_names.gemspec
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
lib = File.expand_path('lib', __dir__)
|
2
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
5
|
require 'lazy_names/version'
|
@@ -23,9 +25,6 @@ Gem::Specification.new do |spec|
|
|
23
25
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
24
26
|
spec.require_paths = ['lib']
|
25
27
|
|
26
|
-
spec.
|
27
|
-
spec.
|
28
|
-
spec.add_development_dependency 'rake', '~> 10.0'
|
29
|
-
spec.add_development_dependency 'rspec', '~> 3.0'
|
30
|
-
spec.required_ruby_version = '>= 2.3.3'
|
28
|
+
spec.required_ruby_version = '>= 2.7'
|
29
|
+
spec.metadata['rubygems_mfa_required'] = 'true'
|
31
30
|
end
|
data/lib/lazy_names/config.rb
CHANGED
@@ -1,19 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'yaml'
|
2
4
|
|
3
5
|
module LazyNames
|
4
6
|
class ConfigLoader
|
5
7
|
class NoConfig < StandardError; end
|
8
|
+
class YAMLConfigInvalid < StandardError; end
|
6
9
|
class ConfigNotResolved < StandardError; end
|
7
10
|
class NamespaceNotFound < StandardError; end
|
11
|
+
class NoDefinitions < StandardError; end
|
8
12
|
|
9
13
|
class << self
|
10
14
|
BasicConfig = Struct.new(:path, :definitions)
|
11
|
-
HOME_PATH = '~/.lazy_names.yml'
|
15
|
+
HOME_PATH = '~/.lazy_names.yml'
|
12
16
|
|
13
17
|
def call(namespace:, path: nil)
|
14
18
|
return read_from_path(namespace, path) if path
|
15
19
|
|
16
|
-
config = read_from_project
|
20
|
+
config = read_from_project if config_in_project_path?
|
17
21
|
config ||= read_from_home_dir(namespace)
|
18
22
|
|
19
23
|
config
|
@@ -35,22 +39,34 @@ module LazyNames
|
|
35
39
|
BasicConfig.new(home_path, definitions)
|
36
40
|
rescue Errno::ENOENT
|
37
41
|
raise NoConfig, 'No config found in your home directory. ' \
|
38
|
-
|
42
|
+
'Create ~/.lazy_names.yml'
|
39
43
|
end
|
40
44
|
|
41
|
-
def read_from_project
|
42
|
-
|
43
|
-
|
44
|
-
definitions = find_definitions(project_path, namespace)
|
45
|
+
def read_from_project
|
46
|
+
definitions = find_project_definitions
|
45
47
|
|
46
48
|
BasicConfig.new(project_path, definitions)
|
47
49
|
end
|
48
50
|
|
51
|
+
def find_project_definitions
|
52
|
+
read_config(project_path)['definitions'].to_hash
|
53
|
+
rescue NoMethodError
|
54
|
+
raise NoDefinitions, "No definitions found in #{project_path}. " \
|
55
|
+
'See config example .lazy_names.tt.project.yml'
|
56
|
+
end
|
57
|
+
|
49
58
|
def find_definitions(path, namespace)
|
50
|
-
|
59
|
+
find_namespace_contents(path, namespace)['definitions'].to_hash
|
60
|
+
rescue NoMethodError
|
61
|
+
raise NoDefinitions, "No definitions found in #{path}. " \
|
62
|
+
'See config example in .lazy_names.tt.yml'
|
63
|
+
end
|
51
64
|
|
65
|
+
def find_namespace_contents(path, namespace)
|
66
|
+
read_config(path)[namespace].to_hash
|
52
67
|
rescue NoMethodError
|
53
|
-
raise NamespaceNotFound
|
68
|
+
raise NamespaceNotFound, "No namespace found in #{path}. " \
|
69
|
+
'See config example in .lazy_names.tt.yml and check README'
|
54
70
|
end
|
55
71
|
|
56
72
|
def config_in_project_path?
|
@@ -59,6 +75,8 @@ module LazyNames
|
|
59
75
|
|
60
76
|
def read_config(path)
|
61
77
|
YAML.safe_load(File.read(path))
|
78
|
+
rescue Psych::SyntaxError => e
|
79
|
+
raise YAMLConfigInvalid, e
|
62
80
|
end
|
63
81
|
|
64
82
|
def project_path
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module LazyNames
|
2
4
|
class ConfigValidator
|
3
5
|
attr_reader :errors
|
@@ -23,11 +25,9 @@ module LazyNames
|
|
23
25
|
|
24
26
|
def validate_constants!
|
25
27
|
constants.each do |c|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
self.errors.undefined << c
|
30
|
-
end
|
28
|
+
resolve_const_in_project(c)
|
29
|
+
rescue NameError
|
30
|
+
self.errors.undefined << c
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
data/lib/lazy_names/definer.rb
CHANGED
@@ -1,10 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module LazyNames
|
2
4
|
class Definer
|
3
5
|
class << self
|
4
6
|
def call(config, top_level_binding)
|
5
7
|
config.constants.each do |origin|
|
6
|
-
eval <<-RUBY, top_level_binding, __FILE__, __LINE__ + 1
|
7
|
-
#{config.lazy_name(origin)} = #{origin}
|
8
|
+
eval <<-RUBY, top_level_binding, __FILE__, __LINE__ + 1 # rubocop:disable Security/Eval
|
9
|
+
#{config.lazy_name(origin)} = #{origin} # LN_MC = LazyNames::MyClass. See spec/lazy_names/definer_spec.rb
|
8
10
|
RUBY
|
9
11
|
end
|
10
12
|
end
|
data/lib/lazy_names/logger.rb
CHANGED
data/lib/lazy_names/version.rb
CHANGED
data/lib/lazy_names.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'lazy_names/version'
|
2
4
|
require 'lazy_names/find_namespace'
|
3
5
|
require 'lazy_names/config_loader'
|
@@ -7,9 +9,9 @@ require 'lazy_names/definer'
|
|
7
9
|
require 'lazy_names/logger'
|
8
10
|
|
9
11
|
module LazyNames
|
10
|
-
def self.load_definitions!(top_level_binding = TOPLEVEL_BINDING)
|
12
|
+
def self.load_definitions!(top_level_binding = TOPLEVEL_BINDING) # rubocop:disable Metrics/AbcSize
|
11
13
|
basic_config = LazyNames::ConfigLoader
|
12
|
-
|
14
|
+
.(namespace: LazyNames::FindNamespace.())
|
13
15
|
config = LazyNames::Config.new(basic_config.definitions, basic_config.path)
|
14
16
|
config.validate!
|
15
17
|
LazyNames::Definer.(config, top_level_binding)
|
metadata
CHANGED
@@ -1,71 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lazy_names
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- zhisme
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
12
|
-
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: bundler
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - "~>"
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '1.16'
|
20
|
-
type: :development
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - "~>"
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '1.16'
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: pry
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - "~>"
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '0.13'
|
34
|
-
type: :development
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - "~>"
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '0.13'
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: rake
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - "~>"
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: '10.0'
|
48
|
-
type: :development
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - "~>"
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '10.0'
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: rspec
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - "~>"
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '3.0'
|
62
|
-
type: :development
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - "~>"
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: '3.0'
|
11
|
+
date: 2025-02-21 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
69
13
|
description: |
|
70
14
|
lazy_names is ruby programmer friend. You can save your time not typing long
|
71
15
|
error-phone constants/classes but defining short and nice versions of them.
|
@@ -75,7 +19,12 @@ executables: []
|
|
75
19
|
extensions: []
|
76
20
|
extra_rdoc_files: []
|
77
21
|
files:
|
22
|
+
- ".github/dependabot.yml"
|
23
|
+
- ".github/workflows/codecov.yml"
|
24
|
+
- ".github/workflows/codeql.yml"
|
25
|
+
- ".github/workflows/rake.yml"
|
78
26
|
- ".gitignore"
|
27
|
+
- ".lazy_names.tt.project.yml"
|
79
28
|
- ".lazy_names.tt.yml"
|
80
29
|
- ".rspec"
|
81
30
|
- ".rubocop.yml"
|
@@ -100,7 +49,8 @@ files:
|
|
100
49
|
homepage: https://github.com/zhisme/lazy_names
|
101
50
|
licenses:
|
102
51
|
- MIT
|
103
|
-
metadata:
|
52
|
+
metadata:
|
53
|
+
rubygems_mfa_required: 'true'
|
104
54
|
post_install_message:
|
105
55
|
rdoc_options: []
|
106
56
|
require_paths:
|
@@ -109,14 +59,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
109
59
|
requirements:
|
110
60
|
- - ">="
|
111
61
|
- !ruby/object:Gem::Version
|
112
|
-
version: 2.
|
62
|
+
version: '2.7'
|
113
63
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
114
64
|
requirements:
|
115
65
|
- - ">="
|
116
66
|
- !ruby/object:Gem::Version
|
117
67
|
version: '0'
|
118
68
|
requirements: []
|
119
|
-
rubygems_version: 3.
|
69
|
+
rubygems_version: 3.3.26
|
120
70
|
signing_key:
|
121
71
|
specification_version: 4
|
122
72
|
summary: Define short constants to frequently used classes/constants
|