Class: LH::DependencyInjection::ContextHash

Inherits:
Object
  • Object
show all
Defined in:
lib/lh/dependency_injection/context.rb

Instance Method Summary collapse

Constructor Details

#initializeContextHash

Returns a new instance of ContextHash.



5
6
7
# File 'lib/lh/dependency_injection/context.rb', line 5

def initialize
  @context = { }
end

Instance Method Details

#[](key) ⇒ Object



13
14
15
16
17
18
# File 'lib/lh/dependency_injection/context.rb', line 13

def [](key)
  if @context[key].respond_to? :call
    @context[key] = @context[key].call
  end
  @context[key]
end

#has_key?(key) ⇒ Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/lh/dependency_injection/context.rb', line 20

def has_key?(key)
  @context.has_key?(key)
end

#merge!(other_context) ⇒ Object



9
10
11
# File 'lib/lh/dependency_injection/context.rb', line 9

def merge!(other_context)
  @context.merge!(other_context.context)
end

#specify(key, value = nil, &block) ⇒ Object



24
25
26
# File 'lib/lh/dependency_injection/context.rb', line 24

def specify(key, value=nil, &block)
  @context[key] = value || block
end