Module: Rankum::Utils::Interactor

Included in:
Metrics::FCPCalculator, Runners::CLIOutputer, Runners::CLISetup, Runners::RankumCLI
Defined in:
lib/rankum/utils/interactor.rb

Instance Method Summary collapse

Instance Method Details

#contextObject



34
35
36
# File 'lib/rankum/utils/interactor.rb', line 34

def context
  @context
end

#executeObject



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/rankum/utils/interactor.rb', line 11

def execute
  begin
    yield
    exit if @context.fail?
    success!
   rescue Exception => e
     fail!
  end

  @context
end

#fail!Object



38
39
40
41
# File 'lib/rankum/utils/interactor.rb', line 38

def fail!
  @context.send("success?=",false)
  @context.send("fail?=",true)
end

#initialize(context = {}) ⇒ Object



7
8
9
# File 'lib/rankum/utils/interactor.rb', line 7

def initialize context={}
  @context = OpenStruct.new(context)
end

#organize(*interactors) ⇒ Object



23
24
25
26
27
28
29
30
31
32
# File 'lib/rankum/utils/interactor.rb', line 23

def organize *interactors
  interactors.each do |interactor|
    context_hash = @context.to_h
    context = interactor.run(context_hash)

    @context = OpenStruct.new(context_hash.merge!(context.to_h))
  end

  @context
end

#success!Object



43
44
45
46
# File 'lib/rankum/utils/interactor.rb', line 43

def success!
  @context.send("success?=",true)
  @context.send("fail?=",false)
end