Sha256: 710631f475599c59c863360c80283dfccd70a5e07eea721ccdb195c432f2e971

Contents?: true

Size: 811 Bytes

Versions: 16

Compression:

Stored size: 811 Bytes

Contents

class SmartIoC::BeanLocator
  include SmartIoC::Args
  
  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)
    check_arg(package_name, :package_name, Symbol)

    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

16 entries across 16 versions & 1 rubygems

Version Path
smart_ioc-0.2.4 lib/smart_ioc/bean_locator.rb
smart_ioc-0.2.3 lib/smart_ioc/bean_locator.rb
smart_ioc-0.2.2 lib/smart_ioc/bean_locator.rb
smart_ioc-0.2.1 lib/smart_ioc/bean_locator.rb
smart_ioc-0.2.0 lib/smart_ioc/bean_locator.rb
smart_ioc-0.1.30 lib/smart_ioc/bean_locator.rb
smart_ioc-0.1.29 lib/smart_ioc/bean_locator.rb
smart_ioc-0.1.28 lib/smart_ioc/bean_locator.rb
smart_ioc-0.1.27 lib/smart_ioc/bean_locator.rb
smart_ioc-0.1.26 lib/smart_ioc/bean_locator.rb
smart_ioc-0.1.25 lib/smart_ioc/bean_locator.rb
smart_ioc-0.1.24 lib/smart_ioc/bean_locator.rb
smart_ioc-0.1.23 lib/smart_ioc/bean_locator.rb
smart_ioc-0.1.22 lib/smart_ioc/bean_locator.rb
smart_ioc-0.1.21 lib/smart_ioc/bean_locator.rb
smart_ioc-0.1.20 lib/smart_ioc/bean_locator.rb