expectant 0.3.1 → 0.3.2

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: 06e38c364b8d2d666a81174ddafa2b426153ce1627c155bd996c8b1a912c6212
4
- data.tar.gz: 7d5d662b9971375813d280f5c129aeb0ec80d960b5520368063714c7057ce794
3
+ metadata.gz: 61a972417f48272cce39684ca13d5ada787226afede1c929330e54f810a73611
4
+ data.tar.gz: 99e5d0f2289f2b7a0793bc0b0ad5ed8857b53e61a8c07cd21f21ca9f246f0df7
5
5
  SHA512:
6
- metadata.gz: 04545df86e467ffcb8bd6c48f8cb702f90527ef5f9c5bf745d265bcc95ab80f84a606dafec9b57a345058d148ad61f7e7702476cbcc749d5471ed9ca7b5e2d7f
7
- data.tar.gz: 7c427ebfc893ee72957783526adba4189f23e032f08c574ae9785932f01ac783cc7d0a4ae25a64743b5529d8c324ae966e1330ff79be3f869383c6ef796d5680
6
+ metadata.gz: 0b693ecdc765275f20849772663a00badf73587c73e48616fdb451c48c8eabc1753bdd4448f4fe47fca7915f2377995670e02071d5e34907f1c25c1753906aa8
7
+ data.tar.gz: 3a2b7792f3014d1663d9e25cb718df703ccea3fc26c82f473e72feb8728b69b22cc2375feae2ad29cc2aa8b17082a71d4196368524cfd4595d2da57d2dfd73ad
data/.editorconfig ADDED
@@ -0,0 +1,28 @@
1
+ root = true
2
+
3
+ [*]
4
+ end_of_line = lf
5
+ charset = utf-8
6
+ trim_trailing_whitespace = true
7
+ insert_final_newline = true
8
+ indent_style = space
9
+ indent_size = 2
10
+
11
+ [*.js]
12
+ indent_style = space
13
+ indent_size = 2
14
+
15
+ [*.rb]
16
+ indent_style = space
17
+ indent_size = 2
18
+
19
+ [*.css]
20
+ indent_style = space
21
+ indent_size = 2
22
+
23
+ [*.html]
24
+ indent_style = space
25
+ indent_size = 2
26
+
27
+ [*.{diff,md}]
28
+ trim_trailing_whitespace = false
data/lib/expectant/dsl.rb CHANGED
@@ -33,7 +33,8 @@ module Expectant
33
33
  # Options:
34
34
  # collision: :error|:force -> method name collision policy for dynamic definitions
35
35
  # singular: string|symbol -> control singular name for the schema
36
- def expects(schema_name, collision: :error, singular: nil)
36
+ # validation: :permissive|:strict -> unknown key handling
37
+ def expects(schema_name, collision: :error, singular: nil, validation: :permissive)
37
38
  field_method_name = Utils.singularize(schema_name.to_sym)
38
39
  if !singular.nil?
39
40
  if singular.is_a?(String) || singular.is_a?(Symbol)
@@ -42,12 +43,23 @@ module Expectant
42
43
  raise ConfigurationError, "Invalid singular option: #{singular.inspect}"
43
44
  end
44
45
  end
46
+
47
+ validation = validation.to_sym
48
+ if ![:permissive, :strict].include?(validation)
49
+ raise ConfigurationError, "Invalid validation option: #{validation.inspect}"
50
+ end
51
+
45
52
  schema = schema_name.to_sym
46
53
 
47
54
  if @_expectant_schemas.key?(schema)
48
55
  raise SchemaError, "Schema :#{schema} already defined"
49
56
  else
50
- create_schema(schema, collision: collision, field_method_name: field_method_name)
57
+ create_schema(
58
+ schema,
59
+ collision: collision,
60
+ field_method_name: field_method_name,
61
+ validation: validation
62
+ )
51
63
  end
52
64
 
53
65
  self
@@ -59,8 +71,8 @@ module Expectant
59
71
 
60
72
  private
61
73
 
62
- def create_schema(schema_name, collision: :error, field_method_name: nil)
63
- @_expectant_schemas[schema_name] = Schema.new(schema_name)
74
+ def create_schema(schema_name, collision: :error, field_method_name: nil, validation: :permissive)
75
+ @_expectant_schemas[schema_name] = Schema.new(schema_name, validation: validation)
64
76
 
65
77
  # Dynamically define the field definition method
66
78
  # (e.g. input for :inputs, datum for :data)
@@ -4,13 +4,14 @@ require "dry/validation"
4
4
 
5
5
  module Expectant
6
6
  class Schema
7
- attr_reader :name, :fields, :validators
7
+ attr_reader :name, :fields, :validators, :validation
8
8
 
9
- def initialize(name)
9
+ def initialize(name, validation: :permissive)
10
10
  @name = name
11
11
  @fields = []
12
12
  @validators = []
13
13
  @contract_class = nil
14
+ @validation = validation
14
15
  end
15
16
 
16
17
  def keys
@@ -22,7 +23,7 @@ module Expectant
22
23
  end
23
24
 
24
25
  def duplicate
25
- dup = self.class.new(@name)
26
+ dup = self.class.new(@name, validation: @validation)
26
27
  dup.instance_variable_set(:@fields, @fields.dup)
27
28
  dup.instance_variable_set(:@validators, @validators.dup)
28
29
  dup
@@ -55,6 +56,7 @@ module Expectant
55
56
  def build_contract
56
57
  fields = @fields
57
58
  validators = @validators
59
+ validation_mode = @validation
58
60
 
59
61
  Class.new(Dry::Validation::Contract) do
60
62
  # Enable option passing (allows context and instance to be passed at validation time)
@@ -63,6 +65,8 @@ module Expectant
63
65
 
64
66
  # Define schema based on fields using dry-types
65
67
  params do
68
+ config.validate_keys = true if validation_mode == :strict
69
+
66
70
  fields.each do |field|
67
71
  dry_type = field.dry_type
68
72
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Expectant
4
- VERSION = "0.3.1"
4
+ VERSION = "0.3.2"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: expectant
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hector Medina Fetterman
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2026-03-15 00:00:00.000000000 Z
11
+ date: 2026-03-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dry-validation
@@ -62,6 +62,7 @@ executables: []
62
62
  extensions: []
63
63
  extra_rdoc_files: []
64
64
  files:
65
+ - ".editorconfig"
65
66
  - ".rspec"
66
67
  - ".standard.yml"
67
68
  - CHANGELOG.md