Sha256: ae900f06a8cadd38af4ed0799164407f8783a4c7aed74ad6cfd6f59cebad11da

Contents?: true

Size: 739 Bytes

Versions: 19

Compression:

Stored size: 739 Bytes

Contents

require 'dry-struct'

module Dry
  module Validation
    class Schema
      module StructClassBuilder
        def create_class(target, other = nil)
          if other.is_a?(Class) && other < Dry::Struct
            super do
              other.schema.each { |attr, type| required(attr).filled(type) }
            end
          else
            super
          end
        end
      end

      module StructNode
        def node(input, *)
          if input.is_a?(::Class) && input < ::Dry::Struct
            [type, [name, [:schema, Schema.create_class(self, input)]]]
          else
            super
          end
        end
      end

      singleton_class.prepend(StructClassBuilder)
      Value.prepend(StructNode)
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
dry-validation-0.13.3 lib/dry/validation/extensions/struct.rb
dry-validation-0.13.2 lib/dry/validation/extensions/struct.rb
dry-validation-0.13.1 lib/dry/validation/extensions/struct.rb
dry-validation-0.11.2 lib/dry/validation/extensions/struct.rb
dry-validation-0.12.3 lib/dry/validation/extensions/struct.rb
dry-validation-0.13.0 lib/dry/validation/extensions/struct.rb
dry-validation-0.12.2 lib/dry/validation/extensions/struct.rb
dry-validation-0.12.1 lib/dry/validation/extensions/struct.rb
dry-validation-0.12.0 lib/dry/validation/extensions/struct.rb
dry-validation-0.11.1 lib/dry/validation/extensions/struct.rb
dry-validation-0.11.0 lib/dry/validation/extensions/struct.rb
dry-validation-0.10.7 lib/dry/validation/extensions/struct.rb
dry-validation-0.10.6 lib/dry/validation/extensions/struct.rb
dry-validation-0.10.5 lib/dry/validation/extensions/struct.rb
dry-validation-0.10.4 lib/dry/validation/extensions/struct.rb
dry-validation-0.10.3 lib/dry/validation/extensions/struct.rb
dry-validation-0.10.2 lib/dry/validation/extensions/struct.rb
dry-validation-0.10.1 lib/dry/validation/extensions/struct.rb
dry-validation-0.10.0 lib/dry/validation/extensions/struct.rb