Class: Dry::System::Lifecycle Private

Inherits:
BasicObject
Defined in:
lib/dry/system/lifecycle.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Lifecycle booting DSL

Lifecycle objects are used in the boot files where you can register custom init/start/stop triggers

See Also:

  • [Container[Container.finalize]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(container, opts, &block) ⇒ Lifecycle

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Lifecycle.



45
46
47
48
49
50
51
52
# File 'lib/dry/system/lifecycle.rb', line 45

def initialize(container, opts, &block)
  @container = container
  @settings = nil
  @statuses = []
  @triggers = {}
  @opts = opts
  instance_exec(target, &block)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *args, &block) ⇒ Object (private)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



128
129
130
131
132
133
134
135
136
137
138
# File 'lib/dry/system/lifecycle.rb', line 128

def method_missing(meth, *args, &block)
  if target.registered?(meth)
    target[meth]
  elsif container.key?(meth)
    container[meth]
  elsif ::Kernel.respond_to?(meth)
    ::Kernel.public_send(meth, *args, &block)
  else
    super
  end
end

Instance Attribute Details

#containerObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



18
19
20
# File 'lib/dry/system/lifecycle.rb', line 18

def container
  @container
end

#init(&block) ⇒ Object (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



80
81
82
# File 'lib/dry/system/lifecycle.rb', line 80

def init
  @init
end

#optsObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



30
31
32
# File 'lib/dry/system/lifecycle.rb', line 30

def opts
  @opts
end

#start(&block) ⇒ Object (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



85
86
87
# File 'lib/dry/system/lifecycle.rb', line 85

def start
  @start
end

#statusesObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



26
27
28
# File 'lib/dry/system/lifecycle.rb', line 26

def statuses
  @statuses
end

#stop(&block) ⇒ Object (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



90
91
92
# File 'lib/dry/system/lifecycle.rb', line 90

def stop
  @stop
end

#triggersObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



28
29
30
# File 'lib/dry/system/lifecycle.rb', line 28

def triggers
  @triggers
end

Class Method Details

.cacheObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



40
41
42
# File 'lib/dry/system/lifecycle.rb', line 40

def self.cache
  @cache ||= ::Concurrent::Map.new
end

.new(container, opts = {}, &block) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



33
34
35
36
37
# File 'lib/dry/system/lifecycle.rb', line 33

def self.new(container, opts = {}, &block)
  cache.fetch_or_store([container, opts, block].hash) do
    super
  end
end

Instance Method Details

#call(*triggers) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



55
56
57
58
59
60
61
62
# File 'lib/dry/system/lifecycle.rb', line 55

def call(*triggers)
  triggers.each do |trigger|
    unless statuses.include?(trigger)
      __send__(trigger)
      statuses << trigger
    end
  end
end

#componentObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



107
108
109
# File 'lib/dry/system/lifecycle.rb', line 107

def component
  opts[:component]
end

#configObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



75
76
77
# File 'lib/dry/system/lifecycle.rb', line 75

def config
  component.config
end

#configure(&block) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



70
71
72
# File 'lib/dry/system/lifecycle.rb', line 70

def configure(&block)
  component.configure(&block)
end

#register(*args, &block) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



102
103
104
# File 'lib/dry/system/lifecycle.rb', line 102

def register(*args, &block)
  container.register(*args, &block)
end

#settings(&block) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



65
66
67
# File 'lib/dry/system/lifecycle.rb', line 65

def settings(&block)
  component.settings(&block)
end

#targetObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



112
113
114
# File 'lib/dry/system/lifecycle.rb', line 112

def target
  component.container
end

#use(*names) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



95
96
97
98
99
# File 'lib/dry/system/lifecycle.rb', line 95

def use(*names)
  names.each do |name|
    target.start(name)
  end
end