mad_flatter 1.0.0.pre.beta → 2.0.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 +4 -4
- data/CHANGELOG.md +14 -3
- data/Gemfile.lock +12 -12
- data/README.md +1 -7
- data/lib/mad_flatter/hash_informable.rb +7 -7
- data/lib/mad_flatter/options.rb +8 -0
- data/lib/mad_flatter/options_validatable.rb +10 -11
- data/lib/mad_flatter/service.rb +4 -0
- data/lib/mad_flatter/version.rb +1 -1
- data/lib/mad_flatter.rb +9 -4
- metadata +5 -6
- data/lib/mad_flatter/hash_retrievable.rb +0 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 970e8a0b3df7bbe9ef22e8aca026ca61aba74d115f24b06f82fd52a0e75fdd71
|
4
|
+
data.tar.gz: 7e60a9691f934b7a438a7c368c53cedb2143099d5ffc523d51c7e72b1274e28d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7c644ab261b05fb7fdec5d1ca050c4d16d2defda599a428be8e224795f4512936758e6cae6a9e833764738744f599d77a563d8b4af63bfedda713b7102ba83a7
|
7
|
+
data.tar.gz: 8d2c362749860e61d29acd458113973a2e2393563742f26292a69ac82dcd9aa38223947c0ac42825ad604a7f16bd27661c572841922ef581cf7550b4546bdccd
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,16 @@
|
|
1
|
-
|
1
|
+
### 2.0.0
|
2
|
+
* Changes
|
3
|
+
* Add spec coverage.
|
4
|
+
* Update README.md.
|
5
|
+
* Breaking change
|
6
|
+
* Remove unused Module HashRetrievable.
|
7
|
+
* Bug Fixes
|
8
|
+
* Fix bug that raised an error when :namespace option is not a Symbol due cut & paste error from validation routine that checked the :metadata option for validity.
|
9
|
+
* Fix bug when checking `MadFlatter::Service#options.namespace? an error was raised if option :namespace was not passed as an option since it is optional.
|
2
10
|
|
3
|
-
|
11
|
+
### 1.0.1-beta
|
12
|
+
* Bug Fixes
|
13
|
+
* Fix bug requiring support codez in lib/mad_flatter.rb.
|
4
14
|
|
5
|
-
-
|
15
|
+
### 1.0.0-alpha
|
16
|
+
* Initial release.
|
data/Gemfile.lock
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
mad_flatter (
|
4
|
+
mad_flatter (2.0.0)
|
5
5
|
activesupport (~> 7.0, >= 7.0.3.1)
|
6
6
|
immutable_struct_ex (~> 0.2.0)
|
7
7
|
|
8
8
|
GEM
|
9
9
|
remote: https://rubygems.org/
|
10
10
|
specs:
|
11
|
-
activesupport (7.0.
|
11
|
+
activesupport (7.0.4)
|
12
12
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
13
13
|
i18n (>= 1.6, < 2)
|
14
14
|
minitest (>= 5.1)
|
@@ -21,11 +21,11 @@ GEM
|
|
21
21
|
docile (1.4.0)
|
22
22
|
i18n (1.12.0)
|
23
23
|
concurrent-ruby (~> 1.0)
|
24
|
-
immutable_struct_ex (0.2.
|
24
|
+
immutable_struct_ex (0.2.3)
|
25
25
|
json (2.6.2)
|
26
26
|
kwalify (0.7.2)
|
27
27
|
method_source (1.0.0)
|
28
|
-
minitest (5.16.
|
28
|
+
minitest (5.16.3)
|
29
29
|
parallel (1.22.1)
|
30
30
|
parser (3.1.2.1)
|
31
31
|
ast (~> 2.4.1)
|
@@ -40,7 +40,7 @@ GEM
|
|
40
40
|
kwalify (~> 0.7.0)
|
41
41
|
parser (~> 3.1.0)
|
42
42
|
rainbow (>= 2.0, < 4.0)
|
43
|
-
regexp_parser (2.
|
43
|
+
regexp_parser (2.6.0)
|
44
44
|
rexml (3.2.5)
|
45
45
|
rspec (3.11.0)
|
46
46
|
rspec-core (~> 3.11.0)
|
@@ -48,14 +48,14 @@ GEM
|
|
48
48
|
rspec-mocks (~> 3.11.0)
|
49
49
|
rspec-core (3.11.0)
|
50
50
|
rspec-support (~> 3.11.0)
|
51
|
-
rspec-expectations (3.11.
|
51
|
+
rspec-expectations (3.11.1)
|
52
52
|
diff-lcs (>= 1.2.0, < 2.0)
|
53
53
|
rspec-support (~> 3.11.0)
|
54
54
|
rspec-mocks (3.11.1)
|
55
55
|
diff-lcs (>= 1.2.0, < 2.0)
|
56
56
|
rspec-support (~> 3.11.0)
|
57
|
-
rspec-support (3.11.
|
58
|
-
rubocop (1.
|
57
|
+
rspec-support (3.11.1)
|
58
|
+
rubocop (1.36.0)
|
59
59
|
json (~> 2.3)
|
60
60
|
parallel (~> 1.10)
|
61
61
|
parser (>= 3.1.2.1)
|
@@ -67,11 +67,11 @@ GEM
|
|
67
67
|
unicode-display_width (>= 1.4.0, < 3.0)
|
68
68
|
rubocop-ast (1.21.0)
|
69
69
|
parser (>= 3.1.1.0)
|
70
|
-
rubocop-performance (1.
|
70
|
+
rubocop-performance (1.15.0)
|
71
71
|
rubocop (>= 1.7.0, < 2.0)
|
72
72
|
rubocop-ast (>= 0.4.0)
|
73
|
-
rubocop-rspec (2.
|
74
|
-
rubocop (~> 1.
|
73
|
+
rubocop-rspec (2.13.2)
|
74
|
+
rubocop (~> 1.33)
|
75
75
|
ruby-progressbar (1.11.0)
|
76
76
|
simplecov (0.21.2)
|
77
77
|
docile (~> 1.1)
|
@@ -81,7 +81,7 @@ GEM
|
|
81
81
|
simplecov_json_formatter (0.1.4)
|
82
82
|
tzinfo (2.0.5)
|
83
83
|
concurrent-ruby (~> 1.0)
|
84
|
-
unicode-display_width (2.
|
84
|
+
unicode-display_width (2.3.0)
|
85
85
|
|
86
86
|
PLATFORMS
|
87
87
|
x86_64-darwin-19
|
data/README.md
CHANGED
@@ -11,13 +11,7 @@
|
|
11
11
|
|
12
12
|
[](#license)
|
13
13
|
|
14
|
-
|
15
|
-
|
16
|
-
TODO: Add specs.
|
17
|
-
TODO: Better documentation.
|
18
|
-
|
19
|
-
mad_flatter is a Ruby gem that takes a Ruby `Hash` and flattens the Hash keys to
|
20
|
-
create a new Hash with unique Hash keys; that is, embedded Hashes use their
|
14
|
+
mad_flatter is a Ruby gem that takes a Ruby `Hash` and flattens the Hash keys to create a new Hash with unique Hash keys; that is, embedded Hashes use their
|
21
15
|
respective keys as namespaces to create unique keys across the entire Hash.
|
22
16
|
For example:
|
23
17
|
|
@@ -9,16 +9,16 @@ module MadFlatter
|
|
9
9
|
hash.each do |key, value|
|
10
10
|
if value.is_a? Hash
|
11
11
|
load_hash_info(hash: value,
|
12
|
-
|
13
|
-
|
14
|
-
|
12
|
+
namespace: namespace,
|
13
|
+
dig: dig << key,
|
14
|
+
hash_info: hash_info)
|
15
15
|
dig.pop
|
16
16
|
else
|
17
17
|
assign_hash_info(hash_info: hash_info,
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
18
|
+
key: key,
|
19
|
+
value: value,
|
20
|
+
namespace: namespace,
|
21
|
+
dig: dig)
|
22
22
|
end
|
23
23
|
|
24
24
|
next
|
data/lib/mad_flatter/options.rb
CHANGED
@@ -14,10 +14,16 @@ module MadFlatter
|
|
14
14
|
def new(**options)
|
15
15
|
immutable_struct_ex = ImmutableStructEx.new(**options) do
|
16
16
|
def namespace?
|
17
|
+
return false unless respond_to? :namespace
|
18
|
+
|
17
19
|
namespace || false
|
18
20
|
end
|
19
21
|
|
20
22
|
def metadata?
|
23
|
+
# This should never return false since
|
24
|
+
# the :metadata option is required.
|
25
|
+
return false unless respond_to? :metadata
|
26
|
+
|
21
27
|
metadata || false
|
22
28
|
end
|
23
29
|
end
|
@@ -26,6 +32,8 @@ module MadFlatter
|
|
26
32
|
end
|
27
33
|
|
28
34
|
def with_defaults(options, defaults: DEFAULT_OPTIONS)
|
35
|
+
validate_options_type!(options: options) unless options.respond_to? :to_h
|
36
|
+
|
29
37
|
new(**defaults.to_h.merge(options.to_h))
|
30
38
|
end
|
31
39
|
|
@@ -12,17 +12,17 @@ module MadFlatter
|
|
12
12
|
OPTIONS = [OPTION_METADATA, OPTION_NAMESPACE].freeze
|
13
13
|
|
14
14
|
def validate_options!(options:)
|
15
|
-
|
15
|
+
validate_options_type! options: options
|
16
16
|
|
17
|
-
|
17
|
+
return if options.blank?
|
18
18
|
|
19
19
|
validate_option_keys! options: options
|
20
20
|
validate_option_metadata! metadata: options[:metadata]
|
21
21
|
validate_option_namespace! namespace: options[:namespace]
|
22
22
|
end
|
23
23
|
|
24
|
-
def
|
25
|
-
raise ArgumentError,
|
24
|
+
def validate_options_type!(options:)
|
25
|
+
raise ArgumentError, "options (#{options.class}) is not a Hash" unless options.is_a? Hash
|
26
26
|
end
|
27
27
|
|
28
28
|
def validate_option_keys!(options:)
|
@@ -31,16 +31,16 @@ module MadFlatter
|
|
31
31
|
return if invalid_options.blank?
|
32
32
|
|
33
33
|
raise ArgumentError, 'One or more option keys were unrecognized. ' \
|
34
|
-
|
34
|
+
"#{OPTIONS} was expected but '#{invalid_options}' was received."
|
35
35
|
end
|
36
36
|
|
37
37
|
def validate_option_metadata!(metadata:)
|
38
38
|
return if [TrueClass, FalseClass].include? metadata.class
|
39
39
|
|
40
40
|
raise ArgumentError, "option :#{OPTION_METADATA} value is invalid. " \
|
41
|
-
|
42
|
-
|
43
|
-
|
41
|
+
'A TrueClass/FalseClass was expected ' \
|
42
|
+
"with the acceptable values #{OPTION_METADATA_VALUES} " \
|
43
|
+
"but '#{metadata}' (#{metadata.class}) was received."
|
44
44
|
end
|
45
45
|
|
46
46
|
def validate_option_namespace!(namespace:)
|
@@ -48,9 +48,8 @@ module MadFlatter
|
|
48
48
|
return if namespace.blank? || namespace.is_a?(Symbol)
|
49
49
|
|
50
50
|
raise ArgumentError, "option :#{OPTION_NAMESPACE} value is invalid. " \
|
51
|
-
|
52
|
-
|
53
|
-
"but '#{metadata}' (#{metadata.class}) was received."
|
51
|
+
'A Symbol was expected ' \
|
52
|
+
"but '#{namespace}' (#{namespace.class}) was received."
|
54
53
|
end
|
55
54
|
end
|
56
55
|
end
|
data/lib/mad_flatter/service.rb
CHANGED
@@ -12,6 +12,8 @@ module MadFlatter
|
|
12
12
|
include Optionable
|
13
13
|
|
14
14
|
def initialize(options: nil)
|
15
|
+
options ||= {}
|
16
|
+
|
15
17
|
# Accept whatever options are sent, but make sure
|
16
18
|
# we have defaults set up. #with_defaults
|
17
19
|
# will merge options into OptionsDefaultable::DEFAULT_OPTIONS
|
@@ -20,6 +22,8 @@ module MadFlatter
|
|
20
22
|
end
|
21
23
|
|
22
24
|
def execute(hash:, options: nil)
|
25
|
+
options ||= {}
|
26
|
+
|
23
27
|
# Merge options received into the default options passed through
|
24
28
|
# the constructor. Options received here, will override any options
|
25
29
|
# passed to the constructor, allowing us to retain defaut options
|
data/lib/mad_flatter/version.rb
CHANGED
data/lib/mad_flatter.rb
CHANGED
@@ -1,8 +1,13 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'active_support'
|
4
|
+
require_relative 'mad_flatter/hash_informable'
|
5
|
+
require_relative 'mad_flatter/hash_loadable'
|
6
|
+
require_relative 'mad_flatter/metadata_optionable'
|
7
|
+
require_relative 'mad_flatter/namespace_optionable'
|
8
|
+
require_relative 'mad_flatter/optionable'
|
9
|
+
require_relative 'mad_flatter/options_defaultable'
|
10
|
+
require_relative 'mad_flatter/options_validatable'
|
11
|
+
require_relative 'mad_flatter/options'
|
12
|
+
require_relative 'mad_flatter/service'
|
4
13
|
require_relative 'mad_flatter/version'
|
5
|
-
|
6
|
-
Dir[File.join('.', 'lib/mad_flatter/**/*.rb')].each do |f|
|
7
|
-
require f
|
8
|
-
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mad_flatter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- gangelo
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-09-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -183,7 +183,6 @@ files:
|
|
183
183
|
- lib/mad_flatter.rb
|
184
184
|
- lib/mad_flatter/hash_informable.rb
|
185
185
|
- lib/mad_flatter/hash_loadable.rb
|
186
|
-
- lib/mad_flatter/hash_retrievable.rb
|
187
186
|
- lib/mad_flatter/metadata_optionable.rb
|
188
187
|
- lib/mad_flatter/namespace_optionable.rb
|
189
188
|
- lib/mad_flatter/optionable.rb
|
@@ -211,11 +210,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
211
210
|
version: 2.3.1
|
212
211
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
213
212
|
requirements:
|
214
|
-
- - "
|
213
|
+
- - ">="
|
215
214
|
- !ruby/object:Gem::Version
|
216
|
-
version:
|
215
|
+
version: '0'
|
217
216
|
requirements: []
|
218
|
-
rubygems_version: 3.
|
217
|
+
rubygems_version: 3.3.22
|
219
218
|
signing_key:
|
220
219
|
specification_version: 4
|
221
220
|
summary: mad_flatter gem
|
@@ -1,13 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module MadFlatter
|
4
|
-
# Defines methods to retrieve model hash values dynamically.
|
5
|
-
module HashRetrievable
|
6
|
-
module_function
|
7
|
-
|
8
|
-
# Returns the value of the hash using fully quaified hash names.
|
9
|
-
def get_hash_value(hash:, hash_info:)
|
10
|
-
hash.dig(*[hash_info[:dig], hash_info[:field_name]].flatten.compact)
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|