dorian-sort-yaml 0.1.0

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.
Files changed (4) hide show
  1. checksums.yaml +7 -0
  2. data/bin/sort-yaml +4 -0
  3. data/lib/dorian/sort-yaml.rb +32 -0
  4. metadata +48 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 8bad7f8409471b619ce00f1b0603e38e896f93313df355fcb9e72e4ce49ecc0c
4
+ data.tar.gz: f2bac6f4510d1e8c1be8f006323ddbac80f519a3c9e2ec085041fc0ad3b9e3c0
5
+ SHA512:
6
+ metadata.gz: cea5b954a402a7d658978d057169fe6f2f362bae969a730b951afb028eb9a864756406a5bc637556ca730a0b9a67300df9077132694555ca8cf4953807c9bf29
7
+ data.tar.gz: db6913ff0487f54aad2b60897174024d3e9ef6da472bf5c245fea923f066d30299ed3af1e9f00042c746c1e3a3c0f2046d1610c6847acbb4259a4159724855dd
data/bin/sort-yaml ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'dorian/sort-yaml'
4
+ Dorian::SortYaml.run
@@ -0,0 +1,32 @@
1
+ require 'yaml'
2
+
3
+ module Dorian
4
+ class SortYaml
5
+ def self.run
6
+ if ARGV.size < 1
7
+ puts 'USAGE: sort-yaml FILE [FILE...]'
8
+ exit
9
+ end
10
+
11
+ ARGV.each do |filepath|
12
+ File.write(
13
+ filepath,
14
+ sort_yaml(YAML.safe_load(File.read(filepath))).to_yaml
15
+ )
16
+ end
17
+ end
18
+
19
+ def self.sort_yaml(data)
20
+ if data.is_a?(Array)
21
+ data.map { |element| sort_yaml(element) }
22
+ elsif data.is_a?(Hash)
23
+ data
24
+ .sort_by { |key, _value| key }
25
+ .to_h
26
+ .transform_values { |value| sort_yaml(value) }
27
+ else
28
+ data
29
+ end
30
+ end
31
+ end
32
+ end
metadata ADDED
@@ -0,0 +1,48 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dorian-sort-yaml
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Dorian Marié
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2021-10-10 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: |-
14
+ Sorts keys of hashes of YAML files
15
+
16
+ e.g. `sort-yaml config/locales/*`
17
+ email: dorian@dorianmarie.fr
18
+ executables:
19
+ - sort-yaml
20
+ extensions: []
21
+ extra_rdoc_files: []
22
+ files:
23
+ - bin/sort-yaml
24
+ - lib/dorian/sort-yaml.rb
25
+ homepage: https://github.com/dorianmariefr/sort-yaml
26
+ licenses:
27
+ - MIT
28
+ metadata: {}
29
+ post_install_message:
30
+ rdoc_options: []
31
+ require_paths:
32
+ - lib
33
+ required_ruby_version: !ruby/object:Gem::Requirement
34
+ requirements:
35
+ - - ">="
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ required_rubygems_version: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: '0'
43
+ requirements: []
44
+ rubygems_version: 3.2.22
45
+ signing_key:
46
+ specification_version: 4
47
+ summary: Sorts keys of hashes of YAML files
48
+ test_files: []