Class: Farce::Internal::DryTypes::MapType
- Inherits:
-
CollectionType
- Object
- CollectionType
- Farce::Internal::DryTypes::MapType
- Defined in:
- lib/farce/integrations/dry_types.rb
Overview
A Map type that supports dry-types homogeneous maps and schemas.
Instance Attribute Summary
Attributes inherited from CollectionType
Instance Method Summary collapse
-
#map(key_type, value_type) ⇒ MapType
Apply dry types to every key and value before Farce construction.
-
#schema ⇒ BasicObject
Define or extend fixed keys and their dry types before Farce construction.
-
#strict(strict = true) ⇒ MapType
Return a schema that rejects unknown keys.
-
#with_key_transform(transform = nil) {|key| ... } ⇒ MapType
Transform input keys before schema lookup.
-
#with_type_transform(transform = nil) {|type| ... } ⇒ MapType
Transform schema key types when defining a schema.
Methods inherited from CollectionType
#call, #constrained?, #default?, #inspect, #meta, #name, #optional?, #primitive?, #pristine, #to_ast, #to_proc, #try, #valid?, #with
Instance Method Details
#map(key_type, value_type) ⇒ MapType
Apply dry types to every key and value before Farce construction.
343 344 345 346 347 |
# File 'lib/farce/integrations/dry_types.rb', line 343 def map(key_type, value_type) typed = DryTypes.collection_source(source).map(key_type, value_type) typed = DryTypes.restore_optional_source(source, typed) self.class.new(typed, kind:, configuration:) end |
#schema(keys_or_map, meta = {}) ⇒ MapType #schema(keys_or_map) ⇒ MapType
Define or extend fixed keys and their dry types before Farce construction.
359 360 361 362 363 |
# File 'lib/farce/integrations/dry_types.rb', line 359 def schema(...) typed = DryTypes.collection_source(source).schema(...) typed = DryTypes.restore_optional_source(source, typed) self.class.new(typed, kind:, configuration:) end |
#strict(strict = true) ⇒ MapType
Return a schema that rejects unknown keys.
368 |
# File 'lib/farce/integrations/dry_types.rb', line 368 def strict(strict = true) = rebuild_map_source(:strict, strict) # rubocop:disable Style/OptionalBooleanParameter |
#with_key_transform(transform = nil) {|key| ... } ⇒ MapType
Transform input keys before schema lookup.
376 |
# File 'lib/farce/integrations/dry_types.rb', line 376 def with_key_transform(transform = nil, &) = rebuild_map_source(:with_key_transform, transform, &) |
#with_type_transform(transform = nil) {|type| ... } ⇒ MapType
Transform schema key types when defining a schema.
384 |
# File 'lib/farce/integrations/dry_types.rb', line 384 def with_type_transform(transform = nil, &) = rebuild_map_source(:with_type_transform, transform, &) |