yaml_normalizer 1.1.0 → 1.2.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 16763d1b205a80bb7f7f9c41859fc79246544a6ada2ac31b8a07dd81927bc30c
4
- data.tar.gz: 13063de9b8599168a8baa498db8f0aa94ab7039af5b873994281e67fae1781e0
3
+ metadata.gz: 2036bed9f89b7b2aab2dcfbeeb10f2300e31832a0e9bacee0136a7078a91d574
4
+ data.tar.gz: b29a9f93c38c0749cf4058ed981d9533f5560a970cbd3e8f622e7a9e3ce0bb22
5
5
  SHA512:
6
- metadata.gz: c31e31854ead314f718f0299896a45c6d5669896592b2f8f751ed30efa992928fea3ad327597a2d20159dea71b4be5fbe85986f15db62d263fff4f6d3639d8c1
7
- data.tar.gz: '0960b79a9df709d79d37a8c68cc8829aa81d24e2355dc6ee803cbd254d48165b0160d4938378ced917536882ee481e57bdf0a8de5251bc59316aee42c2524ce6'
6
+ metadata.gz: ba8873fe4c0296e7ad4df98df28525d8ef23b815b385fafc39911468956c627631651729fa740845bdc1ccf3cad07d4efcaa9010142e4eaafaed3537bdcdfb22
7
+ data.tar.gz: 074d417f0de927bd0f24f5769eefd02733aaaaefd822b06f433aa4e21c7eb4906d6dfaef5e0c1e6a77e9f7f585d8c79ec616e1aa4ff828bf2c3304a8525512fe
@@ -19,9 +19,7 @@ module YamlNormalizer
19
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
- if recursive && value.instance_of?(Hash)
23
- seed[key] = value.extend(SortByKey).sort_by_key
24
- end
22
+ seed[key] = value.extend(SortByKey).sort_by_key if recursive && value.instance_of?(Hash)
25
23
  end
26
24
  end
27
25
  end
@@ -7,3 +7,4 @@ module YamlNormalizer
7
7
  end
8
8
 
9
9
  require 'yaml_normalizer/helpers/normalize'
10
+ require 'yaml_normalizer/helpers/param_parser'
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'optparse'
4
+
5
+ module YamlNormalizer
6
+ module Helpers
7
+ # Methods handling passing of additional params from CLI
8
+ module ParamParser
9
+ # Parse the params provided to the service
10
+ # @param [Array] args - params passed to the service
11
+ # @return nil
12
+ def parse_params(*args)
13
+ OptionParser.new do |opts|
14
+ opts.banner = "Usage: #{program_name} [options] file1, file2..."
15
+ opts.on('-v', '--version', 'Prints the yaml_normalizer version') { print_version }
16
+ opts.on('-h', '--help', 'Prints this help') { print_help(opts) }
17
+ end.parse(args)
18
+ end
19
+
20
+ # Print current version of the tool
21
+ def print_version
22
+ print("#{YamlNormalizer::VERSION}\n")
23
+ exit_success
24
+ end
25
+
26
+ # Print current version of the tool
27
+ # @param [Option] opts - options of opt_parser object
28
+ # @return nil
29
+ def print_help(opts)
30
+ print(opts)
31
+ exit_success
32
+ end
33
+
34
+ private
35
+
36
+ def program_name
37
+ $PROGRAM_NAME.split('/').last
38
+ end
39
+
40
+ def exit_success
41
+ exit unless ENV['ENV'] == 'test'
42
+ end
43
+ end
44
+ end
45
+ end
@@ -11,6 +11,7 @@ module YamlNormalizer
11
11
  # result = check.call
12
12
  class Check < Base
13
13
  include Helpers::Normalize
14
+ include Helpers::ParamParser
14
15
 
15
16
  # files is a sorted array of file path Strings
16
17
  attr_reader :files
@@ -19,6 +20,7 @@ module YamlNormalizer
19
20
  # more Strings that are interpreted as file glob pattern.
20
21
  # @param *args [Array<String>] a list of file glob patterns
21
22
  def initialize(*args)
23
+ parse_params(*args)
22
24
  files = args.each_with_object([]) { |a, o| o << Dir[a.to_s] }
23
25
  @files = files.flatten.sort.uniq
24
26
  end
@@ -11,6 +11,7 @@ module YamlNormalizer
11
11
  # result = normalize.call
12
12
  class Normalize < Base
13
13
  include Helpers::Normalize
14
+ include Helpers::ParamParser
14
15
 
15
16
  # files is a sorted array of file path Strings
16
17
  attr_reader :files
@@ -19,6 +20,7 @@ module YamlNormalizer
19
20
  # more String that are interpreted as file glob pattern.
20
21
  # @param *args [Array<String>] a list of file glob patterns
21
22
  def initialize(*args)
23
+ parse_params(*args)
22
24
  files = args.each_with_object([]) { |a, o| o << Dir[a.to_s] }
23
25
  @files = files.flatten.sort.uniq
24
26
  end
@@ -2,5 +2,5 @@
2
2
 
3
3
  module YamlNormalizer
4
4
  # The current Yaml Normalizer version
5
- VERSION = '1.1.0'
5
+ VERSION = '1.2.0'
6
6
  end
metadata CHANGED
@@ -1,14 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yaml_normalizer
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Wolfgang Teuber
8
+ - Jan Taras
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2019-05-21 00:00:00.000000000 Z
12
+ date: 2019-08-08 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: peach
@@ -311,7 +312,7 @@ description: |-
311
312
  original file and the resulting file are 100% identical to Psych (stable
312
313
  change).
313
314
  email:
314
- - wolfgang.teuber@sage.com
315
+ - jan.taras@sage.com
315
316
  executables:
316
317
  - yaml_check
317
318
  - yaml_normalize
@@ -327,6 +328,7 @@ files:
327
328
  - lib/yaml_normalizer/ext/sort_by_key.rb
328
329
  - lib/yaml_normalizer/helpers.rb
329
330
  - lib/yaml_normalizer/helpers/normalize.rb
331
+ - lib/yaml_normalizer/helpers/param_parser.rb
330
332
  - lib/yaml_normalizer/rake_task.rb
331
333
  - lib/yaml_normalizer/services.rb
332
334
  - lib/yaml_normalizer/services/base.rb
@@ -353,7 +355,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
353
355
  - !ruby/object:Gem::Version
354
356
  version: '0'
355
357
  requirements: []
356
- rubygems_version: 3.0.3
358
+ rubyforge_project:
359
+ rubygems_version: 2.7.7
357
360
  signing_key:
358
361
  specification_version: 4
359
362
  summary: Yaml Normalizer normalizes YAML files