Class: UseCase::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/usecasing_validations.rb

Direct Known Subclasses

Validator

Class Method Summary collapse

Class Method Details

.depends_all(*deps) ⇒ Object



21
22
23
24
25
# File 'lib/usecasing_validations.rb', line 21

def self.depends_all(*deps)
  @dependencies ||= []
  @dependencies.push(*deps)
  ignored_dependencies.push(*deps)
end

.ignored_dependenciesObject



27
28
29
# File 'lib/usecasing_validations.rb', line 27

def self.ignored_dependencies
  @ignored_dependencies ||= []
end

.not_ignored(usecase) ⇒ Object



31
32
33
# File 'lib/usecasing_validations.rb', line 31

def self.not_ignored(usecase)
  !ignored_dependencies.include?(usecase)
end

.tx(execution_order, context) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
# File 'lib/usecasing_validations.rb', line 35

def self.tx(execution_order, context)
  ctx = Context.new(context)
  executed = []
  execution_order.each do |usecase|
    break if not_ignored(usecase) && !ctx.success?
    executed.push(usecase)
    yield usecase, ctx
  end
  rollback(executed, ctx) unless ctx.success?
  ctx
end