Module: UseCasePattern::Base

Extended by:
ActiveSupport::Concern
Includes:
ActiveModel::Validations
Defined in:
lib/use_case_pattern/base.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#failure?Boolean

Did the use case have any errors?

Returns:

  • (Boolean)


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

def failure?
  errors.any?
end

#performObject

Implement all the steps required to complete this use case

Raises:

  • (NotImplementedError)


26
27
28
# File 'lib/use_case_pattern/base.rb', line 26

def perform
  raise NotImplementedError
end

#perform!Object



30
31
32
33
34
35
36
# File 'lib/use_case_pattern/base.rb', line 30

def perform!
  if invalid?
    raise(ValidationError.new(self))
  end

  perform
end

#success?Boolean

Did the use case performed its task without errors?

Returns:

  • (Boolean)


39
40
41
# File 'lib/use_case_pattern/base.rb', line 39

def success?
  errors.none?
end