Module: SmartIoC

Defined in:
lib/smart_ioc.rb,
lib/smart_ioc/version.rb,
lib/smart_ioc/container.rb

Defined Under Namespace

Modules: Args, Errors, Iocify, Scopes Classes: BeanDefinition, BeanDefinitionsStorage, BeanDependency, BeanFactory, BeanFileLoader, BeanLocations, BeanLocator, Container, ExtraPackageContexts, InjectMetadata, Railtie

Constant Summary collapse

VERSION =
"0.3.7"

Class Method Summary collapse

Class Method Details

.benchmark_mode(flag) ⇒ Object



55
56
57
# File 'lib/smart_ioc.rb', line 55

def benchmark_mode(flag)
  @benchmark_mode = !!flag
end

.clearObject

Full clear of data (mostly for tests)



67
68
69
70
# File 'lib/smart_ioc.rb', line 67

def clear
  BeanLocations.clear
  Container.clear
end

.containerObject



72
73
74
# File 'lib/smart_ioc.rb', line 72

def container
  Container.get_instance
end

.find_package_beans(package_name, dir) ⇒ Object

Returns nil.

Parameters:

  • package_name (String or Symbol)

    package name for bean definitions

  • dir (String)

    absolute path with bean definitions

Returns:

  • nil



40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/smart_ioc.rb', line 40

def find_package_beans(package_name, dir)
  time = Benchmark.realtime do
    bean_locator = SmartIoC::BeanLocator.new
    bean_locator.locate_beans(package_name.to_sym, dir)
  end

  time *= 1000

  if is_benchmark_mode
    puts "Search finished for '#{package_name}'. Time taken: #{"%.2f ms" % time}"
  end

  nil
end

.is_benchmark_modeObject



33
34
35
# File 'lib/smart_ioc.rb', line 33

def is_benchmark_mode
  @benchmark_mode
end

.load_all_beansObject

Load all beans (usually required for production env)



60
61
62
63
64
# File 'lib/smart_ioc.rb', line 60

def load_all_beans
  BeanLocations.all_bean_names.each do |bean|
    container.require_bean(bean)
  end
end