Class: TypedOperation::Base

Inherits:
Object
  • Object
show all
Includes:
Vident::Typed::Attributes
Defined in:
lib/typed_operation/base.rb

Class Method Summary collapse

Instance Method Summary collapse

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.message
  end
  prepare if respond_to?(:prepare)
end

Class Method Details

.callObject



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_keyObject



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, **options, &converter)
  attribute(name, signature, **{allow_nil: false}.merge(options), &converter)
end

.to_procObject



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

def to_proc
  method(:call).to_proc
end

Instance Method Details

#callObject



44
45
46
# File 'lib/typed_operation/base.rb', line 44

def call
  raise InvalidOperationError, "You must implement #call"
end

#to_procObject



48
49
50
# File 'lib/typed_operation/base.rb', line 48

def to_proc
  method(:call).to_proc
end