Class: Voom::Commands::Base

Inherits:
Object
  • Object
show all
Extended by:
RescueLogicalErrors
Includes:
AggregateValidations, Namespace, SuccessAndFail, ValidateParams
Defined in:
lib/voom/commands/base.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from RescueLogicalErrors

rescue_logical_errors

Methods included from ExtractErrors

#extract_errors, #extract_fk_errors

Methods included from SuccessAndFail

fail, #fail, #success, success

Methods included from Namespace

#namespace_errors, #namespace_errors!

Methods included from AggregateValidations

#aggregate_validations, #aggregate_validations!

Methods included from ValidateParams

#schema, #validate_params

Constructor Details

#initialize(*args, **params_, &block) ⇒ Base

Returns a new instance of Base.



20
21
22
23
# File 'lib/voom/commands/base.rb', line 20

def initialize(*args, **params_, &block)
  @params = params_.any? ? validate_params(**params_) : {}
  @block = block
end

Instance Attribute Details

#paramsObject (readonly)

Returns the value of attribute params.



18
19
20
# File 'lib/voom/commands/base.rb', line 18

def params
  @params
end

Class Method Details

.call(*args, **params, &block) ⇒ Object



33
34
35
# File 'lib/voom/commands/base.rb', line 33

def self.call(*args, **params, &block)
  rescue_logical_errors {new(*args, **params, &block).call(&block)}
end

.call!(*args, **params, &block) ⇒ Object



37
38
39
# File 'lib/voom/commands/base.rb', line 37

def self.call!(*args, **params, &block)
  self.new(*args, **params, &block).call(&block)
end

Instance Method Details

#callObject



25
26
27
28
29
30
31
# File 'lib/voom/commands/base.rb', line 25

def call
  response = self.perform
  response = response.respond_to?(:success?) ? response : success
  response2 = @block.call(response, self) if @block
  response = response2.respond_to?(:success?) ? response2 : response
  response.respond_to?(:success?) ? response : success
end