opt_parse_validator 0.0.16.6 → 0.0.17.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
- SHA256:
3
- metadata.gz: f8c4d178693b59eec288e32b8499476cebdb92f2c51781b80f5ce3abefe43c68
4
- data.tar.gz: e48fdc7d0cf5485c6812bc955e87f1348f4aa079448014d835ed0e9c1ed961d8
2
+ SHA1:
3
+ metadata.gz: 315b683b0c51adbc5afc6087639680d8fdd7af7c
4
+ data.tar.gz: 015f3118b80dbf817fafbbfd2f96479a05fa8223
5
5
  SHA512:
6
- metadata.gz: 45bd2b0dfce053981b6fb477d37c5bead11e1dc62d789299bfdc97d80ef95c1e87f9c50dde8579e536c68bd3972e595c62ab4ed78ff5c590b16c99e3417a5c0d
7
- data.tar.gz: ce7a7523d9112dfd4aa6072c64c6b1eaffe155a5a16aa5094b72a8d8ddc7c5d5f9d825151f5c10b5d919908356a67b41550779e52f96e6a76848de10285174f7
6
+ metadata.gz: 6dbf1eaf46c391923531d1eab92d0090c0ac574e617b2499c38ae5d5c55578621fd75bd2f9b62602d9c53eadf0c36588041c38d039896218b7b71002312f95be
7
+ data.tar.gz: 8a6b2b370acc963c084e356edef00f64197d3ffa51263a3780898adb449202e789c299197f5259a629e9014747b52b19d30e5a19d3f5c5946b361cb4644d310a
data/README.md CHANGED
@@ -2,7 +2,7 @@ OptParseValidator
2
2
  =================
3
3
 
4
4
  [![Gem Version](https://badge.fury.io/rb/opt_parse_validator.svg)](https://badge.fury.io/rb/opt_parse_validator)
5
- [![Build Status](https://img.shields.io/travis/wpscanteam/OptParseValidator.svg)](https://travis-ci.org/wpscanteam/OptParseValidator)
5
+ [![Build Status](https://travis-ci.org/wpscanteam/OptParseValidator.svg?branch=master)](https://travis-ci.org/wpscanteam/OptParseValidator)
6
6
  [![Coverage Status](https://img.shields.io/coveralls/wpscanteam/OptParseValidator.svg)](https://coveralls.io/r/wpscanteam/OptParseValidator?branch=master)
7
7
  [![Code Climate](https://api.codeclimate.com/v1/badges/56f0307bbbda6d41b99a/maintainability)](https://codeclimate.com/github/wpscanteam/OptParseValidator/maintainability)
8
8
 
@@ -0,0 +1,25 @@
1
+ module OptParseValidator
2
+ class ConfigFilesLoaderMerger < Array
3
+ module ConfigFile
4
+ # Base class, #parse should be implemented in child classes
5
+ class Base
6
+ attr_reader :path
7
+
8
+ # @param [ String ] path The file path of the option file
9
+ def initialize(path)
10
+ @path = path
11
+ end
12
+
13
+ # @params [ Hash ] opts
14
+ # @return [ Hash ] a { 'key' => value } hash
15
+ def parse(_opts = {})
16
+ raise NotImplementedError
17
+ end
18
+
19
+ def ==(other)
20
+ path == other.path
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,16 @@
1
+ require 'json'
2
+
3
+ module OptParseValidator
4
+ class ConfigFilesLoaderMerger < Array
5
+ module ConfigFile
6
+ # Json Implementation
7
+ class JSON < Base
8
+ # @params [ Hash ] opts
9
+ # @return [ Hash ] a { 'key' => value } hash
10
+ def parse(_opts = {})
11
+ ::JSON.parse(File.read(path))
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,18 @@
1
+ require 'yaml'
2
+
3
+ module OptParseValidator
4
+ class ConfigFilesLoaderMerger < Array
5
+ module ConfigFile
6
+ # Yaml Implementation
7
+ class YML < Base
8
+ # @params [ Hash ] opts
9
+ # @option opts [ Array ] :yaml_arguments See https://ruby-doc.org/stdlib-2.3.1/libdoc/psych/rdoc/Psych.html#method-c-safe_load
10
+ #
11
+ # @return [ Hash ] a { 'key' => value } hash
12
+ def parse(opts = {})
13
+ YAML.safe_load(File.read(path), *opts[:yaml_arguments]) || {}
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,44 @@
1
+ require_relative 'config_files_loader_merger/base'
2
+ require_relative 'config_files_loader_merger/json'
3
+ require_relative 'config_files_loader_merger/yml'
4
+
5
+ module OptParseValidator
6
+ # Options Files container
7
+ class ConfigFilesLoaderMerger < Array
8
+ # @return [ Array<String> ] The downcased supported extensions list
9
+ def self.supported_extensions
10
+ extensions = ConfigFile.constants.select do |const|
11
+ name = ConfigFile.const_get(const)
12
+ name.is_a?(Class) && name != ConfigFile::Base
13
+ end
14
+
15
+ extensions.map { |sym| sym.to_s.downcase }
16
+ end
17
+
18
+ # @param [ String ] file_path
19
+ #
20
+ # @return [ Self ]
21
+ def <<(file_path)
22
+ return self unless File.exist?(file_path)
23
+
24
+ ext = File.extname(file_path).delete('.')
25
+
26
+ raise Error, "The option file's extension '#{ext}' is not supported" unless self.class.supported_extensions.include?(ext)
27
+
28
+ super(ConfigFile.const_get(ext.upcase).new(file_path))
29
+ end
30
+
31
+ # @params [ Hash ] opts
32
+ # @option opts [ Boolean ] :symbolize_keys Whether or not to symbolize keys in the returned hash
33
+ # @option opts [ Array ] :yaml_arguments See https://ruby-doc.org/stdlib-2.3.1/libdoc/psych/rdoc/Psych.html#method-c-safe_load
34
+ #
35
+ # @return [ Hash ]
36
+ def parse(opts = {})
37
+ result = {}
38
+
39
+ each { |option_file| result.deep_merge!(option_file.parse(opts)) }
40
+
41
+ opts[:symbolize_keys] ? result.deep_symbolize_keys : result
42
+ end
43
+ end
44
+ end
@@ -1,4 +1,4 @@
1
1
  # Gem Version
2
2
  module OptParseValidator
3
- VERSION = '0.0.16.6'.freeze
3
+ VERSION = '0.0.17.0'.freeze
4
4
  end
@@ -10,7 +10,7 @@ require 'opt_parse_validator/errors'
10
10
  require 'opt_parse_validator/hacks'
11
11
  require 'opt_parse_validator/opts'
12
12
  require 'opt_parse_validator/version'
13
- require 'opt_parse_validator/options_files'
13
+ require 'opt_parse_validator/config_files_loader_merger' # Could even create a gem out of it, as completely independent
14
14
 
15
15
  # Gem namespace
16
16
  module OptParseValidator
@@ -26,9 +26,9 @@ module OptParseValidator
26
26
  super(banner, width, indent)
27
27
  end
28
28
 
29
- # @return [ OptParseValidator::OptionsFiles ]
29
+ # @return [ OptParseValidator::ConfigFilesLoaderMerger ]
30
30
  def options_files
31
- @options_files ||= OptionsFiles.new
31
+ @options_files ||= ConfigFilesLoaderMerger.new
32
32
  end
33
33
 
34
34
  # @param [ Array<OptBase> ] options
@@ -123,7 +123,7 @@ module OptParseValidator
123
123
 
124
124
  # @return [ Void ]
125
125
  def load_options_files
126
- files_data = options_files.parse(true)
126
+ files_data = options_files.parse(symbolize_keys: true)
127
127
 
128
128
  @opts.each do |opt|
129
129
  next unless files_data.key?(opt.to_sym)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opt_parse_validator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.16.6
4
+ version: 0.0.17.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - WPScanTeam
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-01-11 00:00:00.000000000 Z
11
+ date: 2019-03-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -34,16 +34,22 @@ dependencies:
34
34
  name: addressable
35
35
  requirement: !ruby/object:Gem::Requirement
36
36
  requirements:
37
- - - "~>"
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '2.5'
40
+ - - "<"
38
41
  - !ruby/object:Gem::Version
39
- version: 2.5.0
42
+ version: '2.7'
40
43
  type: :runtime
41
44
  prerelease: false
42
45
  version_requirements: !ruby/object:Gem::Requirement
43
46
  requirements:
44
- - - "~>"
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: '2.5'
50
+ - - "<"
45
51
  - !ruby/object:Gem::Version
46
- version: 2.5.0
52
+ version: '2.7'
47
53
  - !ruby/object:Gem::Dependency
48
54
  name: bundler
49
55
  requirement: !ruby/object:Gem::Requirement
@@ -120,14 +126,14 @@ dependencies:
120
126
  requirements:
121
127
  - - "~>"
122
128
  - !ruby/object:Gem::Version
123
- version: 0.62.0
129
+ version: 0.65.0
124
130
  type: :development
125
131
  prerelease: false
126
132
  version_requirements: !ruby/object:Gem::Requirement
127
133
  requirements:
128
134
  - - "~>"
129
135
  - !ruby/object:Gem::Version
130
- version: 0.62.0
136
+ version: 0.65.0
131
137
  - !ruby/object:Gem::Dependency
132
138
  name: simplecov
133
139
  requirement: !ruby/object:Gem::Requirement
@@ -153,12 +159,12 @@ files:
153
159
  - LICENSE
154
160
  - README.md
155
161
  - lib/opt_parse_validator.rb
162
+ - lib/opt_parse_validator/config_files_loader_merger.rb
163
+ - lib/opt_parse_validator/config_files_loader_merger/base.rb
164
+ - lib/opt_parse_validator/config_files_loader_merger/json.rb
165
+ - lib/opt_parse_validator/config_files_loader_merger/yml.rb
156
166
  - lib/opt_parse_validator/errors.rb
157
167
  - lib/opt_parse_validator/hacks.rb
158
- - lib/opt_parse_validator/options_file/base.rb
159
- - lib/opt_parse_validator/options_file/json.rb
160
- - lib/opt_parse_validator/options_file/yml.rb
161
- - lib/opt_parse_validator/options_files.rb
162
168
  - lib/opt_parse_validator/opts.rb
163
169
  - lib/opt_parse_validator/opts/alias.rb
164
170
  - lib/opt_parse_validator/opts/array.rb
@@ -201,7 +207,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
201
207
  version: '0'
202
208
  requirements: []
203
209
  rubyforge_project:
204
- rubygems_version: 2.7.8
210
+ rubygems_version: 2.6.10
205
211
  signing_key:
206
212
  specification_version: 4
207
213
  summary: Ruby OptionParser Validators
@@ -1,22 +0,0 @@
1
- module OptParseValidator
2
- module OptionsFile
3
- # Base class, #parse should be implemented in child classes
4
- class Base
5
- attr_reader :path
6
-
7
- # @param [ String ] path The file path of the option file
8
- def initialize(path)
9
- @path = path
10
- end
11
-
12
- # @return [ Hash ] a { key: value } hash
13
- def parse
14
- raise NotImplementedError
15
- end
16
-
17
- def ==(other)
18
- path == other.path
19
- end
20
- end
21
- end
22
- end
@@ -1,13 +0,0 @@
1
- require 'json'
2
-
3
- module OptParseValidator
4
- module OptionsFile
5
- # Json Implementation
6
- class JSON < Base
7
- # @return [ Hash ] a { 'key' => value } hash
8
- def parse
9
- ::JSON.parse(File.read(path))
10
- end
11
- end
12
- end
13
- end
@@ -1,13 +0,0 @@
1
- require 'yaml'
2
-
3
- module OptParseValidator
4
- module OptionsFile
5
- # Yaml Implementation
6
- class YML < Base
7
- # @return [ Hash ] a { 'key' => value } hash
8
- def parse
9
- YAML.safe_load(File.read(path)) || {}
10
- end
11
- end
12
- end
13
- end
@@ -1,42 +0,0 @@
1
- require 'opt_parse_validator/options_file/base'
2
- require 'opt_parse_validator/options_file/json'
3
- require 'opt_parse_validator/options_file/yml'
4
-
5
- module OptParseValidator
6
- # Options Files container
7
- class OptionsFiles < Array
8
- # @return [ Array<String> ] The downcased supported extensions list
9
- def supported_extensions
10
- extensions = OptionsFile.constants.select do |const|
11
- name = OptionsFile.const_get(const)
12
- name.is_a?(Class) && name != OptionsFile::Base
13
- end
14
-
15
- extensions.map { |sym| sym.to_s.downcase }
16
- end
17
-
18
- # @param [ String ] file_path
19
- #
20
- # @return [ Self ]
21
- def <<(file_path)
22
- return self unless File.exist?(file_path)
23
-
24
- ext = File.extname(file_path).delete('.')
25
-
26
- raise Error, "The option file's extension '#{ext}' is not supported" unless supported_extensions.include?(ext)
27
-
28
- super(OptionsFile.const_get(ext.upcase).new(file_path))
29
- end
30
-
31
- # @params [ Boolean ] symbolize_keys Whether or not to symbolize keys in the returned hash
32
- #
33
- # @return [ Hash ]
34
- def parse(symbolize_keys = false)
35
- result = {}
36
-
37
- each { |option_file| result.deep_merge!(option_file.parse) }
38
-
39
- symbolize_keys ? result.deep_symbolize_keys : result
40
- end
41
- end
42
- end