Class: Farce::Internal::DryTypes::CollectionType
- Inherits:
-
Object
- Object
- Farce::Internal::DryTypes::CollectionType
- Includes:
- Dry::Types::Builder, Dry::Types::Type
- Defined in:
- lib/farce/integrations/dry_types.rb
Overview
A regular dry type that constructs a Farce value.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#source ⇒ Dry::Types::Type
readonly
The dry type evaluated before Farce construction.
Instance Method Summary collapse
-
#call(input = ::Dry::Types::Undefined) {|partial| ... } ⇒ Object?
(also: #[])
Apply validation, coercion, and Farce construction to input.
-
#constrained? ⇒ Boolean
Report whether this type contains constraints.
-
#default? ⇒ Boolean
Report whether this is a default type.
-
#inspect ⇒ String
Return the wrapped dry type representation.
-
#meta(data = ::Dry::Types::Undefined) ⇒ BasicObject
Read or extend this type's metadata.
-
#name ⇒ String
Return the output type name.
-
#optional? ⇒ Boolean
Report whether this type accepts nil.
-
#primitive?(input) ⇒ Boolean
Test whether a value is accepted by the output type.
-
#pristine ⇒ CollectionType
Return a new type without source metadata.
-
#to_ast(meta: true) ⇒ Array
Return the dry-types abstract syntax tree.
-
#to_proc ⇒ Proc
Convert this type to a callable object.
-
#try(input) {|failure| ... } ⇒ Dry::Types::Result, Object
Try to construct a Farce value and return a dry-types result.
-
#valid?(input = ::Dry::Types::Undefined) ⇒ Boolean
(also: #===)
Test whether input can produce a valid Farce value.
-
#with(mode: UNDEFINED, scope: UNDEFINED, **source_options) ⇒ CollectionType
Return a new Farce type with different output or source options.
Instance Attribute Details
#source ⇒ Dry::Types::Type (readonly)
The dry type evaluated before Farce construction.
147 148 149 |
# File 'lib/farce/integrations/dry_types.rb', line 147 def source @source end |
Instance Method Details
#call(input = ::Dry::Types::Undefined) {|partial| ... } ⇒ Object? Also known as: []
Apply validation, coercion, and Farce construction to input.
179 |
# File 'lib/farce/integrations/dry_types.rb', line 179 def call(input = ::Dry::Types::Undefined, &) = @type.call(input, &) |
#constrained? ⇒ Boolean
Report whether this type contains constraints.
236 |
# File 'lib/farce/integrations/dry_types.rb', line 236 def constrained? = @type.constrained? |
#default? ⇒ Boolean
Report whether this is a default type.
232 |
# File 'lib/farce/integrations/dry_types.rb', line 232 def default? = @type.default? |
#inspect ⇒ String
Return the wrapped dry type representation.
266 |
# File 'lib/farce/integrations/dry_types.rb', line 266 def inspect = @type.inspect |
#meta ⇒ Hash #meta(data) ⇒ CollectionType
Read or extend this type's metadata.
279 280 281 282 283 |
# File 'lib/farce/integrations/dry_types.rb', line 279 def (data = ::Dry::Types::Undefined) return @type. if ::Dry::Types::Undefined.equal?(data) self.class.new(source.(data), kind:, configuration:) end |
#name ⇒ String
Return the output type name.
228 |
# File 'lib/farce/integrations/dry_types.rb', line 228 def name = @type.name |
#optional? ⇒ Boolean
Report whether this type accepts nil.
240 |
# File 'lib/farce/integrations/dry_types.rb', line 240 def optional? = @type.optional? |
#primitive?(input) ⇒ Boolean
Test whether a value is accepted by the output type.
219 |
# File 'lib/farce/integrations/dry_types.rb', line 219 def primitive?(input) = @type.primitive?(input) |
#pristine ⇒ CollectionType
Return a new type without source metadata.
287 |
# File 'lib/farce/integrations/dry_types.rb', line 287 def pristine = self.class.new(source.pristine, kind:, configuration:) |
#to_ast(meta: true) ⇒ Array
Return the dry-types abstract syntax tree.
258 |
# File 'lib/farce/integrations/dry_types.rb', line 258 def to_ast(meta: true) = @type.to_ast(meta:) |
#to_proc ⇒ Proc
Convert this type to a callable object.
262 |
# File 'lib/farce/integrations/dry_types.rb', line 262 def to_proc = proc { call(it) } |
#try(input) {|failure| ... } ⇒ Dry::Types::Result, Object
Try to construct a Farce value and return a dry-types result.
203 |
# File 'lib/farce/integrations/dry_types.rb', line 203 def try(input, &) = @type.try(input, &) |
#valid?(input = ::Dry::Types::Undefined) ⇒ Boolean Also known as: ===
Test whether input can produce a valid Farce value.
208 |
# File 'lib/farce/integrations/dry_types.rb', line 208 def valid?(input = ::Dry::Types::Undefined) = @type.valid?(input) |
#with(mode: UNDEFINED, scope: UNDEFINED, **source_options) ⇒ CollectionType
Return a new Farce type with different output or source options.
295 296 297 298 299 |
# File 'lib/farce/integrations/dry_types.rb', line 295 def with(mode: UNDEFINED, scope: UNDEFINED, **) configured = configuration.with(kind:, mode:, scope:) next_source = .empty? ? source : source.with(**) self.class.new(next_source, kind:, configuration: configured) end |