dry_struct_generator 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +27 -0
- data/lib/dry_struct_generator/config/configuration.rb +3 -1
- data/lib/dry_struct_generator/config/generator_configuration.rb +4 -2
- data/lib/dry_struct_generator/struct_generator.rb +13 -10
- data/lib/dry_struct_generator/types.rb +3 -1
- data/lib/dry_struct_generator/version.rb +1 -1
- data/lib/dry_struct_generator.rb +5 -5
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 331956d915c216ff8914c45d61b4ee0928a84e509007c2aad38377748e336f32
|
4
|
+
data.tar.gz: 3a2d129137904e648e2e9a9cff814d8b3ad34bfae285fd3e0657d23d875cda4f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 972be3883f6fec30329e1cac25dfd545d217bf4a7c659246a32df8de856577bbcc755b3fdf420bca07f2d145637bd485e88705194e9fa75b9fbbc6f882b0719b
|
7
|
+
data.tar.gz: 3720ad2e90a59fc83d6e71a4c7f2a95dd8be5b09fc92d4aa01cc43165e9c84ba28629350be92dd6b97d776c4c5de875a826572b9c962ea8d2963d8d3b17d57b9
|
data/.rubocop.yml
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
AllCops:
|
2
2
|
TargetRubyVersion: 2.6
|
3
|
+
Exclude:
|
4
|
+
- 'spec/**/*.rb'
|
5
|
+
- 'vendor/bundle/**/*'
|
3
6
|
|
4
7
|
Style/StringLiterals:
|
5
8
|
Enabled: true
|
@@ -11,3 +14,27 @@ Style/StringLiteralsInInterpolation:
|
|
11
14
|
|
12
15
|
Layout/LineLength:
|
13
16
|
Max: 120
|
17
|
+
|
18
|
+
Metrics/MethodLength:
|
19
|
+
Max: 20
|
20
|
+
|
21
|
+
Documentation:
|
22
|
+
Enabled: false
|
23
|
+
|
24
|
+
Metrics/AbcSize:
|
25
|
+
Enabled: false
|
26
|
+
|
27
|
+
Metrics/BlockLength:
|
28
|
+
Max: 40
|
29
|
+
|
30
|
+
Metrics/ClassLength:
|
31
|
+
Max: 200
|
32
|
+
|
33
|
+
Metrics/PerceivedComplexity:
|
34
|
+
Max: 10
|
35
|
+
|
36
|
+
Metrics/CyclomaticComplexity:
|
37
|
+
Max: 10
|
38
|
+
|
39
|
+
Style/ClassVars:
|
40
|
+
Enabled: false
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module DryStructGenerator
|
2
4
|
class StructGenerator
|
3
5
|
@@definitions = {}
|
@@ -20,6 +22,7 @@ module DryStructGenerator
|
|
20
22
|
|
21
23
|
def call(validator, options = {})
|
22
24
|
return @@definitions[validator] if @@definitions[validator]
|
25
|
+
|
23
26
|
validator_definition = validation_schema_parser.new.call(validator).keys.merge(options)
|
24
27
|
result = generate(validator_definition)
|
25
28
|
|
@@ -30,27 +33,27 @@ module DryStructGenerator
|
|
30
33
|
|
31
34
|
def generate(validator_definition)
|
32
35
|
instance = self
|
33
|
-
Class.new(
|
36
|
+
Class.new(struct_class) do
|
34
37
|
validator_definition.each do |field_name, schema|
|
35
38
|
type = instance.get_field_type(schema)
|
36
|
-
schema
|
39
|
+
schema[:required] ? attribute(field_name.to_sym, type) : attribute?(field_name.to_sym, type)
|
37
40
|
end
|
38
41
|
end
|
39
42
|
end
|
40
43
|
|
41
44
|
def get_field_type(schema)
|
42
|
-
if schema
|
45
|
+
if schema[:array]
|
43
46
|
type = type_to_dry_type[:array]
|
44
|
-
schema
|
45
|
-
|
46
|
-
|
47
|
-
type = generate(schema.dig(:keys))
|
47
|
+
type = schema[:keys] ? type.of(generate(schema[:keys].to_sym)) : type.of(type_to_dry_type[schema[:type].to_sym])
|
48
|
+
elsif schema[:keys]
|
49
|
+
type = generate(schema[:keys])
|
48
50
|
else
|
49
|
-
type = type_to_dry_type[schema
|
50
|
-
type = type.optional if schema
|
51
|
+
type = type_to_dry_type[schema[:type].to_sym]
|
52
|
+
type = type.optional if schema[:nullable]
|
53
|
+
type = type.default(schema[:default]) if schema[:default]
|
51
54
|
end
|
52
55
|
|
53
56
|
type
|
54
57
|
end
|
55
58
|
end
|
56
|
-
end
|
59
|
+
end
|
data/lib/dry_struct_generator.rb
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
3
|
+
require "dry-types"
|
4
|
+
require "dry-struct"
|
5
|
+
require "dry_validation_parser"
|
6
6
|
require_relative "dry_struct_generator/version"
|
7
7
|
require_relative "dry_struct_generator/config/configuration"
|
8
8
|
require_relative "dry_struct_generator/config/generator_configuration"
|
9
|
-
require_relative
|
10
|
-
require_relative
|
9
|
+
require_relative "dry_struct_generator/types"
|
10
|
+
require_relative "dry_struct_generator/struct_generator"
|
11
11
|
|
12
12
|
module DryStructGenerator
|
13
13
|
class Error < StandardError; end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dry_struct_generator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jane-Terziev
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-01-
|
11
|
+
date: 2024-01-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dry-struct
|