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, &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.



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

def initialize(container, &block)
  @container = container
  @statuses = []
  @triggers = {}
  instance_exec(container, &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.



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

def method_missing(meth, *args, &block)
  if container.key?(meth)
    container[meth]
  elsif ::Kernel.respond_to?(meth)
    ::Kernel.public_send(meth, *args, &block)
  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.



14
15
16
# File 'lib/dry/system/lifecycle.rb', line 14

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.



57
58
59
# File 'lib/dry/system/lifecycle.rb', line 57

def init
  @init
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.



62
63
64
# File 'lib/dry/system/lifecycle.rb', line 62

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.



22
23
24
# File 'lib/dry/system/lifecycle.rb', line 22

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.



67
68
69
# File 'lib/dry/system/lifecycle.rb', line 67

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.



24
25
26
# File 'lib/dry/system/lifecycle.rb', line 24

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.



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

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

.new(container, &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.



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

def self.new(container, &block)
  cache.fetch_or_store([container, 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.



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

def call(*triggers)
  triggers.each do |trigger|
    unless statuses.include?(trigger)
      __send__(trigger)
      statuses << trigger
    end
  end
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.



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

def register(*args, &block)
  container.register(*args, &block)
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.



72
73
74
75
76
# File 'lib/dry/system/lifecycle.rb', line 72

def use(*names)
  names.each do |name|
    container.boot!(name)
  end
end