Class: SmartCore::Injection::Locator::Dependency Private

Inherits:
Object
  • Object
show all
Defined in:
lib/smart_core/injection/locator/dependency.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.

Since:

  • 0.1.0

Version:

  • 0.3.0

Instance Method Summary collapse

Constructor Details

#initialize(memoize:) ⇒ void

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.

Parameters:

  • memoize (Hash)

    a customizable set of options

Options Hash (memoize:):

  • (Boolean)

Since:

  • 0.1.0

Version:

  • 0.3.0



13
14
15
16
17
18
# File 'lib/smart_core/injection/locator/dependency.rb', line 13

def initialize(memoize:)
  @binded = false
  @value = nil
  @memoize = memoize
  @barrier = SmartCore::Engine::Lock.new
end

Instance Method Details

#bind(&block) ⇒ Any

Parameters:

  • block (Block)

Returns:

  • (Any)

Since:

  • 0.2.0

Version:

  • 0.3.0



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
64
# File 'lib/smart_core/injection/locator/dependency.rb', line 38

def bind(&block)
  with_barrier do
    # NOTE:
    #   Temporary disabled old variant of dependency resolving
    #   cuz we need to reivew the canonical way of dependency resolving
    #   and rework the resolving at all on runtime level (under `memoize: true` option).
    #   Old code variant:
    #
    #   if @binded
    #     @value
    #   else
    #     @binded = true
    #     @value = yield
    #   end

    if @memoize
      if @binded
        @value
      else
        @binded = true
        @value = yield
      end
    else
      yield
    end
  end
end

#rebind(&block) ⇒ Any

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.

Parameters:

  • block (Block)

Returns:

  • (Any)

Since:

  • 0.1.0



25
26
27
28
29
30
# File 'lib/smart_core/injection/locator/dependency.rb', line 25

def rebind(&block)
  with_barrier do
    @binded = false
    bind(&block)
  end
end