Module: TypedOperation::Operations::Parameters

Included in:
Base, ImmutableBase
Defined in:
lib/typed_operation/operations/parameters.rb

Overview

Method to define parameters for your operation.

Instance Method Summary collapse

Instance Method Details

#named_param(name, signature = :any, **options, &converter) ⇒ Object

Parameter for a keyword or named argument. : (Symbol, ?Literal::Types::_Matchable, **untyped) ?{ (untyped) -> untyped } -> void



35
36
37
# File 'lib/typed_operation/operations/parameters.rb', line 35

def named_param(name, signature = :any, **options, &converter)
  param(name, signature, **options.merge(positional: false), &converter)
end

#optional(type_signature) ⇒ Object

Wrap a type signature in a NilableType meaning it is optional to TypedOperation. : (Literal::Types::_Matchable) -> Literal::Types::NilableType



41
42
43
# File 'lib/typed_operation/operations/parameters.rb', line 41

def optional(type_signature)
  Literal::Types::NilableType.new(type_signature)
end

#param(name, signature = :any, **options, &converter) ⇒ Object

Parameter for keyword argument, or a positional argument if you use positional: true. Required, but you can set a default or use optional: true if you want optional. : (Symbol, ?Literal::Types::_Matchable, **untyped) ?{ (untyped) -> untyped } -> void



21
22
23
# File 'lib/typed_operation/operations/parameters.rb', line 21

def param(name, signature = :any, **options, &converter)
  PropertyBuilder.new(self, name, signature, options).define(&converter)
end

#positional_param(name, signature = :any, **options, &converter) ⇒ Object

Parameter for positional argument. : (Symbol, ?Literal::Types::_Matchable, **untyped) ?{ (untyped) -> untyped } -> void



29
30
31
# File 'lib/typed_operation/operations/parameters.rb', line 29

def positional_param(name, signature = :any, **options, &converter)
  param(name, signature, **options.merge(positional: true), &converter)
end

#prop(name, type, kind = :keyword, reader: :public, writer: :public, default: nil) ⇒ Object

Override literal ‘prop` to prevent creating writers (Literal::Data does this by default) : (Symbol, Literal::Types::_Matchable, ?Symbol, ?reader: Symbol, ?writer: Symbol | bool, ?default: untyped) -> void



10
11
12
13
14
15
16
# File 'lib/typed_operation/operations/parameters.rb', line 10

def prop(name, type, kind = :keyword, reader: :public, writer: :public, default: nil)
  if self < ImmutableBase
    super(name, type, kind, reader:, default:)
  else
    super(name, type, kind, reader:, writer: false, default:)
  end
end