Class: SmartIoC::BeanLocator

Inherits:
Object
  • Object
show all
Includes:
Args
Defined in:
lib/smart_ioc/bean_locator.rb

Constant Summary collapse

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

Instance Method Summary collapse

Methods included from Args

#check_arg, #check_arg_any, #not_nil

Instance Method Details

#locate_beans(package_name, dir) ⇒ Object

Returns nil.

Parameters:

  • package_name (Symbol)

    package name for bean (ex: :repository)

  • dir (String)

    absolute path for directory with bean definitions

Returns:

  • nil



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/smart_ioc/bean_locator.rb', line 9

def locate_beans(package_name, dir)
  check_arg(package_name, :package_name, Symbol)

  Dir.glob(File.join(dir, '**/*.rb')).each do |file_path|
    File.readlines(file_path).each do |line|
      match_data = line.match(BEAN_PATTERN)

      if match_data
        SmartIoC::BeanLocations.add_bean(
          package_name, match_data.captures.first.gsub(':', '').to_sym, file_path
        )
        break
      end
    end
  end

  nil
end