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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 968d1897a00350db31375552a70066d04d14c4edd7e52406ed2188e4951bb3e2
4
- data.tar.gz: e45f29b9f4c56114fb8c5d546cc25d91f37c785575c1331879c774523b9ed8f6
3
+ metadata.gz: aebec4bd618402d42523186b686d7ccb4de1ca0b5f8e42b7c7bafbe999692ce3
4
+ data.tar.gz: f4340d4cc1f9f35d897dd78e88aff278339361db7e87cc058cd6edac2f9363d6
5
5
  SHA512:
6
- metadata.gz: 3a667a39333140b85e9710f5d8a87e89b3e951fe634065e2f464ddc7e4d7beb23fbfac0096acd72bf01aeaa28a0a322221dca11d1174fbc88728a0f59703a735
7
- data.tar.gz: a1415e35e038896b2205d5fa409483aceedefee8566d43a636471b23c89bb423b1ca7b4c3c650a0f23d5af8d05ea8a9c39865443baa0aeecc12cf9771eca2880
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).
@@ -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
@@ -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.with_index do |_, index|
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 NodeList then result.search(rest_keys)
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
- scalar_index = find_scalar_index(key)
33
- return unless scalar_index
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 find_scalar_index(key)
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Yamlook
4
- VERSION = '0.0.1'
4
+ VERSION = '0.1.2'
5
5
  end
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.0.1
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-09-14 00:00:00.000000000 Z
11
+ date: 2020-11-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: psych