Sha256: 00a7536a0c70b06bc1f0ef6951927989b9c3fdfa46afeca3f66ff0f15d9c4f30

Contents?: true

Size: 869 Bytes

Versions: 6

Compression:

Stored size: 869 Bytes

Contents

class SmartIoC::BeanLocator
  BEAN_PATTERN = /bean\s+(:[a-zA-z0-9\-\_]+)/

  # @param package_name [Symbol] package name for bean (ex: :repository)
  # @param dir [String] absolute path for directory with bean definitions
  # @return nil
  def locate_beans(package_name, dir)
    if !package_name.is_a?(Symbol)
      raise ArgumentError, 'package name should be a symbol'
    end

    package_name = package_name

    Dir.glob(File.join(dir, '**/*.rb')).each do |file_path|
      source_str = File.read(file_path)

      beans = find_package_beans(source_str)

      beans.each do |bean_name|
        SmartIoC::BeanLocations.add_bean(package_name, bean_name, file_path)
      end
    end
    nil
  end

  private

  def find_package_beans(source_str)
    tokens = source_str.scan(BEAN_PATTERN)
    tokens.flatten.uniq.map {|token| token.gsub(':', '').to_sym}
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
smart_ioc-0.1.19 lib/smart_ioc/bean_locator.rb
smart_ioc-0.1.18 lib/smart_ioc/bean_locator.rb
smart_ioc-0.1.17 lib/smart_ioc/bean_locator.rb
smart_ioc-0.1.16 lib/smart_ioc/bean_locator.rb
smart_ioc-0.1.14 lib/smart_ioc/bean_locator.rb
smart_ioc-0.1.13 lib/smart_ioc/bean_locator.rb