yamlook 0.1.2 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: aebec4bd618402d42523186b686d7ccb4de1ca0b5f8e42b7c7bafbe999692ce3
4
- data.tar.gz: f4340d4cc1f9f35d897dd78e88aff278339361db7e87cc058cd6edac2f9363d6
3
+ metadata.gz: 867706c81bb16407e762b76754d645825cdb6ba53030ac1ce5bf99d46087b5a9
4
+ data.tar.gz: 1c0a8face94149303d06484573db378b23cfe8a6e6d0e7ab6229737f62201103
5
5
  SHA512:
6
- metadata.gz: 21a8e45883a890fdfb1d054f3029f53cd8dae4841f1baf3f8a4fa09145721d1e1ec71abdc8f137fe004314260403df199016f29c1ce11e07d22fb9803415ca90
7
- data.tar.gz: d095774554d7022fed685a86f532a6fc9b45eebd899fb8e4f8d5347a0e2deb16e9c3324c4875c6f4896eb116054de9a386b5e35eced0bdaf694c80fe3f0816a4
6
+ metadata.gz: a2c4351ab5486d2a8802f935afc331af435b7655f0de81dae3f030235524682f80c8f867af85f5a041b0e70699c4edf74ec62e2bae1488353647310576abc7c8
7
+ data.tar.gz: db2af0dcb85bc99700317118320453aad3dc8d1e46d8597e80e069b3f24687d2a4105203a82fdbf954ebe57eeb2c7e40108da3880a3131431a6aa255bf5f6667
data/lib/yamlook.rb CHANGED
@@ -4,5 +4,6 @@ require 'psych'
4
4
 
5
5
  require 'yamlook/node'
6
6
  require 'yamlook/node_list'
7
+ require 'yamlook/locale'
7
8
  require 'yamlook/file'
8
9
  require 'yamlook/search'
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 = root_node_list.search(keys).flatten.compact.map do |finding|
16
- finding.filename = filename
17
- finding
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(root_mapping.children)
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
@@ -17,6 +17,8 @@ module Yamlook
17
17
  end
18
18
 
19
19
  def search(keys)
20
+ return [] unless nodes
21
+
20
22
  keys.each_index.map do |index|
21
23
  key = keys[0..index].join('.')
22
24
  rest_keys = keys[index + 1..-1]
@@ -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)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Yamlook
4
- VERSION = '0.1.2'
4
+ VERSION = '0.3.1'
5
5
  end
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.1.2
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: 2020-11-07 00:00:00.000000000 Z
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.1.2
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.