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



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

def interact; end

#performObject



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

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

#perform!Object



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

def perform!
  interact
  Result.success(data: parse_output!)
end

#rollbackObject



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

def rollback; end