yamlook 0.0.1 → 0.1.2
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/node.rb +7 -7
- data/lib/yamlook/node_list.rb +10 -12
- data/lib/yamlook/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aebec4bd618402d42523186b686d7ccb4de1ca0b5f8e42b7c7bafbe999692ce3
|
4
|
+
data.tar.gz: f4340d4cc1f9f35d897dd78e88aff278339361db7e87cc058cd6edac2f9363d6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 21a8e45883a890fdfb1d054f3029f53cd8dae4841f1baf3f8a4fa09145721d1e1ec71abdc8f137fe004314260403df199016f29c1ce11e07d22fb9803415ca90
|
7
|
+
data.tar.gz: d095774554d7022fed685a86f532a6fc9b45eebd899fb8e4f8d5347a0e2deb16e9c3324c4875c6f4896eb116054de9a386b5e35eced0bdaf694c80fe3f0816a4
|
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/node.rb
CHANGED
@@ -6,13 +6,6 @@ module Yamlook
|
|
6
6
|
attr_reader :value, :line, :column
|
7
7
|
attr_accessor :filename
|
8
8
|
|
9
|
-
def initialize(value:, line:, column:, filename: nil)
|
10
|
-
@value = value
|
11
|
-
@line = line
|
12
|
-
@column = column
|
13
|
-
@filename = filename
|
14
|
-
end
|
15
|
-
|
16
9
|
def self.from_scalar(scalar)
|
17
10
|
return unless scalar
|
18
11
|
|
@@ -23,6 +16,13 @@ module Yamlook
|
|
23
16
|
)
|
24
17
|
end
|
25
18
|
|
19
|
+
def initialize(value:, line:, column:, filename: nil)
|
20
|
+
@value = value
|
21
|
+
@line = line
|
22
|
+
@column = column
|
23
|
+
@filename = filename
|
24
|
+
end
|
25
|
+
|
26
26
|
def to_s
|
27
27
|
"#{filename}:#{line}:#{column}\n#{value}"
|
28
28
|
end
|
data/lib/yamlook/node_list.rb
CHANGED
@@ -8,20 +8,23 @@ module Yamlook
|
|
8
8
|
class NodeList
|
9
9
|
attr_reader :nodes
|
10
10
|
|
11
|
+
def self.from_mapping(mapping)
|
12
|
+
new(mapping.children)
|
13
|
+
end
|
14
|
+
|
11
15
|
def initialize(nodes)
|
12
16
|
@nodes = nodes
|
13
17
|
end
|
14
18
|
|
15
19
|
def search(keys)
|
16
|
-
keys.map
|
20
|
+
keys.each_index.map do |index|
|
17
21
|
key = keys[0..index].join('.')
|
18
22
|
rest_keys = keys[index + 1..-1]
|
19
|
-
|
20
23
|
result = find(key)
|
21
24
|
|
22
25
|
case result
|
23
|
-
when
|
24
|
-
when Scalar then Node.from_scalar(result)
|
26
|
+
when Mapping then NodeList.from_mapping(result).search(rest_keys)
|
27
|
+
when Scalar then Node.from_scalar(result) if rest_keys.empty?
|
25
28
|
end
|
26
29
|
end
|
27
30
|
end
|
@@ -29,16 +32,11 @@ module Yamlook
|
|
29
32
|
private
|
30
33
|
|
31
34
|
def find(key)
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
result = nodes[scalar_index + 1]
|
36
|
-
return NodeList.new(result.children) if result.is_a?(Mapping)
|
37
|
-
|
38
|
-
result
|
35
|
+
key_node_index = find_key_node_index(key)
|
36
|
+
nodes[key_node_index + 1] if key_node_index
|
39
37
|
end
|
40
38
|
|
41
|
-
def
|
39
|
+
def find_key_node_index(key)
|
42
40
|
nodes.find_index { |node| node.is_a?(Scalar) && node.value == key }
|
43
41
|
end
|
44
42
|
end
|
data/lib/yamlook/version.rb
CHANGED
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.1.2
|
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
|
+
date: 2020-11-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: psych
|