Class: TypedOperation::Base
- Inherits:
-
Object
- Object
- TypedOperation::Base
- Includes:
- Vident::Typed::Attributes
- Defined in:
- lib/typed_operation/base.rb
Class Method Summary collapse
- .call ⇒ Object
- .curry(**args) ⇒ Object (also: [], with)
- .operation_key ⇒ Object
-
.param(name, signature = :any, **options, &converter) ⇒ Object
property are required by default, you can fall back to attribute or set allow_nil: true if you want optional.
- .to_proc ⇒ Object
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(**attributes) ⇒ Base
constructor
A new instance of Base.
- #to_proc ⇒ Object
Constructor Details
#initialize(**attributes) ⇒ Base
Returns a new instance of Base.
35 36 37 38 39 40 41 42 |
# File 'lib/typed_operation/base.rb', line 35 def initialize(**attributes) begin prepare_attributes(attributes) rescue ::Dry::Struct::Error => e raise ParameterError, e. end prepare if respond_to?(:prepare) end |
Class Method Details
.call ⇒ Object
11 12 13 |
# File 'lib/typed_operation/base.rb', line 11 def call(...) new(...).call end |
.curry(**args) ⇒ Object Also known as: [], with
15 16 17 |
# File 'lib/typed_operation/base.rb', line 15 def curry(**args) PartiallyApplied.new(self, **args).curry end |
.operation_key ⇒ Object
25 26 27 |
# File 'lib/typed_operation/base.rb', line 25 def operation_key name.underscore.to_sym end |
.param(name, signature = :any, **options, &converter) ⇒ Object
property are required by default, you can fall back to attribute or set allow_nil: true if you want optional
30 31 32 |
# File 'lib/typed_operation/base.rb', line 30 def param(name, signature = :any, **, &converter) attribute(name, signature, **{allow_nil: false}.merge(), &converter) end |
.to_proc ⇒ Object
21 22 23 |
# File 'lib/typed_operation/base.rb', line 21 def to_proc method(:call).to_proc end |
Instance Method Details
#call ⇒ Object
44 45 46 |
# File 'lib/typed_operation/base.rb', line 44 def call raise InvalidOperationError, "You must implement #call" end |
#to_proc ⇒ Object
48 49 50 |
# File 'lib/typed_operation/base.rb', line 48 def to_proc method(:call).to_proc end |