Class: DI

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

Class Method Summary collapse

Class Method Details

.[](what) ⇒ Object



65
66
67
# File 'lib/di.rb', line 65

def [](what)
  @@container.resolve(what)
end

.containerObject



69
70
71
# File 'lib/di.rb', line 69

def container
  @@container
end

.init(opts = {}) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/di.rb', line 15

def init (opts = {})

  c = Dry::Container.new
  @@container = c

  # one time object
  c.register(:dante_runner,
             -> {Dante::Runner.new('stf-client')})

  # one time object because dante is one time
  c.register(:demonizer,
             -> do
               Stf::Demonizer.new(c[:dante_runner],
                             log_path: opts[:log], pid_path: opts[:pid])
             end)

  c.register(:stf,
             -> {Stf::Client.new(opts[:url], opts[:token])},
             memoize: true)

  c.register(:start_debug_session_interactor,
             -> {Stf::StartDebugSessionInteractor.new},
             memoize: true)

  c.register(:start_one_debug_session_interactor,
             -> {Stf::StartOneDebugSessionInteractor.new},
             memoize: true)

  c.register(:get_keys_interactor,
             -> {Stf::GetKeysInteractor.new},
             memoize: true)

  c.register(:get_values_interactor,
             -> {Stf::GetValuesInteractor.new},
             memoize: true)

  c.register(:stop_all_debug_sessions_interactor,
             -> {Stf::StopAllDebugSessionsInteractor.new},
             memoize: true)

  c.register(:stop_debug_session_interactor,
             -> {Stf::StopDebugSessionInteractor.new},
             memoize: true)

  c.register(:remove_all_user_devices_interactor,
             -> {Stf::RemoveAllUserDevicesInteractor.new},
             memoize: true)

end