yamlook 0.1.0 → 0.3.5

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: 721149ad77c2d1122094c2861ebf1f4d0238dfe475c7849751468f804f94b5c9
4
- data.tar.gz: 5a9bfa6256d28b43c02f2b40ae3a700e3b085c289c7d74a857e3e7d070feb191
3
+ metadata.gz: df1211ccca0c68e598391b78bd6328f09a1f67eb0948a926c5263bfa7206934a
4
+ data.tar.gz: 496953bbe6969dc05ff4165b2ab4ac8a76eb9df68be265b126c2b6eacb7061f8
5
5
  SHA512:
6
- metadata.gz: 031f66fa62e1ddd557f663b085309576c8ebb62cfc671b3d979696b0e8df753598ead9e069ab322ef7631f5f35b3d14749776aa6757fb32079a4378e920b2c5d
7
- data.tar.gz: 110c6cd592fcb0594a5efbd5cb8243bd49b1d6ac1fbedd6e1dd7f8422e7bd8da804a22b9bbbbb905b291e73459a98090822adc65d5c942b7fa3a278a51b8faf8
6
+ metadata.gz: bdf2d00d030814fc65940d1ad4d3bed49dbad70a022945d8b2534f303316646a289670d1e99cf40a8f993870f96cfbd35f942c2b9cb105acccdd6c522272302c
7
+ data.tar.gz: 7c68b6c0b71d2975014197ad68cde9f3e503213d5124ed993df1743530650e15e41ff450fd8b02d981ffde3a168fc567b31daf097823b786e7490fcd9596d06a
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/bin/yamlook CHANGED
@@ -5,4 +5,6 @@ $LOAD_PATH.unshift("#{__dir__}/../lib")
5
5
 
6
6
  require 'yamlook'
7
7
 
8
- Yamlook::Search.perform(ARGV[0].split('.'))
8
+ cli_parser = Yamlook::Cli.new(ARGV)
9
+
10
+ Yamlook::Search.perform(cli_parser.argument.split('.'))
data/lib/yamlook.rb CHANGED
@@ -4,5 +4,7 @@ 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'
10
+ require 'yamlook/cli'
@@ -0,0 +1,56 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'optparse'
4
+ require 'yamlook/version'
5
+
6
+ module Yamlook
7
+ # Yamlook CLI
8
+ class Cli
9
+ attr_reader :arguments, :options
10
+
11
+ def initialize(arguments)
12
+ @arguments = arguments
13
+ @options = {}
14
+
15
+ opt_parser.parse!(@arguments)
16
+
17
+ show_help! if @arguments.empty?
18
+ rescue OptionParser::InvalidOption => e
19
+ puts e
20
+ exit 1
21
+ end
22
+
23
+ def argument
24
+ @arguments.first
25
+ end
26
+
27
+ private
28
+
29
+ # rubocop:disable Metrics/MethodLength
30
+ def opt_parser
31
+ @opt_parser ||= OptionParser.new do |opts|
32
+ opts.banner = 'Usage: yamlook KEYS'
33
+ opts.separator ''
34
+ opts.separator 'Example: yamlook some.deep.key.in.you.yaml.file'
35
+
36
+ opts.separator ''
37
+ opts.separator 'Options:'
38
+ opts.on_tail('-h', '--help', 'Show this message') do
39
+ puts opts.help
40
+ exit
41
+ end
42
+
43
+ opts.on_tail('--version', 'Show version') do
44
+ puts Yamlook::VERSION
45
+ exit
46
+ end
47
+ end
48
+ end
49
+ # rubocop:enable Metrics/MethodLength
50
+
51
+ def show_help!
52
+ puts opt_parser.help
53
+ exit
54
+ end
55
+ end
56
+ end
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.0'
4
+ VERSION = '0.3.5'
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.0
4
+ version: 0.3.5
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-09-22 00:00:00.000000000 Z
11
+ date: 2021-08-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: psych
@@ -72,11 +72,14 @@ files:
72
72
  - README.md
73
73
  - bin/yamlook
74
74
  - lib/yamlook.rb
75
+ - lib/yamlook/cli.rb
75
76
  - lib/yamlook/file.rb
77
+ - lib/yamlook/locale.rb
76
78
  - lib/yamlook/node.rb
77
79
  - lib/yamlook/node_list.rb
78
80
  - lib/yamlook/search.rb
79
81
  - lib/yamlook/version.rb
82
+ - locales.yaml
80
83
  homepage: https://github.com/sl4vr/yamlook
81
84
  licenses:
82
85
  - MIT
@@ -96,7 +99,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
96
99
  - !ruby/object:Gem::Version
97
100
  version: '0'
98
101
  requirements: []
99
- rubygems_version: 3.1.2
102
+ rubygems_version: 3.1.4
100
103
  signing_key:
101
104
  specification_version: 4
102
105
  summary: Search occurrences of dot-notated yaml keys.