camel_snake_struct 0.2.0 → 0.3.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: 987bc380d252b4990ae2007fcf0d5d75dcb1eb56a9f680eb043a3b6e7e65fa0c
4
- data.tar.gz: 1ac44036b2c851c8f98c3bef57c20ab3cf1e6d557b675c2a48465a6b8e3be5ee
3
+ metadata.gz: 19cacf8a8dd3f5e1758672ed4ba28f90784c0017cf65bd39947293eab12d86a6
4
+ data.tar.gz: b4282acdaad784ebc5f7cf4aea44af63cccf5ef23e1c86cc8b6b876b9afcf8d1
5
5
  SHA512:
6
- metadata.gz: c64e7b0995a1098f8a932fa80f6c488ab1c75ce6dbcbaeaa181981442fb147c599b49e9a4b156fcb9930ca044d34fa92b795499594f99c1cc678259185fbe103
7
- data.tar.gz: e8f184b499b1fbff46d2d22ff86459cc7c46b8f38369d7e28fc7af4cf5b3d07caef7115bacc3daa375fa452e503cb91bb2701ec1041515eb6242a463cc50c81e
6
+ metadata.gz: 200e79a30d0e957e8833d757a6ea342bd79778459a7cfad2ac20c6e07859cf556c00092c8f0050325535e8982a6a7ae15f174e9a413bb1182bd0ca206684bad2
7
+ data.tar.gz: d5229f7d105c08f93b869acd0d33875026788a09133a227a82ba006f2b99ddc782b4d856fbd49fbf2d5069b4a3ef933d352e3111f6a45b5ce7656e60a1a791ac
data/.gitignore CHANGED
@@ -10,4 +10,6 @@
10
10
  # rspec failure tracking
11
11
  .rspec_status
12
12
  vendor/bundle
13
- gems.locked
13
+ gems.locked
14
+ Gemfile.lock
15
+ .ruby-version
data/.rubocop.yml CHANGED
@@ -4,7 +4,7 @@ require:
4
4
 
5
5
  AllCops:
6
6
  NewCops: enable
7
- TargetRubyVersion: 2.4
7
+ TargetRubyVersion: 2.5
8
8
  Exclude:
9
9
  - 'vendor/**/*'
10
10
 
@@ -19,3 +19,15 @@ Metrics/MethodLength:
19
19
 
20
20
  Metrics/ClassLength:
21
21
  Max: 200
22
+
23
+ Metrics/CyclomaticComplexity:
24
+ Max: 9
25
+
26
+ Metrics/PerceivedComplexity:
27
+ Max: 9
28
+
29
+ Gemspec/RequiredRubyVersion:
30
+ Enabled: false
31
+
32
+ Bundler/GemFilename:
33
+ Enabled: false
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ # 0.3.0
2
+ * Learning Structs store meta data about the shape of the hash from the examples provided. This can be used with tapioca custom DSL compilers to generate sorbet types
3
+
4
+ # 0.2.1
5
+ * activesupport < 8.0
6
+
1
7
  # 0.2.0
2
8
  * Add support to check if key is set
3
9
 
data/README.md CHANGED
@@ -67,6 +67,18 @@ puts result3.date.timezone # nil
67
67
  puts result3.date.unix_time # nil
68
68
  ```
69
69
 
70
+ Learning Structs store meta data about the shape of the hash from the examples provided.
71
+ This can be used with tapioca custom DSL compilers to generate sorbet types
72
+
73
+ ```ruby
74
+ MyLoadedStruct = Class.new(CamelSnakeStruct)
75
+ MyLoadedStruct.example('data' => [{ 'name' => 'Jeff' }], 'errors' => [], 'date' => { 'timezone' => 'UTC', 'unixTime' => 0})
76
+
77
+ puts MyLoadedStruct.types_meta_data
78
+ # {"data"=>#<struct CamelSnakeStruct::Type__Meta__Data class_types=#<Set: {MyLoadedStruct::Datum}>, array=true>, "errors"=>#<struct CamelSnakeStruct::Type__Meta__Data class_types=#<Set: {}>, array=true>, "date"=>#<struct CamelSnakeStruct::Type__Meta__Data class_types=#<Set: {MyLoadedStruct::Date}>, array=false>}
79
+ ```
80
+
81
+
70
82
  ### Limitations
71
83
 
72
84
  * Expects to receive a hash
data/bin/rake CHANGED
@@ -9,8 +9,8 @@
9
9
  #
10
10
 
11
11
  require "pathname"
12
- ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../gems.rb",
13
- Pathname.new(__FILE__).realpath)
12
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13
+ Pathname.new(__FILE__).realpath)
14
14
 
15
15
  bundle_binstub = File.expand_path("../bundle", __FILE__)
16
16
 
data/bin/rspec CHANGED
@@ -9,7 +9,7 @@
9
9
  #
10
10
 
11
11
  require "pathname"
12
- ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../gems.rb",
12
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13
13
  Pathname.new(__FILE__).realpath)
14
14
 
15
15
  bundle_binstub = File.expand_path("../bundle", __FILE__)
data/bin/rubocop CHANGED
@@ -9,7 +9,7 @@
9
9
  #
10
10
 
11
11
  require "pathname"
12
- ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../gems.rb",
12
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13
13
  Pathname.new(__FILE__).realpath)
14
14
 
15
15
  bundle_binstub = File.expand_path("../bundle", __FILE__)
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = "camel_snake_struct"
3
- spec.version = "0.2.0"
3
+ spec.version = "0.3.0"
4
4
  spec.authors = ["Grant Petersen-Speelman"]
5
5
  spec.email = ["grant@nexl.io"]
6
6
 
@@ -21,5 +21,6 @@ Gem::Specification.new do |spec|
21
21
  spec.bindir = "exe"
22
22
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
23
  spec.require_paths = ["lib"]
24
- spec.add_dependency 'activesupport', '>= 3.2', '< 7.0'
24
+ spec.add_dependency 'activesupport', '>= 3.2', '< 8.0'
25
+ spec.metadata['rubygems_mfa_required'] = 'true'
25
26
  end
@@ -1,11 +1,20 @@
1
+ require "active_support"
1
2
  require 'active_support/core_ext/string'
2
3
 
3
4
  class CamelSnakeStruct
4
5
  def self.example(data)
6
+ raise ArgumentError, "Examples are for Learning Structs" if self == CamelSnakeStruct
7
+
5
8
  new_example = new(data)
6
9
  walk_example(new_example)
7
10
  end
8
11
 
12
+ Type__Meta__Data = Struct.new(:class_types, :array) do
13
+ def classes
14
+ class_types.to_a
15
+ end
16
+ end
17
+
9
18
  def self.walk_example(new_example)
10
19
  new_example.send(:_method_to_key).keys.each do |m_name|
11
20
  result = new_example.public_send(m_name)
@@ -14,9 +23,25 @@ class CamelSnakeStruct
14
23
  elsif result.is_a?(Array) && result.first.is_a?(CamelSnakeStruct)
15
24
  walk_example(result.first)
16
25
  end
26
+
27
+ store_meta_data(new_example.class, m_name, result)
17
28
  end
18
29
  end
19
30
 
31
+ def self.store_meta_data(example_class, m_name, result)
32
+ types_meta_data = (example_class.types_meta_data[m_name] ||= Type__Meta__Data.new(Set.new, false))
33
+ if result.is_a?(Array)
34
+ types_meta_data.array = true
35
+ result.map(&:class).each { |c| types_meta_data.class_types << c }
36
+ else
37
+ types_meta_data.class_types << result.class
38
+ end
39
+ end
40
+
41
+ def self.types_meta_data
42
+ @types_meta_data ||= {}
43
+ end
44
+
20
45
  def initialize(hash)
21
46
  @_raw_hash = hash&.to_h || {}
22
47
  @_method_to_key = @_raw_hash.keys.each_with_object({}) do |key, mapping|
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: camel_snake_struct
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Grant Petersen-Speelman
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-11-06 00:00:00.000000000 Z
11
+ date: 2023-04-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -19,7 +19,7 @@ dependencies:
19
19
  version: '3.2'
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
- version: '7.0'
22
+ version: '8.0'
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
@@ -29,7 +29,7 @@ dependencies:
29
29
  version: '3.2'
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
- version: '7.0'
32
+ version: '8.0'
33
33
  description: Easily access camelCased hashes in a ruby friendly way
34
34
  email:
35
35
  - grant@nexl.io
@@ -41,6 +41,7 @@ files:
41
41
  - ".rspec"
42
42
  - ".rubocop.yml"
43
43
  - CHANGELOG.md
44
+ - Gemfile
44
45
  - README.md
45
46
  - Rakefile
46
47
  - bin/console
@@ -49,7 +50,6 @@ files:
49
50
  - bin/rubocop
50
51
  - bin/setup
51
52
  - camel_snake_struct.gemspec
52
- - gems.rb
53
53
  - lib/camel_snake_struct.rb
54
54
  homepage: https://github.com/NEXL-LTS/camel_snake_struct-ruby
55
55
  licenses: []
@@ -57,7 +57,8 @@ metadata:
57
57
  homepage_uri: https://github.com/NEXL-LTS/camel_snake_struct-ruby
58
58
  source_code_uri: https://github.com/NEXL-LTS/camel_snake_struct-ruby
59
59
  changelog_uri: https://github.com/NEXL-LTS/camel_snake_struct/CHANGELOG.md
60
- post_install_message:
60
+ rubygems_mfa_required: 'true'
61
+ post_install_message:
61
62
  rdoc_options: []
62
63
  require_paths:
63
64
  - lib
@@ -72,8 +73,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
72
73
  - !ruby/object:Gem::Version
73
74
  version: '0'
74
75
  requirements: []
75
- rubygems_version: 3.2.22
76
- signing_key:
76
+ rubygems_version: 3.1.6
77
+ signing_key:
77
78
  specification_version: 4
78
79
  summary: Easily access camelCased hashes in a ruby friendly way
79
80
  test_files: []
File without changes