Class: SmartIoC::BeanFileLoader

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

Instance Method Summary collapse

Constructor Details

#initializeBeanFileLoader

Returns a new instance of BeanFileLoader.



2
3
4
5
6
# File 'lib/smart_ioc/bean_file_loader.rb', line 2

def initialize
  @loaded_locations = {}
  @load_proc        = Proc.new { |location| load(location) }
  @semaphore        = Mutex.new
end

Instance Method Details

#clear_locationsObject



30
31
32
# File 'lib/smart_ioc/bean_file_loader.rb', line 30

def clear_locations
  @loaded_locations = {}
end

#require_bean(bean_name) ⇒ Object

return nil

Parameters:

  • bean_name (Symbol)

    bean name



15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/smart_ioc/bean_file_loader.rb', line 15

def require_bean(bean_name)
  locations = SmartIoC::BeanLocations.get_bean_locations(bean_name).values.flatten

  locations.each do |location|
    next if @loaded_locations.has_key?(location)
    @loaded_locations[location] = true

    @semaphore.synchronize do
      @load_proc.call(location)
    end
  end

  nil
end

#set_load_proc(&block) ⇒ Object

Raises:

  • (ArgumentError)


8
9
10
11
# File 'lib/smart_ioc/bean_file_loader.rb', line 8

def set_load_proc(&block)
  raise ArgumentError, "block should be given" unless block_given?
  @load_proc = block
end