yamlook 0.0.3 → 0.3.1
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/README.md +17 -0
- data/lib/yamlook.rb +1 -0
- data/lib/yamlook/file.rb +6 -8
- data/lib/yamlook/locale.rb +17 -0
- data/lib/yamlook/node_list.rb +4 -2
- data/lib/yamlook/search.rb +6 -0
- data/lib/yamlook/version.rb +1 -1
- data/locales.yaml +176 -0
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 867706c81bb16407e762b76754d645825cdb6ba53030ac1ce5bf99d46087b5a9
|
4
|
+
data.tar.gz: 1c0a8face94149303d06484573db378b23cfe8a6e6d0e7ab6229737f62201103
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a2c4351ab5486d2a8802f935afc331af435b7655f0de81dae3f030235524682f80c8f867af85f5a041b0e70699c4edf74ec62e2bae1488353647310576abc7c8
|
7
|
+
data.tar.gz: db2af0dcb85bc99700317118320453aad3dc8d1e46d8597e80e069b3f24687d2a4105203a82fdbf954ebe57eeb2c7e40108da3880a3131431a6aa255bf5f6667
|
data/README.md
CHANGED
@@ -1,5 +1,16 @@
|
|
1
1
|
# Yamlook
|
2
2
|
|
3
|
+
Yamlook searches for dot-notated yaml keys occurrences in yaml files. It might be handy if you have localization
|
4
|
+
or deep configs and you don't know where one or another value comes from.
|
5
|
+
|
6
|
+
For instance you have such code:
|
7
|
+
```
|
8
|
+
<%= link_to t("admin.marketing.reports.some_report.title"), some_report_path(format: "csv") %>
|
9
|
+
```
|
10
|
+
Run `yamlook admin.marketing.reports.some_report.title` in terminal and it will show up all occurrences of that value
|
11
|
+
in your internationalization yaml files. If you have all the internationalization in one yaml file, you will likely
|
12
|
+
have to specify some root key as well, e.g. `yamlook en.admin.marketing.reports.some_report.title`.
|
13
|
+
|
3
14
|
## Installation
|
4
15
|
|
5
16
|
```
|
@@ -8,10 +19,16 @@ $ gem install yamlook
|
|
8
19
|
|
9
20
|
## Usage
|
10
21
|
|
22
|
+
Run yamlook in terminal with dot-notated yaml keys as argument:
|
11
23
|
```
|
12
24
|
$ yamlook some.deep.key.in.you.yaml.file
|
13
25
|
```
|
14
26
|
|
27
|
+
## Contributing
|
28
|
+
|
29
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/sl4vr/yamlook.
|
30
|
+
|
31
|
+
|
15
32
|
## License
|
16
33
|
|
17
34
|
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/lib/yamlook.rb
CHANGED
data/lib/yamlook/file.rb
CHANGED
@@ -12,9 +12,11 @@ module Yamlook
|
|
12
12
|
def search(keys)
|
13
13
|
return unless yaml
|
14
14
|
|
15
|
-
findings =
|
16
|
-
|
17
|
-
|
15
|
+
findings = Locale.key_combinations(keys).flat_map do |key_combination|
|
16
|
+
root_node_list.search(key_combination).flatten.compact.map do |finding|
|
17
|
+
finding.filename = filename
|
18
|
+
finding
|
19
|
+
end
|
18
20
|
end
|
19
21
|
|
20
22
|
findings if findings.any?
|
@@ -33,11 +35,7 @@ module Yamlook
|
|
33
35
|
end
|
34
36
|
|
35
37
|
def root_node_list
|
36
|
-
NodeList.new(
|
37
|
-
end
|
38
|
-
|
39
|
-
def root_mapping
|
40
|
-
yaml.children.first
|
38
|
+
NodeList.new(yaml.root.children)
|
41
39
|
end
|
42
40
|
end
|
43
41
|
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Yamlook
|
4
|
+
# Possible locale keys handling
|
5
|
+
module Locale
|
6
|
+
LOCALES_FILEPATH = File.join(File.expand_path('../..', __dir__), 'locales.yaml')
|
7
|
+
LOCALES = Psych.load_file(LOCALES_FILEPATH)['locales'].freeze
|
8
|
+
|
9
|
+
module_function
|
10
|
+
|
11
|
+
def key_combinations(keys)
|
12
|
+
localized_keys = LOCALES.map { |locale| [locale, *keys] }
|
13
|
+
|
14
|
+
[keys, *localized_keys]
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/yamlook/node_list.rb
CHANGED
@@ -17,14 +17,16 @@ module Yamlook
|
|
17
17
|
end
|
18
18
|
|
19
19
|
def search(keys)
|
20
|
-
|
20
|
+
return [] unless nodes
|
21
|
+
|
22
|
+
keys.each_index.map do |index|
|
21
23
|
key = keys[0..index].join('.')
|
22
24
|
rest_keys = keys[index + 1..-1]
|
23
25
|
result = find(key)
|
24
26
|
|
25
27
|
case result
|
26
28
|
when Mapping then NodeList.from_mapping(result).search(rest_keys)
|
27
|
-
when Scalar then Node.from_scalar(result)
|
29
|
+
when Scalar then Node.from_scalar(result) if rest_keys.empty?
|
28
30
|
end
|
29
31
|
end
|
30
32
|
end
|
data/lib/yamlook/search.rb
CHANGED
@@ -4,12 +4,16 @@ module Yamlook
|
|
4
4
|
# Searches for occurrences of dot-notated keys in all yaml files
|
5
5
|
# of current directory
|
6
6
|
module Search
|
7
|
+
NoArgumentsError = Class.new(ArgumentError)
|
8
|
+
|
7
9
|
EXTENSIONS = %w[yml yaml].freeze
|
8
10
|
PATTERN = EXTENSIONS.map { |ext| ::File.join('**', "*.#{ext}") }.freeze
|
9
11
|
|
10
12
|
module_function
|
11
13
|
|
12
14
|
def perform(keys)
|
15
|
+
raise NoArgumentsError, 'Nothing to seach for.' if keys.empty?
|
16
|
+
|
13
17
|
findings = Dir.glob(PATTERN).map do |filename|
|
14
18
|
result = File.new(filename).search(keys)
|
15
19
|
print_progress(result)
|
@@ -17,6 +21,8 @@ module Yamlook
|
|
17
21
|
end
|
18
22
|
|
19
23
|
print_result(findings.compact)
|
24
|
+
rescue NoArgumentsError => e
|
25
|
+
puts e.message
|
20
26
|
end
|
21
27
|
|
22
28
|
def print_progress(result)
|
data/lib/yamlook/version.rb
CHANGED
data/locales.yaml
ADDED
@@ -0,0 +1,176 @@
|
|
1
|
+
locales:
|
2
|
+
- af
|
3
|
+
- sq
|
4
|
+
- am
|
5
|
+
- ar
|
6
|
+
- ar-dz
|
7
|
+
- ar-bh
|
8
|
+
- ar-eg
|
9
|
+
- ar-iq
|
10
|
+
- ar-jo
|
11
|
+
- ar-kw
|
12
|
+
- ar-lb
|
13
|
+
- ar-ly
|
14
|
+
- ar-ma
|
15
|
+
- ar-om
|
16
|
+
- ar-qa
|
17
|
+
- ar-sa
|
18
|
+
- ar-sy
|
19
|
+
- ar-tn
|
20
|
+
- ar-ae
|
21
|
+
- ar-ye
|
22
|
+
- hy
|
23
|
+
- as
|
24
|
+
- az
|
25
|
+
- az-az
|
26
|
+
- eu
|
27
|
+
- be
|
28
|
+
- bn
|
29
|
+
- bs
|
30
|
+
- bg
|
31
|
+
- my
|
32
|
+
- ca
|
33
|
+
- zh
|
34
|
+
- zh-cn
|
35
|
+
- zh-hk
|
36
|
+
- zh-mo
|
37
|
+
- zh-sg
|
38
|
+
- zh-tw
|
39
|
+
- hr
|
40
|
+
- cs
|
41
|
+
- da
|
42
|
+
- dv
|
43
|
+
- nl
|
44
|
+
- nl-be
|
45
|
+
- nl-nl
|
46
|
+
- en
|
47
|
+
- en-au
|
48
|
+
- en-bz
|
49
|
+
- en-ca
|
50
|
+
- en-cb
|
51
|
+
- en-gb
|
52
|
+
- en-in
|
53
|
+
- en-ie
|
54
|
+
- en-jm
|
55
|
+
- en-nz
|
56
|
+
- en-ph
|
57
|
+
- en-za
|
58
|
+
- en-tt
|
59
|
+
- en-us
|
60
|
+
- et
|
61
|
+
- mk
|
62
|
+
- fo
|
63
|
+
- fa
|
64
|
+
- fi
|
65
|
+
- fr
|
66
|
+
- fr-be
|
67
|
+
- fr-ca
|
68
|
+
- fr-fr
|
69
|
+
- fr-lu
|
70
|
+
- fr-ch
|
71
|
+
- gd
|
72
|
+
- gd-ie
|
73
|
+
- gl
|
74
|
+
- ka
|
75
|
+
- de
|
76
|
+
- de-at
|
77
|
+
- de-de
|
78
|
+
- de-li
|
79
|
+
- de-lu
|
80
|
+
- de-ch
|
81
|
+
- el
|
82
|
+
- gn
|
83
|
+
- gu
|
84
|
+
- he
|
85
|
+
- hi
|
86
|
+
- hu
|
87
|
+
- is
|
88
|
+
- id
|
89
|
+
- it
|
90
|
+
- it-it
|
91
|
+
- it-ch
|
92
|
+
- ja
|
93
|
+
- kn
|
94
|
+
- ks
|
95
|
+
- kk
|
96
|
+
- km
|
97
|
+
- ko
|
98
|
+
- lo
|
99
|
+
- la
|
100
|
+
- lv
|
101
|
+
- lt
|
102
|
+
- ms
|
103
|
+
- ms-bn
|
104
|
+
- ms-my
|
105
|
+
- ml
|
106
|
+
- mt
|
107
|
+
- mi
|
108
|
+
- mr
|
109
|
+
- mn
|
110
|
+
- ne
|
111
|
+
- nb
|
112
|
+
- no-no
|
113
|
+
- nn
|
114
|
+
- or
|
115
|
+
- pl
|
116
|
+
- pt
|
117
|
+
- pt-br
|
118
|
+
- pt-pt
|
119
|
+
- pa
|
120
|
+
- rm
|
121
|
+
- ro
|
122
|
+
- ro-mo
|
123
|
+
- ru
|
124
|
+
- ru-mo
|
125
|
+
- sa
|
126
|
+
- sr
|
127
|
+
- sr-sp
|
128
|
+
- tn
|
129
|
+
- sd
|
130
|
+
- si
|
131
|
+
- sk
|
132
|
+
- sl
|
133
|
+
- so
|
134
|
+
- sb
|
135
|
+
- es
|
136
|
+
- es-ar
|
137
|
+
- es-bo
|
138
|
+
- es-cl
|
139
|
+
- es-co
|
140
|
+
- es-cr
|
141
|
+
- es-do
|
142
|
+
- es-ec
|
143
|
+
- es-sv
|
144
|
+
- es-gt
|
145
|
+
- es-hn
|
146
|
+
- es-mx
|
147
|
+
- es-ni
|
148
|
+
- es-pa
|
149
|
+
- es-py
|
150
|
+
- es-pe
|
151
|
+
- es-pr
|
152
|
+
- es-es
|
153
|
+
- es-uy
|
154
|
+
- es-ve
|
155
|
+
- sw
|
156
|
+
- sv
|
157
|
+
- sv-fi
|
158
|
+
- sv-se
|
159
|
+
- tg
|
160
|
+
- ta
|
161
|
+
- tt
|
162
|
+
- te
|
163
|
+
- th
|
164
|
+
- bo
|
165
|
+
- ts
|
166
|
+
- tr
|
167
|
+
- tk
|
168
|
+
- uk
|
169
|
+
- ur
|
170
|
+
- uz
|
171
|
+
- uz-uz
|
172
|
+
- vi
|
173
|
+
- cy
|
174
|
+
- xh
|
175
|
+
- yi
|
176
|
+
- zu
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yamlook
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Viacheslav Mefodin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-08-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: psych
|
@@ -73,10 +73,12 @@ files:
|
|
73
73
|
- bin/yamlook
|
74
74
|
- lib/yamlook.rb
|
75
75
|
- lib/yamlook/file.rb
|
76
|
+
- lib/yamlook/locale.rb
|
76
77
|
- lib/yamlook/node.rb
|
77
78
|
- lib/yamlook/node_list.rb
|
78
79
|
- lib/yamlook/search.rb
|
79
80
|
- lib/yamlook/version.rb
|
81
|
+
- locales.yaml
|
80
82
|
homepage: https://github.com/sl4vr/yamlook
|
81
83
|
licenses:
|
82
84
|
- MIT
|
@@ -96,7 +98,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
96
98
|
- !ruby/object:Gem::Version
|
97
99
|
version: '0'
|
98
100
|
requirements: []
|
99
|
-
rubygems_version: 3.
|
101
|
+
rubygems_version: 3.0.9
|
100
102
|
signing_key:
|
101
103
|
specification_version: 4
|
102
104
|
summary: Search occurrences of dot-notated yaml keys.
|