lazy_names 0.1.1 → 0.2.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/.lazy_names.tt.project.yml +3 -0
- data/Gemfile.lock +1 -3
- data/README.md +29 -13
- data/lib/lazy_names/config_loader.rb +22 -7
- data/lib/lazy_names/version.rb +1 -1
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 7d0986ae45e667f52744c72afa5c79ed9adadd84
|
4
|
+
data.tar.gz: bfce318aab2ff6de0cf1a2147dc334011d03bab0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cfc61aaa924dbd3c67221000f7d38ac0445cc43fe8b14a3c16e9d8ea70dd5b40d95553d98e38777b5212ec7765c40d0155051dfc594347f8132f2f76091c2840
|
7
|
+
data.tar.gz: 5002c013d4d4537aeb12addace4a0c77001a655ca888e835e6344b0f5f1a5d1c946d122f333a7638cf5381d426b487f4031ee3fb8ba5948d2b182690970ac569
|
data/Gemfile.lock
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
lazy_names (0.0
|
4
|
+
lazy_names (0.2.0)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
8
8
|
specs:
|
9
9
|
coderay (1.1.3)
|
10
10
|
diff-lcs (1.3)
|
11
|
-
fakefs (1.2.1)
|
12
11
|
method_source (1.0.0)
|
13
12
|
pry (0.13.1)
|
14
13
|
coderay (~> 1.1)
|
@@ -33,7 +32,6 @@ PLATFORMS
|
|
33
32
|
|
34
33
|
DEPENDENCIES
|
35
34
|
bundler (~> 1.16)
|
36
|
-
fakefs (~> 1.2)
|
37
35
|
lazy_names!
|
38
36
|
pry (~> 0.13)
|
39
37
|
rake (~> 10.0)
|
data/README.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# lazy_names
|
2
2
|
|
3
|
-
LazyNames helps programmer to type faster very-long
|
4
|
-
If you are lazy like me typing many times a day in console long
|
3
|
+
LazyNames helps programmer to type faster very-long class names, constants by defining them on a shorter version.
|
4
|
+
If you are lazy like me typing many times a day in console long constants then this gem will ease your development process.
|
5
5
|
|
6
6
|
## Why
|
7
7
|
|
@@ -54,6 +54,9 @@ $ bundle exec rails c # or bin/console
|
|
54
54
|
```
|
55
55
|
|
56
56
|
## Configuration
|
57
|
+
|
58
|
+
### Global definition
|
59
|
+
|
57
60
|
Take a look onto `lazy_names.tt.yml` it has very basic template for you to start.
|
58
61
|
|
59
62
|
```yml
|
@@ -69,14 +72,14 @@ So consider this example:
|
|
69
72
|
$ pwd
|
70
73
|
/Users/name/my_awesome_project
|
71
74
|
```
|
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.
|
75
|
+
The last folder name of you ruby project must match the same one in your configuration.
|
76
|
+
After **definitions** sections you can actually redefine your long constants.
|
77
|
+
So in this example `Models::Users::CreditCard` is your real project constant and
|
78
|
+
`MUCC` will be your short variant of it, so you can access `Models::Users::CreditCard`
|
79
|
+
from `MUCC`. `MUCC` and any other right hand side can be any value, you define the best-suitable names.
|
80
|
+
|
81
|
+
You can define as many constants as you want. The same rule applies for projects.
|
82
|
+
Your config can have multiple constant definitions per namespace.
|
80
83
|
```yml
|
81
84
|
---
|
82
85
|
my_awesome_project:
|
@@ -87,9 +90,22 @@ my_another_project:
|
|
87
90
|
'OtherLongConst': 'Short'
|
88
91
|
```
|
89
92
|
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
+
### Project definitions
|
94
|
+
|
95
|
+
In the meantime you can put your `.lazy_names.yml` config directly to project folder, it will be looked up firstly from project.
|
96
|
+
Just do not forget to put in your `.gitignore`. I believe every developer defines shorter versions of constants by his own opinion.
|
97
|
+
```sh
|
98
|
+
echo '.lazy_names.yml' >> .gitignore
|
99
|
+
```
|
100
|
+
If project folder doesn't contain any `.lazy_names.yml`, it will fallback to home directory.
|
101
|
+
|
102
|
+
Configuration per project a bit different: you don't need to specify global scope `my_awesome_project`, you can skip forward to definitions
|
103
|
+
```yml
|
104
|
+
---
|
105
|
+
definitions:
|
106
|
+
'Models::Users::CreditCard: 'MUCC'
|
107
|
+
```
|
108
|
+
Example config can be found in `.lazy_names.tt.project.yml`
|
93
109
|
|
94
110
|
## Development
|
95
111
|
|
@@ -5,6 +5,7 @@ module LazyNames
|
|
5
5
|
class NoConfig < StandardError; end
|
6
6
|
class ConfigNotResolved < StandardError; end
|
7
7
|
class NamespaceNotFound < StandardError; end
|
8
|
+
class NoDefinitions < StandardError; end
|
8
9
|
|
9
10
|
class << self
|
10
11
|
BasicConfig = Struct.new(:path, :definitions)
|
@@ -13,7 +14,7 @@ module LazyNames
|
|
13
14
|
def call(namespace:, path: nil)
|
14
15
|
return read_from_path(namespace, path) if path
|
15
16
|
|
16
|
-
config = read_from_project
|
17
|
+
config = read_from_project if config_in_project_path?
|
17
18
|
config ||= read_from_home_dir(namespace)
|
18
19
|
|
19
20
|
config
|
@@ -38,19 +39,33 @@ module LazyNames
|
|
38
39
|
'Create ~/.lazy_names.yml'
|
39
40
|
end
|
40
41
|
|
41
|
-
def read_from_project
|
42
|
-
|
43
|
-
|
44
|
-
definitions = find_definitions(project_path, namespace)
|
42
|
+
def read_from_project
|
43
|
+
definitions = find_project_definitions
|
45
44
|
|
46
45
|
BasicConfig.new(project_path, definitions)
|
47
46
|
end
|
48
47
|
|
48
|
+
def find_project_definitions
|
49
|
+
read_config(project_path)['definitions'].to_hash
|
50
|
+
|
51
|
+
rescue NoMethodError
|
52
|
+
raise NoDefinitions, "No definitions found in #{project_path}. " \
|
53
|
+
'See config example .lazy_names.tt.project.yml'
|
54
|
+
end
|
55
|
+
|
49
56
|
def find_definitions(path, namespace)
|
50
|
-
|
57
|
+
find_namespace_contents(path, namespace)['definitions'].to_hash
|
58
|
+
|
59
|
+
rescue NoMethodError
|
60
|
+
raise NoDefinitions, "No definitions found in #{path}. " \
|
61
|
+
'See config example in .lazy_names.tt.yml'
|
62
|
+
end
|
51
63
|
|
64
|
+
def find_namespace_contents(path, namespace)
|
65
|
+
read_config(path)[namespace].to_hash
|
52
66
|
rescue NoMethodError
|
53
|
-
raise NamespaceNotFound
|
67
|
+
raise NamespaceNotFound, "No namespace found in #{path}. " \
|
68
|
+
'See config example in .lazy_names.tt.yml and check README'
|
54
69
|
end
|
55
70
|
|
56
71
|
def config_in_project_path?
|
data/lib/lazy_names/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lazy_names
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- zhisme
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-02-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -76,6 +76,7 @@ extensions: []
|
|
76
76
|
extra_rdoc_files: []
|
77
77
|
files:
|
78
78
|
- ".gitignore"
|
79
|
+
- ".lazy_names.tt.project.yml"
|
79
80
|
- ".lazy_names.tt.yml"
|
80
81
|
- ".rspec"
|
81
82
|
- ".rubocop.yml"
|
@@ -116,7 +117,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
116
117
|
- !ruby/object:Gem::Version
|
117
118
|
version: '0'
|
118
119
|
requirements: []
|
119
|
-
|
120
|
+
rubyforge_project:
|
121
|
+
rubygems_version: 2.5.2
|
120
122
|
signing_key:
|
121
123
|
specification_version: 4
|
122
124
|
summary: Define short constants to frequently used classes/constants
|