Class: ActiveInteractor::Base

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(input = {}) ⇒ Base

Returns a new instance of Base.



33
34
35
36
# File 'lib/active_interactor/base.rb', line 33

def initialize(input = {})
  @input = input.freeze
  @context = parse_input!
end

Class Method Details

.argument(name, type, description = nil, **options) ⇒ Object



6
7
8
# File 'lib/active_interactor/base.rb', line 6

def argument(name, type, description = nil, **options)
  attributes[:arguments][name.to_sym] = { name: name, type: type, description: description }.merge(options)
end

.perform(input_context = {}) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/active_interactor/base.rb', line 14

def perform(input_context = {})
  perform!(input_context)
rescue Error => e
  e.result
rescue StandardError => e
  Result.failure(errors: e.message)
end

.perform!(input_context = {}) ⇒ Object



10
11
12
# File 'lib/active_interactor/base.rb', line 10

def perform!(input_context = {})
  new(input_context).perform!
end

.returns(name, type, description = nil, **options) ⇒ Object



22
23
24
# File 'lib/active_interactor/base.rb', line 22

def returns(name, type, description = nil, **options)
  attributes[:fields][name.to_sym] = { name: name, type: type, description: description }.merge(options)
end

Instance Method Details

#interactObject



53
# File 'lib/active_interactor/base.rb', line 53

def interact; end

#performObject



45
46
47
48
49
50
51
# File 'lib/active_interactor/base.rb', line 45

def perform
  perform!
rescue Error => e
  e.result
rescue StandardError => e
  Result.failure(errors: e.message)
end

#perform!Object



38
39
40
41
42
43
# File 'lib/active_interactor/base.rb', line 38

def perform!
  with_notification(:perform) do |payload|
    interact
    payload[:result] = Result.success(data: parse_output!)
  end
end

#rollbackObject



54
# File 'lib/active_interactor/base.rb', line 54

def rollback; end