yaml_normalizer 2.0.0 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/yaml_normalizer/ext/sort_by_key.rb +1 -1
- data/lib/yaml_normalizer/helpers/normalize.rb +5 -3
- data/lib/yaml_normalizer/helpers/param_parser.rb +8 -12
- data/lib/yaml_normalizer/rake_task.rb +15 -16
- data/lib/yaml_normalizer/services/check.rb +2 -1
- data/lib/yaml_normalizer/services/is_yaml.rb +1 -0
- data/lib/yaml_normalizer/services/normalize.rb +2 -1
- data/lib/yaml_normalizer/version.rb +1 -1
- metadata +2 -268
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 147c80fe321c3b244de1fe9456de27af5d1b124d8ad31d7f564b0b7ab6d1db2f
|
4
|
+
data.tar.gz: c3f856e4eb45b53bfe63e3cf9122aac358ff37d0a85d53116cf576422195c58a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7c7771f0ccecfbd8dd6877c2fa011aa107fc7a5e5945d98565f2b156edfd202ad7e18e082761e47314b634cb3fc66a278e4e32524aeacf3965d8bb53f5db06d1
|
7
|
+
data.tar.gz: 24450ee1daa379f169f4f8f5a6859ff22ebfcf5fe8c5675c716384c9c2ff85e4274b757f4713e40cc906c52b6c8d8c2b3db62a0d4834598ca6b687612645cff2
|
@@ -16,7 +16,7 @@ module YamlNormalizer
|
|
16
16
|
# => {:a=>nil, :b=>{:x=>10, :y=>{:a=>2, :b=>1}, :z=>20}}
|
17
17
|
# @param recursive [Boolean] defines if sort_by_key is called on child
|
18
18
|
# nodes, defaults to true
|
19
|
-
def sort_by_key(recursive
|
19
|
+
def sort_by_key(recursive: true)
|
20
20
|
keys.sort_by(&:to_s).each_with_object({}) do |key, seed|
|
21
21
|
value = seed[key] = fetch(key)
|
22
22
|
seed[key] = value.extend(SortByKey).sort_by_key if recursive && value.instance_of?(Hash)
|
@@ -23,8 +23,10 @@ module YamlNormalizer
|
|
23
23
|
# @return [String] normalized YAML string
|
24
24
|
def normalize_yaml(yaml)
|
25
25
|
hashes = parse(yaml).transform
|
26
|
-
hashes.
|
27
|
-
|
26
|
+
hashes.map do |hash|
|
27
|
+
hash.extend(Ext::SortByKey)
|
28
|
+
hash.sort_by_key.to_yaml
|
29
|
+
end.join
|
28
30
|
end
|
29
31
|
|
30
32
|
private
|
@@ -39,7 +41,7 @@ module YamlNormalizer
|
|
39
41
|
|
40
42
|
def relative_path_for(file)
|
41
43
|
realpath = Pathname.new(file).realpath
|
42
|
-
realpath.relative_path_from(
|
44
|
+
realpath.relative_path_from(Dir.pwd)
|
43
45
|
end
|
44
46
|
end
|
45
47
|
end
|
@@ -12,23 +12,23 @@ module YamlNormalizer
|
|
12
12
|
def parse_params(*args)
|
13
13
|
OptionParser.new do |opts|
|
14
14
|
opts.banner = "Usage: #{program_name} [options] file1, file2..."
|
15
|
-
opts.on('-v', '--version', 'Prints the yaml_normalizer version') { print_version }
|
16
15
|
opts.on('-h', '--help', 'Prints this help') { print_help(opts) }
|
16
|
+
opts.on('-v', '--version', 'Prints the yaml_normalizer version') { print_version }
|
17
17
|
end.parse(args)
|
18
18
|
end
|
19
19
|
|
20
|
-
# Print current version of the tool
|
21
|
-
def print_version
|
22
|
-
print("#{YamlNormalizer::VERSION}\n")
|
23
|
-
exit_success
|
24
|
-
end
|
25
|
-
|
26
20
|
# Print current version of the tool
|
27
21
|
# @param [Option] opts - options of opt_parser object
|
28
22
|
# @return nil
|
29
23
|
def print_help(opts)
|
30
24
|
print(opts)
|
31
|
-
|
25
|
+
exit
|
26
|
+
end
|
27
|
+
|
28
|
+
# Print current version of the tool
|
29
|
+
def print_version
|
30
|
+
print("#{VERSION}\n")
|
31
|
+
exit
|
32
32
|
end
|
33
33
|
|
34
34
|
private
|
@@ -36,10 +36,6 @@ module YamlNormalizer
|
|
36
36
|
def program_name
|
37
37
|
$PROGRAM_NAME.split('/').last
|
38
38
|
end
|
39
|
-
|
40
|
-
def exit_success
|
41
|
-
exit unless ENV['ENV'] == 'test'
|
42
|
-
end
|
43
39
|
end
|
44
40
|
end
|
45
41
|
end
|
@@ -8,35 +8,34 @@ require 'rake/tasklib'
|
|
8
8
|
module YamlNormalizer
|
9
9
|
# Provides Rake task integration
|
10
10
|
class RakeTask < ::Rake::TaskLib
|
11
|
-
# The name of the task
|
12
|
-
# @return [String] name of the
|
11
|
+
# The name of the rake task
|
12
|
+
# @return [String] name of the rake task
|
13
13
|
attr_accessor :name
|
14
14
|
|
15
15
|
# The YAML files to process.
|
16
|
-
# @example
|
16
|
+
# @example
|
17
17
|
# YamlNormalizer::RakeTask.new do |task|
|
18
18
|
# task.files = ['config/locale/*.yml', 'config/*.yml']
|
19
19
|
# end
|
20
20
|
# @return [Array<String>] a list of file globing Strings
|
21
21
|
attr_accessor :files
|
22
22
|
|
23
|
-
#
|
24
|
-
#
|
25
|
-
# @example
|
26
|
-
# In your Rakefile, add:
|
27
|
-
# YamlNormalizer::RakeTask.new
|
23
|
+
# Add YAML Normalizer rake tasks to your project by adding the following line to your Rakefile:
|
24
|
+
# YamlNormalizer::RakeTask.new
|
28
25
|
#
|
29
|
-
#
|
30
|
-
#
|
31
|
-
#
|
32
|
-
#
|
26
|
+
# This gives you the following tasks (run rake -T)
|
27
|
+
# rake yaml:check # Check if configured YAML files are normalized
|
28
|
+
# rake yaml:normalize # Normalize configured YAML files
|
29
|
+
#
|
30
|
+
# @example Configure YAML Normalizer's rake task
|
31
|
+
# YamlNormalizer::RakeTask.new do |config|
|
32
|
+
# config.files = Dir[File.join(File.dirname(__FILE__), 'include.yml')]
|
33
|
+
# end
|
33
34
|
#
|
34
|
-
#
|
35
|
-
# rake yaml:check # Check if given YAML are normalized
|
36
|
-
# rake yaml:normalize # Normalize given YAML files
|
37
|
-
# @param name [String] name of the Rake task
|
35
|
+
# @param name [String] name of the rake task
|
38
36
|
# @param &block [Proc] optional, evaluated inside the task definition
|
39
37
|
def initialize(name = 'yaml', &block)
|
38
|
+
super()
|
40
39
|
yield(self) if block
|
41
40
|
|
42
41
|
desc 'Check if configured YAML files are normalized'
|
@@ -20,6 +20,7 @@ module YamlNormalizer
|
|
20
20
|
# more Strings that are interpreted as file glob pattern.
|
21
21
|
# @param *args [Array<String>] a list of file glob patterns
|
22
22
|
def initialize(*args)
|
23
|
+
super
|
23
24
|
parse_params(*args)
|
24
25
|
files = args.each_with_object([]) { |a, o| o << Dir[a.to_s] }
|
25
26
|
@files = files.flatten.sort.uniq
|
@@ -37,7 +38,7 @@ module YamlNormalizer
|
|
37
38
|
def process(file)
|
38
39
|
return true if IsYaml.call(file) && normalized?(file)
|
39
40
|
|
40
|
-
$stderr.print "#{file} not a YAML file\n"
|
41
|
+
$stderr.print "#{file} is not a YAML file\n"
|
41
42
|
nil
|
42
43
|
end
|
43
44
|
|
@@ -20,6 +20,7 @@ module YamlNormalizer
|
|
20
20
|
# more String that are interpreted as file glob pattern.
|
21
21
|
# @param *args [Array<String>] a list of file glob patterns
|
22
22
|
def initialize(*args)
|
23
|
+
super
|
23
24
|
parse_params(*args)
|
24
25
|
files = args.each_with_object([]) { |a, o| o << Dir[a.to_s] }
|
25
26
|
@files = files.flatten.sort.uniq
|
@@ -43,7 +44,7 @@ module YamlNormalizer
|
|
43
44
|
def normalize!(file)
|
44
45
|
file = relative_path_for(file)
|
45
46
|
if stable?(input = read(file), norm = normalize_yaml(input))
|
46
|
-
File.
|
47
|
+
File.write(file, norm)
|
47
48
|
$stderr.print "[NORMALIZED] #{file}\n"
|
48
49
|
else
|
49
50
|
$stderr.print "[ERROR] Could not normalize #{file}\n"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yaml_normalizer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- The Sage Group plc
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-09-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: peach
|
@@ -52,272 +52,6 @@ dependencies:
|
|
52
52
|
- - "<"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '14.0'
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: awesome_print
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - ">="
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '0'
|
62
|
-
type: :development
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - ">="
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: '0'
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
name: bundler
|
71
|
-
requirement: !ruby/object:Gem::Requirement
|
72
|
-
requirements:
|
73
|
-
- - ">="
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
version: '0'
|
76
|
-
type: :development
|
77
|
-
prerelease: false
|
78
|
-
version_requirements: !ruby/object:Gem::Requirement
|
79
|
-
requirements:
|
80
|
-
- - ">="
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
version: '0'
|
83
|
-
- !ruby/object:Gem::Dependency
|
84
|
-
name: flog
|
85
|
-
requirement: !ruby/object:Gem::Requirement
|
86
|
-
requirements:
|
87
|
-
- - ">="
|
88
|
-
- !ruby/object:Gem::Version
|
89
|
-
version: '0'
|
90
|
-
type: :development
|
91
|
-
prerelease: false
|
92
|
-
version_requirements: !ruby/object:Gem::Requirement
|
93
|
-
requirements:
|
94
|
-
- - ">="
|
95
|
-
- !ruby/object:Gem::Version
|
96
|
-
version: '0'
|
97
|
-
- !ruby/object:Gem::Dependency
|
98
|
-
name: github-markup
|
99
|
-
requirement: !ruby/object:Gem::Requirement
|
100
|
-
requirements:
|
101
|
-
- - ">="
|
102
|
-
- !ruby/object:Gem::Version
|
103
|
-
version: '0'
|
104
|
-
type: :development
|
105
|
-
prerelease: false
|
106
|
-
version_requirements: !ruby/object:Gem::Requirement
|
107
|
-
requirements:
|
108
|
-
- - ">="
|
109
|
-
- !ruby/object:Gem::Version
|
110
|
-
version: '0'
|
111
|
-
- !ruby/object:Gem::Dependency
|
112
|
-
name: guard
|
113
|
-
requirement: !ruby/object:Gem::Requirement
|
114
|
-
requirements:
|
115
|
-
- - ">="
|
116
|
-
- !ruby/object:Gem::Version
|
117
|
-
version: '0'
|
118
|
-
type: :development
|
119
|
-
prerelease: false
|
120
|
-
version_requirements: !ruby/object:Gem::Requirement
|
121
|
-
requirements:
|
122
|
-
- - ">="
|
123
|
-
- !ruby/object:Gem::Version
|
124
|
-
version: '0'
|
125
|
-
- !ruby/object:Gem::Dependency
|
126
|
-
name: guard-rspec
|
127
|
-
requirement: !ruby/object:Gem::Requirement
|
128
|
-
requirements:
|
129
|
-
- - ">="
|
130
|
-
- !ruby/object:Gem::Version
|
131
|
-
version: '0'
|
132
|
-
type: :development
|
133
|
-
prerelease: false
|
134
|
-
version_requirements: !ruby/object:Gem::Requirement
|
135
|
-
requirements:
|
136
|
-
- - ">="
|
137
|
-
- !ruby/object:Gem::Version
|
138
|
-
version: '0'
|
139
|
-
- !ruby/object:Gem::Dependency
|
140
|
-
name: guard-rubocop
|
141
|
-
requirement: !ruby/object:Gem::Requirement
|
142
|
-
requirements:
|
143
|
-
- - ">="
|
144
|
-
- !ruby/object:Gem::Version
|
145
|
-
version: '0'
|
146
|
-
type: :development
|
147
|
-
prerelease: false
|
148
|
-
version_requirements: !ruby/object:Gem::Requirement
|
149
|
-
requirements:
|
150
|
-
- - ">="
|
151
|
-
- !ruby/object:Gem::Version
|
152
|
-
version: '0'
|
153
|
-
- !ruby/object:Gem::Dependency
|
154
|
-
name: inch
|
155
|
-
requirement: !ruby/object:Gem::Requirement
|
156
|
-
requirements:
|
157
|
-
- - ">="
|
158
|
-
- !ruby/object:Gem::Version
|
159
|
-
version: '0'
|
160
|
-
type: :development
|
161
|
-
prerelease: false
|
162
|
-
version_requirements: !ruby/object:Gem::Requirement
|
163
|
-
requirements:
|
164
|
-
- - ">="
|
165
|
-
- !ruby/object:Gem::Version
|
166
|
-
version: '0'
|
167
|
-
- !ruby/object:Gem::Dependency
|
168
|
-
name: mutant-rspec
|
169
|
-
requirement: !ruby/object:Gem::Requirement
|
170
|
-
requirements:
|
171
|
-
- - ">="
|
172
|
-
- !ruby/object:Gem::Version
|
173
|
-
version: '0'
|
174
|
-
type: :development
|
175
|
-
prerelease: false
|
176
|
-
version_requirements: !ruby/object:Gem::Requirement
|
177
|
-
requirements:
|
178
|
-
- - ">="
|
179
|
-
- !ruby/object:Gem::Version
|
180
|
-
version: '0'
|
181
|
-
- !ruby/object:Gem::Dependency
|
182
|
-
name: pry
|
183
|
-
requirement: !ruby/object:Gem::Requirement
|
184
|
-
requirements:
|
185
|
-
- - ">="
|
186
|
-
- !ruby/object:Gem::Version
|
187
|
-
version: '0'
|
188
|
-
type: :development
|
189
|
-
prerelease: false
|
190
|
-
version_requirements: !ruby/object:Gem::Requirement
|
191
|
-
requirements:
|
192
|
-
- - ">="
|
193
|
-
- !ruby/object:Gem::Version
|
194
|
-
version: '0'
|
195
|
-
- !ruby/object:Gem::Dependency
|
196
|
-
name: pry-byebug
|
197
|
-
requirement: !ruby/object:Gem::Requirement
|
198
|
-
requirements:
|
199
|
-
- - ">="
|
200
|
-
- !ruby/object:Gem::Version
|
201
|
-
version: '0'
|
202
|
-
type: :development
|
203
|
-
prerelease: false
|
204
|
-
version_requirements: !ruby/object:Gem::Requirement
|
205
|
-
requirements:
|
206
|
-
- - ">="
|
207
|
-
- !ruby/object:Gem::Version
|
208
|
-
version: '0'
|
209
|
-
- !ruby/object:Gem::Dependency
|
210
|
-
name: pry-doc
|
211
|
-
requirement: !ruby/object:Gem::Requirement
|
212
|
-
requirements:
|
213
|
-
- - ">="
|
214
|
-
- !ruby/object:Gem::Version
|
215
|
-
version: '0'
|
216
|
-
type: :development
|
217
|
-
prerelease: false
|
218
|
-
version_requirements: !ruby/object:Gem::Requirement
|
219
|
-
requirements:
|
220
|
-
- - ">="
|
221
|
-
- !ruby/object:Gem::Version
|
222
|
-
version: '0'
|
223
|
-
- !ruby/object:Gem::Dependency
|
224
|
-
name: rb-readline
|
225
|
-
requirement: !ruby/object:Gem::Requirement
|
226
|
-
requirements:
|
227
|
-
- - ">="
|
228
|
-
- !ruby/object:Gem::Version
|
229
|
-
version: '0'
|
230
|
-
type: :development
|
231
|
-
prerelease: false
|
232
|
-
version_requirements: !ruby/object:Gem::Requirement
|
233
|
-
requirements:
|
234
|
-
- - ">="
|
235
|
-
- !ruby/object:Gem::Version
|
236
|
-
version: '0'
|
237
|
-
- !ruby/object:Gem::Dependency
|
238
|
-
name: redcarpet
|
239
|
-
requirement: !ruby/object:Gem::Requirement
|
240
|
-
requirements:
|
241
|
-
- - ">="
|
242
|
-
- !ruby/object:Gem::Version
|
243
|
-
version: '0'
|
244
|
-
type: :development
|
245
|
-
prerelease: false
|
246
|
-
version_requirements: !ruby/object:Gem::Requirement
|
247
|
-
requirements:
|
248
|
-
- - ">="
|
249
|
-
- !ruby/object:Gem::Version
|
250
|
-
version: '0'
|
251
|
-
- !ruby/object:Gem::Dependency
|
252
|
-
name: rspec
|
253
|
-
requirement: !ruby/object:Gem::Requirement
|
254
|
-
requirements:
|
255
|
-
- - ">="
|
256
|
-
- !ruby/object:Gem::Version
|
257
|
-
version: '0'
|
258
|
-
type: :development
|
259
|
-
prerelease: false
|
260
|
-
version_requirements: !ruby/object:Gem::Requirement
|
261
|
-
requirements:
|
262
|
-
- - ">="
|
263
|
-
- !ruby/object:Gem::Version
|
264
|
-
version: '0'
|
265
|
-
- !ruby/object:Gem::Dependency
|
266
|
-
name: rubocop
|
267
|
-
requirement: !ruby/object:Gem::Requirement
|
268
|
-
requirements:
|
269
|
-
- - ">="
|
270
|
-
- !ruby/object:Gem::Version
|
271
|
-
version: '0'
|
272
|
-
type: :development
|
273
|
-
prerelease: false
|
274
|
-
version_requirements: !ruby/object:Gem::Requirement
|
275
|
-
requirements:
|
276
|
-
- - ">="
|
277
|
-
- !ruby/object:Gem::Version
|
278
|
-
version: '0'
|
279
|
-
- !ruby/object:Gem::Dependency
|
280
|
-
name: rubocop-performance
|
281
|
-
requirement: !ruby/object:Gem::Requirement
|
282
|
-
requirements:
|
283
|
-
- - ">="
|
284
|
-
- !ruby/object:Gem::Version
|
285
|
-
version: '0'
|
286
|
-
type: :development
|
287
|
-
prerelease: false
|
288
|
-
version_requirements: !ruby/object:Gem::Requirement
|
289
|
-
requirements:
|
290
|
-
- - ">="
|
291
|
-
- !ruby/object:Gem::Version
|
292
|
-
version: '0'
|
293
|
-
- !ruby/object:Gem::Dependency
|
294
|
-
name: simplecov
|
295
|
-
requirement: !ruby/object:Gem::Requirement
|
296
|
-
requirements:
|
297
|
-
- - ">="
|
298
|
-
- !ruby/object:Gem::Version
|
299
|
-
version: '0'
|
300
|
-
type: :development
|
301
|
-
prerelease: false
|
302
|
-
version_requirements: !ruby/object:Gem::Requirement
|
303
|
-
requirements:
|
304
|
-
- - ">="
|
305
|
-
- !ruby/object:Gem::Version
|
306
|
-
version: '0'
|
307
|
-
- !ruby/object:Gem::Dependency
|
308
|
-
name: yard
|
309
|
-
requirement: !ruby/object:Gem::Requirement
|
310
|
-
requirements:
|
311
|
-
- - ">="
|
312
|
-
- !ruby/object:Gem::Version
|
313
|
-
version: '0'
|
314
|
-
type: :development
|
315
|
-
prerelease: false
|
316
|
-
version_requirements: !ruby/object:Gem::Requirement
|
317
|
-
requirements:
|
318
|
-
- - ">="
|
319
|
-
- !ruby/object:Gem::Version
|
320
|
-
version: '0'
|
321
55
|
description: |-
|
322
56
|
Yaml Normalizer follows the notion that there is
|
323
57
|
a normalized YAML file format. It re-formats YAML files in a way that the
|