mad_flatter 1.0.1.pre.beta → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b4db6317b089b862c79b036172276e5a283b44536bf5f070a67f5cbb2bdfe9ff
4
- data.tar.gz: d747bee64c0b480fd24e604abb26939981cb15b6821b75338884e71acfcbae1b
3
+ metadata.gz: 56a07650700f70bee720b0c0a4451f69c08d27336012a758159e4bba7200c6a1
4
+ data.tar.gz: 42343fcdd1fc68d209d0ecde0575cf507091253bf2484659efac7f52b33e3267
5
5
  SHA512:
6
- metadata.gz: 5795b276b36c15cf55ea10599248ae6c3b00bfb88891b33d0f8c64ea3115d663d04ffb3dd5b8d806c0c2acc6376e5c4406af08b37ac465c878814d1a9d906e9b
7
- data.tar.gz: 1f0b0839632b6b1582417a4d1cb22df0ce9570286b998ad60c831381db72be4c241b19be0c10344fe4c04e133c3b5399f724f28847aa23a6866a6305968b0992
6
+ metadata.gz: 0db85bf75589abb932423b31bff64061adb8302bd619cc397cd1308d2173581edfe06d21edeb6e3b73fe4233135100c6bba67afa55021765398fb86768278b06
7
+ data.tar.gz: a9c7023fe7538b4046c4667844b1cdad88b6a51aee073d675178faf490a8358c220a64a64b4e647d7e0536ee8bfb227899499cc37d75fc549a7b973bec01d25c
data/CHANGELOG.md CHANGED
@@ -1,6 +1,21 @@
1
+ ### 2.1.0
2
+ * Changes
3
+ * Limit ruby version to Gem::Requirement.new(">= 2.3.1", "< 4.0").
4
+ * Update ruby gems.
5
+
6
+ ### 2.0.0
7
+ * Changes
8
+ * Add spec coverage.
9
+ * Update README.md.
10
+ * Breaking change
11
+ * Remove unused Module HashRetrievable.
12
+ * Bug Fixes
13
+ * 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.
14
+ * 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.
15
+
1
16
  ### 1.0.1-beta
2
- * changes
3
- * Fix bug requiring support codez in lib/mad_flatter.rb
17
+ * Bug Fixes
18
+ * Fix bug requiring support codez in lib/mad_flatter.rb.
4
19
 
5
20
  ### 1.0.0-alpha
6
- * Initial release
21
+ * Initial release.
data/Gemfile.lock CHANGED
@@ -1,14 +1,14 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- mad_flatter (1.0.1.pre.beta)
4
+ mad_flatter (2.1.0)
5
5
  activesupport (~> 7.0, >= 7.0.3.1)
6
- immutable_struct_ex (~> 0.2.0)
6
+ immutable_struct_ex (~> 1.0)
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
- activesupport (7.0.3.1)
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.2)
24
+ immutable_struct_ex (1.0.0)
25
25
  json (2.6.2)
26
26
  kwalify (0.7.2)
27
27
  method_source (1.0.0)
28
- minitest (5.16.2)
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,38 +40,38 @@ GEM
40
40
  kwalify (~> 0.7.0)
41
41
  parser (~> 3.1.0)
42
42
  rainbow (>= 2.0, < 4.0)
43
- regexp_parser (2.5.0)
43
+ regexp_parser (2.6.0)
44
44
  rexml (3.2.5)
45
- rspec (3.11.0)
46
- rspec-core (~> 3.11.0)
47
- rspec-expectations (~> 3.11.0)
48
- rspec-mocks (~> 3.11.0)
49
- rspec-core (3.11.0)
50
- rspec-support (~> 3.11.0)
51
- rspec-expectations (3.11.0)
45
+ rspec (3.12.0)
46
+ rspec-core (~> 3.12.0)
47
+ rspec-expectations (~> 3.12.0)
48
+ rspec-mocks (~> 3.12.0)
49
+ rspec-core (3.12.0)
50
+ rspec-support (~> 3.12.0)
51
+ rspec-expectations (3.12.0)
52
52
  diff-lcs (>= 1.2.0, < 2.0)
53
- rspec-support (~> 3.11.0)
54
- rspec-mocks (3.11.1)
53
+ rspec-support (~> 3.12.0)
54
+ rspec-mocks (3.12.0)
55
55
  diff-lcs (>= 1.2.0, < 2.0)
56
- rspec-support (~> 3.11.0)
57
- rspec-support (3.11.0)
58
- rubocop (1.35.0)
56
+ rspec-support (~> 3.12.0)
57
+ rspec-support (3.12.0)
58
+ rubocop (1.38.0)
59
59
  json (~> 2.3)
60
60
  parallel (~> 1.10)
61
61
  parser (>= 3.1.2.1)
62
62
  rainbow (>= 2.2.2, < 4.0)
63
63
  regexp_parser (>= 1.8, < 3.0)
64
64
  rexml (>= 3.2.5, < 4.0)
65
- rubocop-ast (>= 1.20.1, < 2.0)
65
+ rubocop-ast (>= 1.23.0, < 2.0)
66
66
  ruby-progressbar (~> 1.7)
67
67
  unicode-display_width (>= 1.4.0, < 3.0)
68
- rubocop-ast (1.21.0)
68
+ rubocop-ast (1.23.0)
69
69
  parser (>= 3.1.1.0)
70
- rubocop-performance (1.14.3)
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.12.1)
74
- rubocop (~> 1.31)
73
+ rubocop-rspec (2.15.0)
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.2.0)
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](http://img.shields.io/badge/license-MIT-yellowgreen.svg)](#license)
13
13
 
14
- This is a work in process. No breaking changes are expected before v1.0.0.
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
- namespace: namespace,
13
- dig: dig << key,
14
- hash_info: hash_info)
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
- key: key,
19
- value: value,
20
- namespace: namespace,
21
- dig: dig)
18
+ key: key,
19
+ value: value,
20
+ namespace: namespace,
21
+ dig: dig)
22
22
  end
23
23
 
24
24
  next
@@ -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
- raise ArgumentError, 'options is not a Hash' unless options.is_a? Hash
15
+ validate_options_type! options: options
16
16
 
17
- validate_options_present! options: options
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 validate_options_present!(options:)
25
- raise ArgumentError, 'options is blank?' if options.blank?
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
- "#{OPTIONS} was expected but '#{invalid_options} was received."
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
- 'A TrueClass/FalseClass was expected ' \
42
- "with the acceptable values #{OPTION_METADATA_VALUES} " \
43
- "but '#{metadata}' (#{metadata.class}) was received."
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
- 'A Symbol was expected ' \
52
- "with the acceptable values #{OPTION_METADATA_VALUES} " \
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
@@ -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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MadFlatter
4
- VERSION = '1.0.1-beta'
4
+ VERSION = '2.1.0'
5
5
  end
data/lib/mad_flatter.rb CHANGED
@@ -3,7 +3,6 @@
3
3
  require 'active_support'
4
4
  require_relative 'mad_flatter/hash_informable'
5
5
  require_relative 'mad_flatter/hash_loadable'
6
- require_relative 'mad_flatter/hash_retrievable'
7
6
  require_relative 'mad_flatter/metadata_optionable'
8
7
  require_relative 'mad_flatter/namespace_optionable'
9
8
  require_relative 'mad_flatter/optionable'
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: 1.0.1.pre.beta
4
+ version: 2.1.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-08-17 00:00:00.000000000 Z
11
+ date: 2022-11-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -36,14 +36,14 @@ dependencies:
36
36
  requirements:
37
37
  - - "~>"
38
38
  - !ruby/object:Gem::Version
39
- version: 0.2.0
39
+ version: '1.0'
40
40
  type: :runtime
41
41
  prerelease: false
42
42
  version_requirements: !ruby/object:Gem::Requirement
43
43
  requirements:
44
44
  - - "~>"
45
45
  - !ruby/object:Gem::Version
46
- version: 0.2.0
46
+ version: '1.0'
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: pry-byebug
49
49
  requirement: !ruby/object:Gem::Requirement
@@ -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
@@ -209,13 +208,16 @@ required_ruby_version: !ruby/object:Gem::Requirement
209
208
  - - ">="
210
209
  - !ruby/object:Gem::Version
211
210
  version: 2.3.1
211
+ - - "<"
212
+ - !ruby/object:Gem::Version
213
+ version: '4.0'
212
214
  required_rubygems_version: !ruby/object:Gem::Requirement
213
215
  requirements:
214
- - - ">"
216
+ - - ">="
215
217
  - !ruby/object:Gem::Version
216
- version: 1.3.1
218
+ version: '0'
217
219
  requirements: []
218
- rubygems_version: 3.2.15
220
+ rubygems_version: 3.3.22
219
221
  signing_key:
220
222
  specification_version: 4
221
223
  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